mjurmann Posted November 10, 2006 Share Posted November 10, 2006 Hello. I am trying to use PREVIOUS and NEXT arrows to increment the variable "id" in the URL string so that each time a button is selected, the the id will be incremented or decremented thus pulling all ids with "2" or "0" (depending on what arrow is clicked) out on the next page. Here is what I have so far: <div align="center"> <div id="image_navigation"> <a href="gallery.php?id=<?php echo $row_Recordset1['id']-1; ?>"><img src="../images/previous.jpg" border="0" /></a> <a href="gallery.php?id=<?php echo $row_Recordset1['id']+1; ?>"><img src="../images/next.jpg" border="0" /></a> </div></div>The site where this is not working is: http://www.hotheadbeads.com/htms/gallery.php?id=1As you can see, the arrows do not +1 or -1 when clicking on the arrows. Help please! Link to comment https://forums.phpfreaks.com/topic/26857-incrementing-and-decrementing-url-variables/ Share on other sites More sharing options...
ralph4100 Posted November 10, 2006 Share Posted November 10, 2006 try over two lines of codelike this [code]<?php$plusone=$row_Recordset1['id']++;$minusone=$row_Recordset1['id']--;//then echo as needed//the problem I think is that when you can't do calculation while echoing[/code] Link to comment https://forums.phpfreaks.com/topic/26857-incrementing-and-decrementing-url-variables/#findComment-122831 Share on other sites More sharing options...
oracle259 Posted November 10, 2006 Share Posted November 10, 2006 Without seeing more of ur code I think u should do the calculation outside of the link and echo the result in the link like this[code]$plus = $rec_Recordset1['id'] + 1;$minus = $rec_Recordset1['id'] - 1;<div align="center"> <div id="image_navigation"> <a href="gallery.php?id=<?php echo $minus; ?>"><img src="../images/previous.jpg" border="0" />[/url] <a href="gallery.php?id=<?php echo $plus; ?>"><img src="../images/next.jpg" border="0" />[/url] </div></div>[/code] Link to comment https://forums.phpfreaks.com/topic/26857-incrementing-and-decrementing-url-variables/#findComment-122836 Share on other sites More sharing options...
mjurmann Posted November 10, 2006 Author Share Posted November 10, 2006 <?php$plusone=$row_Recordset1['id']++;$minusone=$row_Recordset1['id']--;I did that, but it still isn't working. Here is all of my code:[code]<?php require_once('../Connections/hotheadbeads.php'); ?><?php$colname_Recordset1 = "-1";if (isset($_GET['id'])) { $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);}mysql_select_db($database_hotheadbeads, $hotheadbeads);$query_Recordset1 = sprintf("SELECT * FROM gallery WHERE id = '%s' ORDER BY caption ASC", $colname_Recordset1);$Recordset1 = mysql_query($query_Recordset1, $hotheadbeads) or die(mysql_error());$row_Recordset1 = mysql_fetch_assoc($Recordset1);$totalRows_Recordset1 = mysql_num_rows($Recordset1);?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><title>Hotheadbeads.com | Flame-torched Glass by Teri Wathan</title><link href="http://www.hotheadbeads.com/css/styles.css" rel="stylesheet" type="text/css" /></head><body bgcolor="#000000"><div align="center"> <div id="container"> <div id="header"></div> <div id="body"> <div id="left_column"> <div class="cssnav"> <a href="http://www.hotheadbeads.com"/><img src="http://www.hotheadbeads.com/images/nav/home1.jpg" alt="" width="192" height="28" /></a> </div> <div class="cssnav2"> <a href="http://www.hotheadbeads.com/htms/gallery.php?id=1"/><img src="http://www.hotheadbeads.com/images/nav/gallery1.jpg" alt="" width="192" height="28" /></a> </div> <div class="cssnav3"> <a href="http://www.hotheadbeads.com/htms/specials.php"/><img src="http://www.hotheadbeads.com/images/nav/specials1.jpg" alt="" width="192" height="28" /></a> </div> <div class="cssnav4"> <a href="http://www.hotheadbeads.com/htms/aboutme.php"/><img src="http://www.hotheadbeads.com/images/nav/aboutme1.jpg" alt="" width="192" height="28" /></a> </div> <div class="cssnav5"> <a href="http://www.hotheadbeads.com/blog/"/><img src="http://www.hotheadbeads.com/images/nav/blog1.jpg" alt="" width="192" height="28" /></a> </div> <div class="cssnav6"> <a href="http://www.hotheadbeads.com/htms/contact.php"/><img src="http://www.hotheadbeads.com/images/nav/contact1.jpg" alt="" width="192" height="28" /></a> </div> <div class="cssnav7"> <a href="http://search.ebay.com/_W0QQsassZhotheadbeads" onclick="window.open(this.href,'newwin'); return false;"/><img src="http://www.hotheadbeads.com/images/nav/ebaylistings1.jpg" alt="" width="192" height="28" /></a> </div> <div id="mailing_list"> <form id="form1" name="form1" method="post" action=""> <table width="95%" border="0" cellspacing="2" cellpadding="0"> <tr> <td><label> <input name="email" type="text" id="email" size="16" /> </label></td> </tr> <tr> <td> </td> </tr> <tr> <td><label> <input type="image" src="http://www.hotheadbeads.com/images/submit_btn.jpg" name="Submit" value="Submit" /> </label></td> </tr> </table> </form> </div> </div> <div id="right_column"> <img src="http://www.hotheadbeads.com/images/gallery_msg.jpg" /><br /> <br /> <div class="gallerycontainer"> <?php do { ?> <br /> <a class="thumbnail" href="#thumb"><img src="<?php echo $row_Recordset1['image']; ?>" border="0" /><span><img src="<?php echo $row_Recordset1['largeimage']; ?>" /><br /> <?php echo $row_Recordset1['caption']; ?></span></a> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> <br /> </div><?php$plusone=$row_Recordset1['id']++;$minusone=$row_Recordset1['id']--;?> <div align="center"> <div id="image_navigation"> <a href="gallery.php?id=<?php echo $minusone; ?>"><img src="../images/previous.jpg" border="0" /></a> <a href="gallery.php?id=<?php echo $plusone; ?>"><img src="../images/next.jpg" border="0" /></a></div> </div> </div> </div> <div id="footer"></div> </div></div></body></html><?phpmysql_free_result($Recordset1);?>[/code] Link to comment https://forums.phpfreaks.com/topic/26857-incrementing-and-decrementing-url-variables/#findComment-122849 Share on other sites More sharing options...
mjurmann Posted November 10, 2006 Author Share Posted November 10, 2006 I echoed out the ['id'] and it says "1". So why isn't it adding or subtracting to 1 when the links are clicked? Argh Link to comment https://forums.phpfreaks.com/topic/26857-incrementing-and-decrementing-url-variables/#findComment-122859 Share on other sites More sharing options...
Monkeymatt Posted November 11, 2006 Share Posted November 11, 2006 [code]$plusone=$row_Recordset1[id]+1;$minusone=$row_Recordset['id']-1;[/code]The way you are doing it changes the actual value of the variable after its value is assigned to the new variable. The better way to do it is the way I have.Monkeymatt Link to comment https://forums.phpfreaks.com/topic/26857-incrementing-and-decrementing-url-variables/#findComment-122932 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.