newbie mysql + php q

A

Anonymous

Guest
hi
i'm new to php and am trying to write a php image gallery. i can store and retrieve image info from the db but i'd like to display ten images on each page. can i do this with my sql query or do i need do retrieve all rows and sort through them with php.

many thanks in advance
tim
 
Yes, you can do it with an SQL query. It's a pretty basic query, but since I don't know what your database looks like, I can't tell you exactly what it should look like. At any rate, if you want to retrieve just 10 rows, then use LIMIT 10.
 
Thanks swirlee,

This is what i tried, but it still displays all twelve rows in the db

http://crew.taweb.net.au/tim/gallery.php

Code:
$sql01 = " select id, filename from tim_crew_images order by id desc limit 0, 10";

mysql_select_db($db, $conn);
$result = mysql_query($sql01, $conn) or die(mysql_error());



while($newarray = mysql_fetch_array($result)){
	
	$id = $newarray['id'];
	$filename = $newarray['filename'];
	echo "<p> image # $id <img src='test/thumbnail.php?filename=$filename' /></p>";

any ideas?
tim
 
hmmz... for me it displays 10 rows like the query stayted... from 12 to 3 :)

I think you forgot to look at the last number :D
hehe... that query always works fine... and there were no problems with the code... just a tiny little suggestions is to use mysql_fetch_assoc insted of mysql_fetch_array as it it better to use it... in case you would like to know why: i will explain it... however i dont feel like doing that in case no1 wants to know :)
 
Back
Top