Vick
Vick

Reputation: 25

How to retrieve 1 record at a time from db

I have a table comment as follow:

Comment

comment_id         cmt               followupid
1                 Hello              3 
2                 hi                 4
3                 Hey                2
4                 wassup             1

My query is that I want to echo "Hello", "hi", "hey" , "Wassup" and other (the record continues) individualy, I have used

$comment = mysql_result($runQuery, $i,"cmt");
echo $comment; 

which works fine but the problem is that it echoes all the comments at once, what I want is to echo all the comment but one at a time. the comment are in a div tag such that each the div appears only after 1 second the page is loaded. I want each comment to appear after different time interval

for e.g:

Hello  to appear at        5pm    (not necessarily the corect time it can be just an int)
hi                         5.10 pm 
hey                        6.30 pm 

Please Help!

Upvotes: 0

Views: 197

Answers (2)

hjpotter92
hjpotter92

Reputation: 80629

Create another variable storing time divisions(or number of rows). So that different output at different time can be fetched. For eg. If your table has 24 rows(or items), then this variable shall have a value 24. Use it to divide you output times(As in 24 hours, each hour a different value).

Now, the PHP part(I am not much familiar with date and time functions in PHP, so you can totally ignore the paragraph above.

$result = mysql_query($runquery);
$j = 0;
$i = rand( 0, mysql_num_rows($result) );
while($row=mysql_fetch_assoc($result)){
    // $row contains a single row.
    if( $j++ = $i )
        echo $row['cmt'], $row['comment_id'];
}

This will fetch one random row from the table, but not depending upon the server time.

Upvotes: 0

Shiplu Mokaddim
Shiplu Mokaddim

Reputation: 57640

The following code should give you some hints.

 $result = mysql_query($runquery);
 while($row=mysql_fetch_assoc($result)){
      // $row contains a single row.
      echo $row['cmt'], $row['comment_id']
 }

Upvotes: 1

Related Questions