Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-03-2002, 02:45 AM   PM User | #1
bcarl314
Mega-ultimate member


 
Join Date: Jun 2002
Location: Winona, MN - The land of 10,000 lakes
Posts: 1,855
Thanks: 1
Thanked 45 Times in 42 Posts
bcarl314 will become famous soon enough
Displaying a portion of a result set

How can I nodify the code below to, by default display the 1st 10 resutls from the query, then at the bottom, display a list Page 1 of 2 | 3 | 4 | 5 and so on.?

Code:
<?php
	include('dbConn.php');
	$i="";
	$linkID = mysql_connect("localhost", "$dbUser", "$dbPass");
	if ($linkID != FALSE) {
		mysql_select_db("$dbName", $linkID);
		$resultID = mysql_query("SELECT * FROM images WHERE catID='$catID'", $linkID);
		$tot=mysql_num_rows($resultID);
		while($row = mysql_fetch_assoc($resultID)) {
			$iName= $row['imageName'];
			$iID= $row['imageID'];
			$iWords = $row['keywords'];
			$desc = $row['descTxt'];
			print "<img src='images/small/".$iID.".jpg' align='left' alt='".$iWords."' border='2' bordercolor='black' height='120'>";
			print "<b>".$iName."</b><br>";
			print "<font class='main'>";
			if($desc!=null) {
				include("$desc");
			}
			//print "This is where I need to add a nice little description for this image.<br>Now I've just got to get off my lazy but and do it.";
			print "</font>";
			print "<a href='photos.php?imageID=".$iID."'>Click here to see more about this photograph!</a>";
			print "<br clear='all'><hr>";
		}
	}
	else {
		print "Bad Connection";
	}
	mysql_close($linkID);
?>
I've tried using the limit for my sql, but I get errors. Any help is appreciated.
Thanks.
bcarl314 is offline   Reply With Quote
Old 07-03-2002, 07:55 AM   PM User | #2
Cloudski
Regular Coder

 
Join Date: Jul 2002
Location: U.S. (Wish Japan though)
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Cloudski is an unknown quantity at this point
Well, I uh... don't know much about PHP, but couldn't you set the displaying part of the code(the whole thing) In a for-loop, and st a variable so that whenever it reaches a number, set next page?

Sorry if I am not much help... I am still a newbie at this
Cloudski is offline   Reply With Quote
Old 07-03-2002, 09:02 AM   PM User | #3
Jeewhizz
Regular Coder


 
Join Date: May 2002
Location: London, England
Posts: 369
Thanks: 0
Thanked 0 Times in 0 Posts
Jeewhizz is an unknown quantity at this point
Use something like this

PHP Code:
$query "SELECT * FROM table LIMIT $limit,25";
$result mysql_db_query($db,$query,$connect);
while(
$row mysql_fetch_assoc($result)) {
$iName$row['imageName'];
$iID$row['imageID'];
$iWords $row['keywords'];
$desc $row['descTxt'];
print 
"<img src='images/small/".$iID.".jpg' align='left' alt='".$iWords."' border='2' bordercolor='black' height='120'>";
print 
"<b>".$iName."</b><br>";
print 
"<font class='main'>";
if(
$desc!=null) {
include(
"$desc");
    }
//print "This is where I need to add a nice little description for this image.<br>Now I've just got to get off my lazy but and do it.";
print "</font>";
print 
"<a href='photos.php?imageID=".$iID."'>Click here to see more about this photograph!</a>";
print 
"<br clear='all'><hr>";
}
}
else {
print 
"Bad Connection";
}

$total mysql_num_rows($result);

$foo $total 25;
$foo=$foo+1;
$limit=0;
echo 
"<p>&nbsp;</p>";
echo 
"<center>Go to page: | ";
for(
$i=1;$i<$foo;$i++)
{
  echo 
"<a href=\"$PHP_SELF?limit=$limit\">$i</a> | ";
  
$limit $limit 25;

Hope that helps

Jee
__________________
Jeewhizz - MySQL Moderator
http://www.sitehq.co.uk
PHP and MySQL Hosting
Jeewhizz is offline   Reply With Quote
Old 07-03-2002, 11:18 AM   PM User | #4
bcarl314
Mega-ultimate member


 
Join Date: Jun 2002
Location: Winona, MN - The land of 10,000 lakes
Posts: 1,855
Thanks: 1
Thanked 45 Times in 42 Posts
bcarl314 will become famous soon enough
Jee,

Thanks for the code, that almost exactly what I was trying to do, then I get a undefined variable limit error the first time through.

When someone enters this page the string is...
http://localhost/photos.php?catID=1

Do I need to change all those links to
http://localhost/photos.php?catID=1&limit=0
for the initial viewing?

I trind to use something like
if(!isset($limit)) {
$limit=0;
}
but that seems to throw an error???undef var limit grr

I keep thinking it should work, but it don't.
bcarl314 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:44 PM.


Advertisement
Log in to turn off these ads.