phpnoobie9 Posted March 1, 2008 Share Posted March 1, 2008 I have a table that I insert my categories into. I then have a form that lists those categories in a drop down menu so I can enter my data according to the category and sent to a different table 'images'. It is then sent to the database with the category name saved in a field called 'category' in the images table. I got the following code to display the list of categories in my category table: //Get categories $categories = 'SELECT * FROM categories ORDER BY name ASC'; $catresults = mysql_query ($categories); $categoryname = 'SELECT category FROM templates WHERE (category=$categories)'; while($categorylist = mysql_fetch_array($catresults)) { ?> <a href="<?php echo URL_PATH ?>indextest.php?category=<?php echo $categoryname ?>"><?php echo $categoryname['category'].'<br />'; ?></a> <?php }*/ I want the list of categories in a link for example like: Beach pictures forest pictures water pictures car pictures... etc.. When I click on the link I want to be able to retrieve everything in the image table that has the category according to the above. How do I do that? Link to comment https://forums.phpfreaks.com/topic/93869-how-do-i-retrieve-and-display-data-according-to-a-field-name/ Share on other sites More sharing options...
zq29 Posted March 1, 2008 Share Posted March 1, 2008 Very basic example: <?php if(isset($_GET['cat'])) { $r = mysql_query("SELECT * FROM `images` WHERE `category`='$_GET[cat]'") or die(mysql_error()); while($rr = mysql_fetch_assoc($r)) { //Do whatever... } } else { $r = mysql_query("SELECT * FROM `categories` ORDER BY `name` ASC") or die(mysql_error()); while($rr = mysql_fetch_assoc($r)) echo "<a href='?cat=$rr[id]'>$rr[name]</a><br />"; } ?> Link to comment https://forums.phpfreaks.com/topic/93869-how-do-i-retrieve-and-display-data-according-to-a-field-name/#findComment-480995 Share on other sites More sharing options...
toplay Posted March 1, 2008 Share Posted March 1, 2008 Use: echo urlencode($categoryname); Then in your indextest.php retrieve the value by using $_GET as in $_GET['category']. http://us2.php.net/manual/en/function.urlencode.php Link to comment https://forums.phpfreaks.com/topic/93869-how-do-i-retrieve-and-display-data-according-to-a-field-name/#findComment-481000 Share on other sites More sharing options...
phpnoobie9 Posted March 1, 2008 Author Share Posted March 1, 2008 Thanks. Link to comment https://forums.phpfreaks.com/topic/93869-how-do-i-retrieve-and-display-data-according-to-a-field-name/#findComment-481003 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.