-
亲爱钰
retrieve last 5 rows
My code here works sweet for retrieving the last entry in my table.
PHP Code:
<?php
mysql_connect("localhost","username","password") or die();
mysql_select_db("comments") or die();
$result = mysql_query("SELECT * FROM comments ORDER BY ID desc LIMIT 1") or die();
while($row = mysql_fetch_array($result))
{
echo "uservar=".$row['username']."&commentvar=".$row['comments']."&timeinfo=".$row['date']."";
}
?>
It returns the last username and comment to my flash webpage. How do I retrieve the last 5 comments? Of course they will all need to have different variable names so they can be ordered in flash.
-
And changing LIMIT 1 to LIMIT 5 doesn't do it?
-
亲爱钰
Yes, but it updates the variables so only the last one is actually returned to flash. My actual question should be how do I add a variable into the fetch_array loop and concatenate with uservar and commentvar variables
ie uservar1 uservar2 etc
-
亲爱钰
sussed
OK, i figured it out in case anyones interested. Its not too complicated.
PHP Code:
<?php
mysql_connect("localhost","username","password") or die();
mysql_select_db("comments") or die();
$result = mysql_query("SELECT * FROM comments ORDER BY ID desc LIMIT 5") or die();
while($row = mysql_fetch_array($result))
{
$lastfive++;
echo "uservar".$lastfive."=".$row['username']."&commentvar".$lastfive."=".$row['comments']."&timeinfo".$lastfive."=".$row['date']."";
}
?>
Last edited by slingsrat; 04-12-2012 at 08:30 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|