Jump to content


Photo

weird selection problem


  • Please log in to reply
2 replies to this topic

#1 apocra

apocra
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 21 August 2006 - 08:26 AM

Hi all,

I've got this weird problem which I can't seem to get rid off. I bet it will be some minor glitch I keep failing to notice, I hope someone here can help me.

I've got a database with multiple records (2 in the test-db) which I want to print onscreen in a table. But before that I want to check the id of the records with the id in a textfile. To do this I try to get the id's in a array (test-db has id #1 and #45) and am using the following code:

$pid = mysql_query("SELECT id FROM profiel ORDER BY id ASC LIMIT $num") 
or die('Could not find data in database ' . mysql_error());

$pid2 = mysql_fetch_array ($pid, MYSQL_NUM);

($num = the number of rows in the db and I've checked this, it's 2)

The array $pid2 only has one id in it and not the 2 that are in the database.

Help would be very much appreciated.

Cheers,
Apocra

#2 shoz

shoz
  • Staff Alumni
  • Advanced Member
  • 600 posts

Posted 21 August 2006 - 08:55 AM

mysql_fetch_array returns one row at a time.
$pid = mysql_query("SELECT id FROM profiel ORDER BY id ASC LIMIT $num") 
or die('Could not find data in database ' . mysql_error());

while($pid2 = mysql_fetch_array ($pid, MYSQL_NUM))
{
    echo $pid2[0]."<br />\n";
}
http://php.net/mysql_fetch_array

#3 apocra

apocra
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 21 August 2006 - 09:48 AM

Thanks, that did the trick! I knew it would be some stupid oversight.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users