FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP MySQL Loading Items from database





danway60
Is there a way of only displaying a certain number of rows onto a page?
For my website I use 30 games on a page. I am currently converting the pages that have the game's lists on them on to a database. I am wanting to only display number 1-30 games on a page and then have a second page which displays numbers 31-60 games. Is this possible?

Thanks, Dan.
rvec
http://dev.mysql.com/doc/refman/5.0/en/select.html#id3458772

use that to only get the rows you need, on the php side you can adjust to query to the page you need and how many results you want per page.
kv
Use limit in your select clause. Some thing like this

Code:


SELECT [......] LIMIT 0,30 #for first 30 rows
SELECT [......] LIMIT 30,30 #for next 30 rows



and so on
rvec
@kv: do you actually read the topic before making a reply?
You made the exact same point in 2 topics already Confused
rockacola
Welcome to paginating records in PHP! Laughing

Google a bit and you'll realize there's tons of approaches to do this.

Here's just one of the approach I found in 3 seconds:
http://www.allsyntax.com/tutorials/PHP/23/Pagination-with-PHP/1.php
danway60
How do I use this with a table?
I want to have something like:

Code:

<table border="0" width="600">
  <tr>
    <td><table><tr><td>
     <a href="***   Game URL loaded from the URL on my database   ***">
     <img src="*** IMG url loaded from the database ***">
     *** Name of the Game ****
     <p>*** Game Description loaded from database ***</p>
     </a>
     </td>
     </tr>
   </table>
   </td>
   <td></td>
    <td><table><tr><td>
     <a href="***   Game URL loaded from the URL on my database   ***">
     <img src="*** IMG url loaded from the database ***">
     *** Name of the Game ****
     <p>*** Game Description loaded from database ***</p>
     </a>
     </td>
     </tr>
   </table>
   </td>
    <td><table><tr><td>
     <a href="***   Game URL loaded from the URL on my database   ***">
     <img src="*** IMG url loaded from the database ***">
     *** Name of the Game ****
     <p>*** Game Description loaded from database ***</p>
     </a>
     </td>
     </tr>
   </table>
   </td>
</tr>

</table></td>
  </tr>


I just need to know how to load the *** *** bits from the database.

Each game has its own row. The row contains it's ID, Name, IMG URL, URL of the webpage, and Game Description.
Aredon
hmm you might be able to pull the data as an array and use a foreach loop, but I'm really tired right now so I probubly shouldn't try to write anything yet Wink. I'll get back to you. (Or someone else can jump in with the same idea)
Aredon
could you post the string you're using for your SQL query so I can figure out exactly how you're pulling the data?

Until then we'll assume you have the query all figured out and correct. Keep in mind there are many ways to do this, a better way would be to put the query straight to a mysql_fetch_array (which you could use for other stuff). However, seeing as how I have no idea how your database is structured we'll do it with good 'ol row. (I should also note that I disagree highly with your table structure Smile, but we'll use it anyway)
Code:

<?
$sql="SELECT * FROM `database`";
$result=mysql_query($sql);
echo "<table border=\"0\" width=\"600\"><tr>";
while($row=mysql_fetch_object($result)){
    echo "<td><table><tr><td><a href=\"".$row->url."\"><img src=\"".$row->img."\">".$row->name."<p>".$row->desc."</p></a></td></tr></table></td>";
}
echo "</tr></table></td></tr>";
?>
Related topics
PHP, MySQL...
ASP +PHP+MySQL Tutorials
what is your php mysql apache installer package
Need some php/mysql dlls
The Basics (php, mysql etc)
What is useful way in this php+mysql problem?
PHP/Mysql - beginner!
A very good PHP MySQL Tutorial
Setup php,mysql and others...
php, mysql and iis5
 EASY 40 frih$ IF YOU KNOW PHP+MySQL 
Php Mysql security testing
Link PHP/Mysql with Outlook Express
php-mysql source code
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.