Ameslee Posted January 13, 2007 Share Posted January 13, 2007 [code]<?php echo "<a href = \"?search=$category[0]\"> Employment </a> <br> <a href = \"?search=$category[1]\"> Government </a> <br> <a href = \"?search=$category[2]\"> Training </a> <br> <a href = \"?search=$category[3]\"> Rehabilitation </a><br> <a href = \"?search=$category[4]\"> Accommodation </a><br> <a href = \"?search=$category[5]\"> Sport and Leisure </a><br> <a href = \"?search=$category[6]\"> Information </a> <br> <a href = \"?search=$category[7]\"> Personal Support </a> <br> <a href = \"?search=$category[8]\">Education </a> <br> <a href = \"?search=$category[9]\"> Transition to Work </a> <br> <a href = \"?search=$category[10]\"> Community Participation </a><br> </p>"; $hostname = localhost; $username = ; $password = ; $conn = mysql_connect($hostname, $username, $password) or die(mysql_error()); $connection = mysql_select_db("greenac_VORNExpo", $conn); if (in_array($_GET['search'], $category)) { $sql = mysql_query("SELECT * FROM services WHERE category 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>"; } } ?>[/code]can someone tell me why i am getting the following error and how to fix it, thankserror: Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/greenac/public_html/search.php on line 241 Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 13, 2007 Share Posted January 13, 2007 is $category an array? Where is it defined? Quote Link to comment Share on other sites More sharing options...
Ameslee Posted January 13, 2007 Author Share Posted January 13, 2007 i thought i had already done so, how do i do this?thanks Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 13, 2007 Share Posted January 13, 2007 Where? You didn't do anything with it. If you mean in the links, that doesn't make any sense.I think you want something like this[code]$category = array('Employment', 'Government' ); // etc [/code]then[code]foreach($category AS $id=>$cat){ echo '<a href="?search='.$id.'">'.$cat.'</a> <br>';}[/code]Finally[code]if ($category[$_GET['search']]){[/code]Try that. Quote Link to comment Share on other sites More sharing options...
Ameslee Posted January 13, 2007 Author Share Posted January 13, 2007 [quote author=jesirose link=topic=122194.msg503697#msg503697 date=1168653569][code]foreach($category AS $id=>$cat){ echo '<a href="?search='.$id.'">'.$cat.'</a> <br>';}[/code][/quote]Just wondering what $cat is? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 13, 2007 Share Posted January 13, 2007 it's the value in the array. Foreach works like this:$arr = array($key=>$value);So foreach isforeach($arr AS $key=>$value){}But you can call $key and $value whatever you want. $cat is short for $category. Quote Link to comment Share on other sites More sharing options...
Ameslee Posted January 13, 2007 Author Share Posted January 13, 2007 so i have to change those too suit what i have or what u have put is ok to put straight into my code? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 13, 2007 Share Posted January 13, 2007 you can put what I wrote for you.Should search be a number or string? If it's the string, IE: Government, change this line also:$sql = mysql_query("SELECT * FROM services WHERE category LIKE '".$category[$_GET['search']]."%';") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
Ameslee Posted January 13, 2007 Author Share Posted January 13, 2007 is this right[code]<?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="?search='.$id.'">'.$cat.'</a> <br>'; } $hostname = localhost; $username = ; $password = ; $conn = mysql_connect($hostname, $username, $password) or die(mysql_error()); $connection = mysql_select_db("greenac_VORNExpo", $conn); if ($category[$_GET['search']]){ $sql = mysql_query("SELECT * FROM services WHERE category LIKE '".$category[$_GET['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>"; } } ?>[/code] Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 13, 2007 Share Posted January 13, 2007 Looks good, try it! Quote Link to comment Share on other sites More sharing options...
Ameslee Posted January 13, 2007 Author Share Posted January 13, 2007 hey i had a bit of trouble with that but i fixed it, one problem though, here is the code:[code]<?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="?search='.$cat.'">'.$cat.'</a> <br>'; } $hostname = localhost; $username = ; $password = ; $conn = mysql_connect($hostname, $username, $password) or die(mysql_error()); $connection = mysql_select_db("greenac_VORNExpo", $conn); if (in_array($_GET['search'],$category)) { $sql = mysql_query("SELECT * FROM services WHERE category LIKE '".$_GET['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>"; } } ?>[/code]ill try to explain the problem as best as possible. I click a link, it displays a record. if i have more than one category in that field, it wont display it, if i click a link that is a second record, it wont display. so it doesnt look up the second thing in that field Quote Link to comment Share on other sites More sharing options...
Ameslee Posted January 13, 2007 Author Share Posted January 13, 2007 ive worked it out thanks! Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 13, 2007 Share Posted January 13, 2007 Good job :) 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.