Ameslee Posted May 22, 2007 Share Posted May 22, 2007 <?php if(isset($_GET['search'])){ echo "Search Results<br>"; $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 "<a href=\"display_services.php?id=".$row['service2id']."\">" .$row['name']. "</a><br>"; } } if(isset($_GET["search2"])){ echo "Search Results<br>"; $hostname = localhost; $username = ; $password = ; $conn = mysql_connect($hostname, $username, $password) or die(mysql_error()); $connection = mysql_select_db("greenac_VORNExpo", $conn); $search2 = $_GET["search2"]; $sql = mysql_query("SELECT * FROM services WHERE category LIKE '%".$search2."%';") or die(mysql_error()); while ($row = mysql_fetch_array($sql)){ // display results echo "<a href=\"display_services.php?id=".$row['service2id']."\">" .$row['name']. "</a><br>"; } } echo "<p>Find a Service here. </p>"; for ($i = 'A'; $i != 'AA'; $i++){ echo "<a href = \"?search=$i\"> $i </a>"; } ?> </p> <p>OR Choose a Category below:</p> <p> <?php $category = array('Employment', 'Government', 'Training', 'Rehabilitation', 'Accommodation', 'Sport and Leisure', 'Information', 'Personal Support', 'Education', 'Transition to Work', 'Community Participation'); foreach($category as $cat) { echo '<a href="?search2='.$cat.'">'.$cat.'</a> <br>'; } ?> Ok i have a a-z list, where if u click on a letter it looks up every record with that letter, straight forward enough. Then i have a list of categories......some records are not being displayed when they should. If you click on a category it looks up the category field to see if that category is there, then displays the record. Some records have all categories, so in that field, "all" is entered. If a record has "all" it is not displayed if any of the categories are clicked on. how can i fix the above code so if a record as "all" in the category field, it is displayed no matter what category is picked? hope this makes sense.... Quote Link to comment https://forums.phpfreaks.com/topic/52436-display-records-that-have-all-in-category-field/ Share on other sites More sharing options...
sasa Posted May 22, 2007 Share Posted May 22, 2007 change line $sql = mysql_query("SELECT * FROM services WHERE category LIKE '%".$search2."%';") or die(mysql_error()); to $sql = mysql_query("SELECT * FROM services WHERE category LIKE '%".$search2."%' OR category = 'all';") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/52436-display-records-that-have-all-in-category-field/#findComment-258757 Share on other sites More sharing options...
Ameslee Posted May 22, 2007 Author Share Posted May 22, 2007 Thanks, i knew it would be something simple as that...stupid me. Quote Link to comment https://forums.phpfreaks.com/topic/52436-display-records-that-have-all-in-category-field/#findComment-258763 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.