Closed Thread Icon

Topic awaiting preservation: mysql showing more than one result. (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12086" title="Pages that link to Topic awaiting preservation: mysql showing more than one result. (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: mysql showing more than one result. <span class="small">(Page 1 of 1)</span>\

 
maninacan
Paranoid (IV) Inmate

From: Seattle, WA, USA
Insane since: Oct 2001

posted posted 03-05-2002 23:31

ok, so I'm writing a little guestbook script for my new site, and everything was going fine, until I was trying to view the entries. I want to view many entries at a time in descending order of timestamp the code is this:

$db = mysql_connect("kewlster.com","username","password");
mysql_select_db("guestbook",$db);
$query = "SELECT * FROM entries ORDER BY timestamp DESC";
$result = mysql_query($query,$db);
if($results = mysql_fetch_array($result)){
echo "<BR><BR><BR>\n";
foreach($results as $key => $value){
echo "$key - $value<BR>\n";
}


as you see it gets the results, puts them in an array and then prints them all out to the screen, but the problem is that it's only printing the first result. Please help ASAP.

http://www.kewlster.com

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 03-06-2002 00:37

everytime you do fetch_array you get the next line into the array. so if you do it only once, you only get the first line.

try using
while(mysql_fetch_array(...)) {
...
}

instead of the if().

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 03-06-2002 08:11

as Grumble said, I add:

code:
while($row = mysql_fetch_array($result))
{
echo "<BR><BR><BR>\n";
foreach($row as $key => $value){
echo "$key - $value<BR>\n";
}



basically, mysql_fetch_array() returns a row and not the set of all results.

« BackwardsOnwards »

Show Forum Drop Down Menu