Page 1 of 1

MYSQL_FETCH_ARRAY Only one result

Posted: Fri May 01, 2009 9:02 am
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

Re: MYSQL_FETCH_ARRAY Only one result

Posted: Fri May 01, 2009 9:13 am
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>";
}
 

Re: MYSQL_FETCH_ARRAY Only one result

Posted: Fri May 01, 2009 10:18 am
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

Re: MYSQL_FETCH_ARRAY Only one result

Posted: Fri May 01, 2009 10:25 am
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'

Re: MYSQL_FETCH_ARRAY Only one result

Posted: Fri May 01, 2009 10:48 am
by Slavender
:banghead: I feel very stupid for not realising that one. Thank you!