MYSQL_FETCH_ARRAY Only one result

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Slavender
Forum Newbie
Posts: 4
Joined: Thu Apr 30, 2009 7:43 am

MYSQL_FETCH_ARRAY Only one result

Post by Slavender »

I have another problem, my piece of code is only displaying one result. It should be displaying all results but its not!

I Haven't the slightest clue and I've spent quite a while on it, I tried treating it as an array and giving it a value beside, and using a forloop, tho it didn't work. Heres the code anyway, it should be displaying more than one result! I suppose its a logical error.

Code: Select all

 
    $result = mysql_query("SELECT * FROM tbl_Iblog")or die(mysql_error());  
    $row = mysql_fetch_array($result);
 
    echo "UserName: ".$row['userName'];
    echo "<p> </p>";
    echo " Post:<p></P> ".$row['uPost'];
    echo "<p> </p> <p> </p>";
    
 
Kind Regards,

David Harvey
Last edited by Benjamin on Fri May 01, 2009 12:41 pm, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: MYSQL_FETCH_ARRAY Only one result

Post by susrisha »

try this

Code: Select all

 
while($row = mysql_fetch_array($result))
{
 
    echo "UserName: ".$row['userName'];
    echo "<p> </p>";
    echo " Post:<p></P> ".$row['uPost'];
    echo "<p> </p> <p> </p>";
}
 
Slavender
Forum Newbie
Posts: 4
Joined: Thu Apr 30, 2009 7:43 am

Re: MYSQL_FETCH_ARRAY Only one result

Post by Slavender »

Ok that works great, but perhaps I need to access each row individually for the purpose to display the last row first. I would then decrement through array until it ultimately reached 0.

Is there away I can point to the actual array section.

I'd assume it would be:

$row = mysql_fetch_array[x]($result)


x being the pointer to the row I want?

Kind regards
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: MYSQL_FETCH_ARRAY Only one result

Post by watson516 »

If you just want to change the order in which the rows are displayed, modify your select statement to include an 'ORDER BY field DESC'
Slavender
Forum Newbie
Posts: 4
Joined: Thu Apr 30, 2009 7:43 am

Re: MYSQL_FETCH_ARRAY Only one result

Post by Slavender »

:banghead: I feel very stupid for not realising that one. Thank you!
Post Reply