Page 1 of 1

Next link by ID

Posted: Wed Mar 29, 2006 1:57 pm
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

Posted: Wed Mar 29, 2006 2:06 pm
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?

Posted: Wed Mar 29, 2006 2:21 pm
by josh
just add 1 to $_GET['id'] and print it out in a link

Posted: Wed Mar 29, 2006 3:22 pm
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