Jump to content

mysql foreach


gsencan

Recommended Posts

<?php

mysql_connect("AAA", "BBB"CCC") or die(mysql_error());

mysql_select_db("DDD") or die(mysql_error());

  $result = mysql_query("SELECT * FROM image WHERE CATEGORY='SPORTS' ORDER BY DATE DESC") or die(mysql_error()); 

  $row = mysql_fetch_array( $result );

    echo 'blablabla';

  ?>

 

Here i want to  show 20 data from my database by newest time. DATE is a timestamp (current time )field in my database.

so i think i have to use foreach statement but,

what should i use when i want to show again 20 data in another page but now: newest from 20 to 40 or 40 to 60?

I hope i put it out clear .

 

Link to comment
Share on other sites

I used this code it works for me. So it shows most  recent 20 to 40 data(20 data per page).   

<?php

mysql_connect("AAA", "BBB", "CCC") or die(mysql_error());

mysql_select_db("DDD") or die(mysql_error());

  $result = mysql_query("SELECT * FROM mytable WHERE CATEGORY='SPORTS' ORDER BY DATE DESC LIMIT 20, 40") or die(mysql_error()); 

while($row = mysql_fetch_assoc($result)){

echo 'blablabla';

}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.