Next link by ID

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Next link by ID

Post by psurrena »

Could someone please help explain the process for creating a"next" link that just jumps to the id in my DB.

The code below is for an image portfolio. This portion of the code is the result when clicking on a thumbnail. So, how would I create a "next" button to show the next item in the portfolio?

Thank you in advance.

Code: Select all

...previous code

else { 
    $query   = "SELECT * FROM port WHERE id=".$_GET['id']; 
    $result  = mysql_query($query) or die('Error : ' . mysql_error());  
    $row     = mysql_fetch_array($result, MYSQL_ASSOC);  
    
    $title = $row['title']; 
    $category = $row['category']; 
    $description = $row['description'];
    $url = $row['url'];
    $path = $row['path'];
	
    $content .= "<table cellpadding=0 cellspacing=0 width=370 height=373>
					<tr valign=middle>
						<td width=370 bgcolor=#ffffff>
							<p align=center><img src=phpThumb.php?src=$path&h=280></p>
							<p align=center><a href=$path rel=lightbox title=$title>enlarge</a></p>
							<br />
						</td>
					</tr>
					<tr valign=bottom>
						<td>
							<table width=330 cellspacing=0 cellpadding=2 bgcolor=#61B329>
								<tr valign=top><td width=80 align=right class=light>company:</td><td><b class=white>$title</b></td></tr>
								<tr valign=top><td align=right class=light>category:</td><td class=white>$category</td></tr>
								<tr valign=top><td align=right class=light>description:</td><td class=white>$description<p><a href=\"http://$url\" target=\"_blank\" class=\"white\">$url</a></p></td><td></td></tr>
							</table>	
						</td>	
					</tr>
				</table>"; 
} 

...clode db code
nincha
Forum Contributor
Posts: 191
Joined: Fri Mar 28, 2003 12:30 pm
Location: CA, USA

Post by nincha »

where is 'id', to use for creating a"next" link that just jumps to the id in my DB, coming from? is it from $row array?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

just add 1 to $_GET['id'] and print it out in a link
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Post by psurrena »

So here it is work, thanks everyone!

Code: Select all

...code

 else { 
    $query   = "SELECT * FROM port WHERE id=".$_GET['id']; 
    $result  = mysql_query($query) or die('Error : ' . mysql_error());  
    $row     = mysql_fetch_array($result, MYSQL_ASSOC);  
    
    $id = $row['id'];
    $title = $row['title']; 
    $category = $row['category']; 
    $description = $row['description'];
    $url = $row['url'];
	$path = $row['path'];
	$next = $id + 1; 
	$prev = $id - 1; 
	
    $content .= "<table cellpadding=0 cellspacing=0 width=370 height=373>
					<tr valign=middle>
						<td width=370 bgcolor=#ffffff>
							<p align=center><img src=phpThumb.php?src=$path&h=280></p>
							<p align=center><a href=$path rel=lightbox title=$title>+ enlarge</a> | <a href=index.php?id=$prev>Prev</a> | <a href=index.php?id=$next>Next</a></p>
							<br />
						</td>
					</tr>
					<tr valign=bottom>
						<td>
							<table width=330 cellspacing=0 cellpadding=2 bgcolor=#61B329>
								<tr valign=top><td width=80 align=right class=light>company:</td><td><b class=white>$title</b></td></tr>
								<tr valign=top><td align=right class=light>category:</td><td class=white>$category</td></tr>
								<tr valign=top><td align=right class=light>description:</td><td class=white>$description<p><a href=\"http://$url\" target=\"_blank\" class=\"white\">$url</a></p></td><td></td></tr>
							</table>	
						</td>	
					</tr>
				</table>"; 
}     

...close connection
Post Reply