suckerr70 Posted January 4, 2008 Share Posted January 4, 2008 Now I have this code to call and display my blog stuff. I was wondering if I could make it so if I click a link (<a>Pizza</ a>), it can change "WHERE categoryID='food'" to "WHERE subcategoryID='pizza'". Also, how would I make it cut off after 20, and have a "nest page" link to show the next 20? Thanks! <?php $con = mysql_connect($host,$name,"$pass); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("$db", $con); $result = mysql_query("SELECT * FROM post2 WHERE categoryID='food'"); while($row = mysql_fetch_array($result)) { echo "<h2>" . $row['name'] . "</h3>"; echo "<p>" . $row['address'] . "<br />"; echo $row['phone'] . "</p><br />"; echo "<p>" . $row['description'] . "</p>"; echo "<p>---</p>"; echo "<br />"; } mysql_close($con); ?> Link to comment https://forums.phpfreaks.com/topic/84415-solved-links-changing-script/ Share on other sites More sharing options...
phpQuestioner Posted January 4, 2008 Share Posted January 4, 2008 set your "categoryID" up as a variable and use/set-up a limit with a variable as well. something like this: <?php $con = mysql_connect($host,$name,"$pass); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("$db", $con); $cid = $_GET['cid']; $stophere = $_GET['stop']; if ($cid == NULL) { $cid="food"; } if ($stophere == NULL) { $stophere="20"; } $result = mysql_query("SELECT * FROM post2 WHERE categoryID='$cid' LIMIT $stophere"); while($row = mysql_fetch_array($result)) { echo "<h2>" . $row['name'] . "</h3>"; echo "<p>" . $row['address'] . "<br />"; echo $row['phone'] . "</p><br />"; echo "<p>" . $row['description'] . "</p>"; echo "<p>---</p>"; echo "<br />"; } mysql_close($con); ?> then set your link up like this: <a href="pagename.php?cid=pizza&stop=40">Next Page</a> of course you will have to add in a little bit of math code for completely automated pagination; if that is what your wanting. Link to comment https://forums.phpfreaks.com/topic/84415-solved-links-changing-script/#findComment-430104 Share on other sites More sharing options...
suckerr70 Posted January 4, 2008 Author Share Posted January 4, 2008 Thanks so much! That solves everything. Link to comment https://forums.phpfreaks.com/topic/84415-solved-links-changing-script/#findComment-430254 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.