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
https://forums.phpfreaks.com/topic/245716-mysql-foreach/
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
https://forums.phpfreaks.com/topic/245716-mysql-foreach/#findComment-1262459
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.