vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   calling one row in a column (https://vborg.vbsupport.ru/showthread.php?t=126357)

error_22 09-11-2006 06:06 PM

calling one row in a column
 
Hi,

I was wonerding, is there a way to call one row in a column? Lets say I have table called "test" with 3 columns (id, title, content). Lets also say that there are 10 rows. What if I want to call row number 5 in the id column and at the same time row number 8 in the title column. I was hoping for something like this:

PHP Code:

$sql "SELECT * FROM `test`"
$result mysql_query($sql) or die(mysql_error()); 
while (
$row mysql_fetch_assoc($result)) 
{     
echo 
$row['1']['id']; 
echo 
$row['2']['id']; 


Using that query, I could call every row. They would also be separated. My problem is, the above code doesnt work ahaha. Is there a way to achieve this?

Thanks in advance
Niklas

Adrian Schneider 09-11-2006 06:11 PM

mysql_fetch_assoc() returns an associative array, so it would actually be:
PHP Code:

echo $row['id'];
echo 
$row['title'];
echo 
$row['content']; 


error_22 09-11-2006 09:50 PM

well i never said i used the right fetch method....i have no idea what to use actually. in your example, all rows would be called. my question is: is there a way to separate the rows? I want to be able to call row number 4 and then row number 6, not the other ones? is there a way to achieve this?

Thanks for helping....again ahaha

Adrian Schneider 09-12-2006 07:46 PM

just 4 and 6? or 2, 4, 6, 8, etc?

Anyway, something like this could work for your query [sql]SELECT *
FROM `test`
WHERE `id` IN (2,4)[/sql]Note this is id 2 and 4, not necessarily rows 2 and 4.

You can narrow the results in MySQL or PHP... here is a PHP example to show every second row...
PHP Code:

$counter 0;
while (
$row mysql_fetch_assoc($result)) 
{
    if (++
$counter %== 1)
    {
        continue;
    }
    
// echo your stuff here




All times are GMT. The time now is 02:10 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01072 seconds
  • Memory Usage 1,719KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete