Jump to content


Photo

Listing Rows?


  • Please log in to reply
5 replies to this topic

#1 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 15 October 2006 - 02:51 AM

Ok, I want to list like 12 pictures grabbing them from my database.

So it will show like ids 1 - 12 on the first page and then the next page 13 - 24 and so forth...

How would I go about doing this?

#2 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 15 October 2006 - 03:10 AM

<?php
$select = "SELECT * FROM pictures;";
$query = mysql_query($select);
while ($row = mysql_fetch_array($query)) {
echo "<img src=\"{$row[imagepath]}{$row[imagename]}\" alt=\"{$row[imagename]}\" />";
}
?>

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#3 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 15 October 2006 - 03:11 AM

but how can i make it so it only lists 12 pictures?

#4 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 15 October 2006 - 03:12 AM

<?php
$select = "SELECT * FROM pictures LIMIT 12;";
$query = mysql_query($select);
while ($row = mysql_fetch_array($query)) {
echo "<img src=\"{$row[imagepath]}{$row[imagename]}\" alt=\"{$row[imagename]}\" />";
}
?>

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#5 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 15 October 2006 - 03:42 AM

i had to modify your code

i used

$select = "SELECT * FROM art LIMIT 12;";
$query = mysql_query($select);
while ($row = mysql_fetch_array($query)) {
$desc = $row[desc];
$cat = $row[cat];
$pic = $row[pic];
$id = $row[id];
echo "<a href=?page=view&id=$id><img src=art/$cat/$pic alt='$desc' width=80 height=100 border=0></a>";
}


#6 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 15 October 2006 - 01:39 PM

The mysql LIMIT clause can take 2 arguments eg LIMIT 0, 12 where the first number is the record number to start at and the second is how many.

So your first page would want LIMIT 0, 12
Second would want LIMIT 12, 12
...
Pth page would want LIMIT (P-1) * 12 , 12
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users