Ameslee Posted December 31, 2006 Share Posted December 31, 2006 Here is my code so far:[code]<?php for ($i = 'A'; $i != 'AA'; $i++){ echo "<a href = \"?search=$i\"> $i </a>"; } if(isset($_GET['search']) && $_GET['search'] != ''){ $hostname = localhost; $username = ; $password = ; $conn = mysql_connect($hostname, $username, $password) or die(mysql_error()); $connection = mysql_select_db("greenac_VORNExpo", $conn); $search = $_GET['search']; $sql = mysql_query("SELECT * FROM services WHERE name LIKE '$search"."%'") or die(mysql_error()); while ($row = mysql_fetch_array($sql)){ // display results echo "<br><a href=\"display_services.php?id=".$row['service2id']."\">" .$row['name']. "<br>"; } } ?> <p>OR Choose a Category below:<br> <br> <form name="categorySelect" action="display_services.php" method="GET"> <select name="services"> <option value="Employment">Employment</option> <option value="Government">Government</option> <option value="Training">Training</option> <option value="Rehabilitation">Rehabilitation</option> <option value="Accommodation">Accommodation</option> <option value="Sport and leisure">Sport and Leisure</option> <option value="Information">Information</option> <option value="Personal support">Personal Support</option> <option value="Education">Education</option> <option value="Transition to Work">Transition to Work</option> <option value="Community Participation">Community Participation</option> </select> <input type="submit" value="Go" /> </form> <?php if(isset($_GET['category']) && $_GET['category'] != '') { $hostname = localhost; $username = ; $password = ; $conn = mysql_connect($hostname, $username, $password) or die(mysql_error()); $connection = mysql_select_db("greenac_VORNExpo", $conn); $sql = mysql_query("SELECT * FROM services WHERE category='".$_GET['category']."';"); } ?>[/code]Instead of it going straight to another page can it display the records that fall into that category, then click on the record and it goes to another page which displays everything in that table. At the moment i choose a category, click the go button then it goes to another page, which says "no record found". What should i do?I'm not sure weather to put all the php code together?Let me know if you want to see the code for display_services.php. This page works fine from the first lot of php code.can anyone help me plz? Link to comment https://forums.phpfreaks.com/topic/32348-help-with-code/ Share on other sites More sharing options...
Ameslee Posted December 31, 2006 Author Share Posted December 31, 2006 ok, changed it. How do i get the following code to display all records that have the selected category in one of the fields[code]<form name="categorySelect" action="display_services.php" method="GET"> <select name="services"> <option value="Employment">Employment</option> <option value="Government">Government</option> <option value="Training">Training</option> <option value="Rehabilitation">Rehabilitation</option> <option value="Accommodation">Accommodation</option> <option value="Sport and leisure">Sport and Leisure</option> <option value="Information">Information</option> <option value="Personal support">Personal Support</option> <option value="Education">Education</option> <option value="Transition to Work">Transition to Work</option> <option value="Community Participation">Community Participation</option> </select> <input type="submit" value="Go" /> </form> <?php if(isset($_GET['services']) && $_GET['services'] != '') { $hostname = localhost; $username = ; $password = ;$conn = mysql_connect($hostname, $username, $password) or die(mysql_error());$connection = mysql_select_db("greenac_VORNExpo", $conn); $sql = mysql_query("SELECT * FROM services WHERE category='".$_GET['category']."';"); while ($row = mysql_fetch_array($sql)){ // display results echo "<br><a href=\"display_services.php?id=".$row['service2id']."\">" .$row['name']. "<br>"; } } ?>[/code]When the record is created in the first place, the person can enter more than one category in the field. So a category is selected in the drop down menu, then the field 'category' is checked in each record, coming back to display that record if it has that specific category in that field. hope this makes sense. Link to comment https://forums.phpfreaks.com/topic/32348-help-with-code/#findComment-150254 Share on other sites More sharing options...
corbin Posted December 31, 2006 Share Posted December 31, 2006 If I'm understanding right, the user picks categories and the script pulls stuff from those categories from a DB?If thats the case, your sql query cant handle multiple cats and neither can drop down boxes... Link to comment https://forums.phpfreaks.com/topic/32348-help-with-code/#findComment-150257 Share on other sites More sharing options...
Ameslee Posted December 31, 2006 Author Share Posted December 31, 2006 yeah im starting to realise that, thanks. Im considering something else. Link to comment https://forums.phpfreaks.com/topic/32348-help-with-code/#findComment-150262 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.