webweever Posted June 2, 2009 Share Posted June 2, 2009 I've read over about 100 posts on this topic in the forum but can't find anything to get me pointed in the right direction. I'm looking to create links to my categories which I have with the code below. The part I can't get is when I click on the link I want all the records in that particular category echoed below my links. <?PHP include("../includes/db.php"); ?> <?php $sql = "SELECT * FROM category"; $result = mysql_query($sql); $marker_cats = ""; while ($i = mysql_fetch_array($result)) { $catname = $i['cat_name']; $marker_cats .= "<a href=\"test.php?marker_cat=$catname\">$catname</a> <b>|</b> "; } echo $marker_cats ?> <?php $fetch = mysql_query("SELECT * FROM markers WHERE marker_cat LIKE '%$catname%'") or die(mysql_error()); $num=mysql_numrows($fetch); ?> <?php $i=0; while ($i < $num) { $marker_id=mysql_result($fetch,$i,"marker_id"); $name=mysql_result($fetch,$i,"name"); $street=mysql_result($fetch,$i,"street"); $city=mysql_result($fetch,$i,"city"); $state=mysql_result($fetch,$i,"state"); $zip=mysql_result($fetch,$i,"zip"); $url=mysql_result($fetch,$i,"url"); $lat=mysql_result($fetch,$i,"lat"); $lng=mysql_result($fetch,$i,"lng"); $marker_cat=mysql_result($fetch,$i,"marker_cat"); ?> <?php if (isset($_GET['marker_cat'])) { echo '<br>'.$marker_cat. '<br>'.$name; } ?> <?php $i++; } mysql_close($dbh); ?> Any push in the right direction would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/160620-linking-to-db-categories/ Share on other sites More sharing options...
webweever Posted June 3, 2009 Author Share Posted June 3, 2009 Why is my GET not working? <?php if (isset($_GET['$marker_cat'])) { echo '<br/>'.$name.' | '.$url.' | '.$marker_cat. ''; } ?> I can't get the page to "read" the marker_cat from the link and pull the records for that category. Link to comment https://forums.phpfreaks.com/topic/160620-linking-to-db-categories/#findComment-848445 Share on other sites More sharing options...
gevans Posted June 3, 2009 Share Posted June 3, 2009 if (isset($_GET['$marker_cat'])) { should be if (isset($_GET['marker_cat'])) { Link to comment https://forums.phpfreaks.com/topic/160620-linking-to-db-categories/#findComment-848448 Share on other sites More sharing options...
webweever Posted June 3, 2009 Author Share Posted June 3, 2009 I changed that and it now appears no matter what category I click on I get all records that are in a category. I get the same result no matter what link I click on so it's still not catching the marker_cat variable from the links. On tesp.php I get nothing which is correct. On test.php?marker_cat=CAT1 I get the result as test.php?marker_cat=CAT2. Link to comment https://forums.phpfreaks.com/topic/160620-linking-to-db-categories/#findComment-848456 Share on other sites More sharing options...
webweever Posted June 4, 2009 Author Share Posted June 4, 2009 Anyone have any words of wisdom on this? I've been playing around with this for 2 days and can't seem to get it. Link to comment https://forums.phpfreaks.com/topic/160620-linking-to-db-categories/#findComment-849027 Share on other sites More sharing options...
Ken2k7 Posted June 4, 2009 Share Posted June 4, 2009 Why are you constantly closing and opening PHP tags? <?php require '../includes/db.php'; $sql = 'SELECT cat_name FROM category'; $result = mysql_query($sql) or trigger_error('Select SQL failed.', E_USER_ERROR); while ($row = mysql_fetch_assoc($result)) { echo '<a href="test.php?marker_cat=' . $row['cat_name'] . '">' . $row['cat_name'] . '</a> <b>|</b> '; } if (isset($_GET['marker_cat'])) { $marker_cat = mysql_real_escape_string($_GET['marker_cat']); $sql = 'SELECT * FROM category WHERE marker_cat = "' . $marker_cat . '"'; $result = mysql_query($sql) or trigger_error('Marker Category Select SQL failed.', E_USER_ERROR); while ($row = mysql_fetch_assoc($result)) { // echo your data out here } } Link to comment https://forums.phpfreaks.com/topic/160620-linking-to-db-categories/#findComment-849030 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.