A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: retrieve last 5 rows

  1. #1
    亲爱钰 slingsrat's Avatar
    Join Date
    Mar 2002
    Location
    Middle Earth
    Posts
    229

    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.

  2. #2
    Senior Member
    Join Date
    Apr 2002
    Posts
    2,849
    And changing LIMIT 1 to LIMIT 5 doesn't do it?

  3. #3
    亲爱钰 slingsrat's Avatar
    Join Date
    Mar 2002
    Location
    Middle Earth
    Posts
    229
    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

  4. #4
    亲爱钰 slingsrat's Avatar
    Join Date
    Mar 2002
    Location
    Middle Earth
    Posts
    229

    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center