cffrost2

msg:4533717 | 3:45 pm on Jan 6, 2013 (gmt 0) |
My suggestion would be store each row into arrays. $id = array(); $text = array(); While($row = mysql_fetch_array($result)) { $id[] = $row['text']; $text[] = $row['id']; } Then you'll be able to access each result separately if needed. Just a thought. Maybe a better way. Good luck.
|
skoff

msg:4534290 | 1:43 pm on Jan 8, 2013 (gmt 0) |
First thing, forget the do while thing.. to pass through all records in your query you should use : while($row = mysql_fetch_array($result)) { } and for what your trying to attempt, your best bet would be to put it in a temp variable. Set it with the $id at the end of the loop. So when the loop will pass to the second records and all others after it will still have the value of the previous $id. I dont know what you did want to do with the first record because there would be no "previous" id so this is the reason of the if/else i put. $x = 0; while($row = mysql_fetch_array($result)) { $id = $row['ID']; $text = $row['text'];` echo "<tr> <td>Here is the text - " . $text . "</td> <td>The ID of the text is - " . $ID . "</td> if($x !== 0) { <td>The ID of the previous entry is - " . $x? . "</td> } else { <td> </td> } </tr> "; $x = $row['ID']; } hope this helps!
|
skoff

msg:4534333 | 4:12 pm on Jan 8, 2013 (gmt 0) |
i made some mistakes heres the code :
$x = 0; while($row = mysql_fetch_array($result)) { $ID = $row['ID']; $text = $row['text'];`
echo "<tr> <td>Here is the text - " . $text . "</td> <td>The ID of the text is - " . $ID . "</td>"; if($x !== 0) { echo "<td>The ID of the previous entry is - " . $x? . "</td>"; } else { echo "<td> </td>"; } echo "</tr>";
$x = $row['ID']; }
|
Mr_Cat

msg:4534374 | 5:34 pm on Jan 8, 2013 (gmt 0) |
Thanks skoff! :) will try it shortly and am assuming that to do the opposite, get the id of the previous iteration, I just swap the 'x=' round?
|
skoff

msg:4534376 | 5:48 pm on Jan 8, 2013 (gmt 0) |
you mean to get the id of the next iteration? and also just dont forget to remove the ? after your $x or you'll get an error
|
Mr_Cat

msg:4534397 | 6:35 pm on Jan 8, 2013 (gmt 0) |
yea the next iteration was what I was after, thanks, but I was wondering if I wanted the previous one as well then I'd just swap the x=0 and x=$row['ID'] around. My head is a bit fried from code now so I may be being dim :) Cheers
|
skoff

msg:4534417 | 7:35 pm on Jan 8, 2013 (gmt 0) |
no the reason i set x=0 before the loop is because it need to exist inside of the loop the first time or it would return an error. the asnwer i gave you will return the previous id not the next one.
|
|