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? Quote Link to comment 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 />"; } ?> Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
phpnoobie9 Posted March 1, 2008 Author Share Posted March 1, 2008 Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.