squiblo Posted August 10, 2009 Share Posted August 10, 2009 I have 1 problem with my searching, if I search for anything that is less that 3 characters long, it echos "your search must be more that 3 characters long" but also it will echo "You searched for L. 1 result(s) found". and it will show the results with the letter L in it <?php $search = $_GET['search']; if(strlen($search)<3) { echo "Your search must be at least 3 characters long."; $div_height = 'height:500px;'; $img_height = 'height="500"'; } else { $div_height = 'height:1200px;'; $img_height = 'height="1200"'; } ?> <div id="wb_Shape2" style="position:absolute;top:-60px;left:-15px;<?php echo $div_height; ?>width:793px;z-index:-1;" align="center"> <img src="/Images/body_img.jpg" id="Shape2" align="top" alt="" title="" border="0"<?php echo $img_height; ?> width="793"> </div> <?php //connect to our database mysql_connect("localhost","***","***"); mysql_select_db("***"); //explode our search term $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { //construct query $x++; if ($x==1) $construct .= "username LIKE '%$search_each%'"; else $construct .= " OR username LIKE '%$search_each%'"; } //echo out construct $construct = "SELECT * FROM members WHERE $construct"; $run = mysql_query($construct); $foundnum = mysql_num_rows($run); if ($foundnum==0) echo "You searched for <b>$search</b>. No results found."; else { echo "You searched for <b>$search</b><br>$foundnum result(s) found!<p><hr size='1' width='387'color='#E6E6E6'>"; while ($runrows = mysql_fetch_assoc($run)) { //get data $state = ucwords($runrows['state']); $url = $runrows['url']; $username = ucwords($runrows['username']); $imagelocation = $runrows['imagelocation']; if ($imagelocation == "") { $imagelocation = "./profileimages/noprofilepic.jpg"; } echo " <img src ='$imagelocation' width='100' height='105' border='0' align='left' style='padding-right:10px'><br> <b>$username</b><br> $state<br> <a href='$url'>View Profile</a><br><br><br> <hr size='1' width='387' align='left' color='#E6E6E6'> "; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/169603-search-problem/ Share on other sites More sharing options...
Lyleyboy Posted August 10, 2009 Share Posted August 10, 2009 Not sure I'm getting the right end of the stick here or not but if you put all your query code inside the else then if they only enter an L all they will get is the strlen error message and no query will be executed. Hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/169603-search-problem/#findComment-894773 Share on other sites More sharing options...
squiblo Posted August 10, 2009 Author Share Posted August 10, 2009 not too sure whatr you mean either sorry, i'm not sure which part to move Quote Link to comment https://forums.phpfreaks.com/topic/169603-search-problem/#findComment-894791 Share on other sites More sharing options...
kartul Posted August 10, 2009 Share Posted August 10, 2009 try putting die() after error. Quote Link to comment https://forums.phpfreaks.com/topic/169603-search-problem/#findComment-894793 Share on other sites More sharing options...
Lyleyboy Posted August 10, 2009 Share Posted August 10, 2009 Try some thing like this <div id="wb_Shape2" style="position:absolute;top:-60px;left:-15px;<?php echo $div_height; ?>width:793px;z-index:-1;" align="center"> <img src="/Images/body_img.jpg" id="Shape2" align="top" alt="" title="" border="0"<?php echo $img_height; ?> width="793"> </div> <?php $search = $_GET['search']; if(strlen($search)<3) { echo "Your search must be at least 3 characters long."; $div_height = 'height:500px;'; $img_height = 'height="500"'; } else { $div_height = 'height:1200px;'; $img_height = 'height="1200"'; //connect to our database mysql_connect("localhost","***","***"); mysql_select_db("***"); //explode our search term $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { //construct query $x++; if ($x==1) $construct .= "username LIKE '%$search_each%'"; else $construct .= " OR username LIKE '%$search_each%'"; } //echo out construct $construct = "SELECT * FROM members WHERE $construct"; $run = mysql_query($construct); $foundnum = mysql_num_rows($run); if ($foundnum==0) echo "You searched for <b>$search</b>. No results found."; else { echo "You searched for <b>$search</b><br>$foundnum result(s) found!<p><hr size='1' width='387'color='#E6E6E6'>"; while ($runrows = mysql_fetch_assoc($run)) { //get data $state = ucwords($runrows['state']); $url = $runrows['url']; $username = ucwords($runrows['username']); $imagelocation = $runrows['imagelocation']; if ($imagelocation == "") { $imagelocation = "./profileimages/noprofilepic.jpg"; } echo " <img src ='$imagelocation' width='100' height='105' border='0' align='left' style='padding-right:10px'><br> <b>$username</b><br> $state<br> <a href='$url'>View Profile</a><br><br><br> <hr size='1' width='387' align='left' color='#E6E6E6'> "; } } } ?> Try that, really quick and dirty but it may be what you're after. Quote Link to comment https://forums.phpfreaks.com/topic/169603-search-problem/#findComment-894795 Share on other sites More sharing options...
squiblo Posted August 10, 2009 Author Share Posted August 10, 2009 that works but now if there is more than 3 results the image height stays the same at 500px Quote Link to comment https://forums.phpfreaks.com/topic/169603-search-problem/#findComment-894798 Share on other sites More sharing options...
Lyleyboy Posted August 10, 2009 Share Posted August 10, 2009 that works but now if there is more than 3 results the image height stays the same at 500px Do you mean three results or three charachters in your $search string. Quote Link to comment https://forums.phpfreaks.com/topic/169603-search-problem/#findComment-894803 Share on other sites More sharing options...
Lyleyboy Posted August 10, 2009 Share Posted August 10, 2009 Try putting the DIV code from the top down after all the php has finished. May work for you Quote Link to comment https://forums.phpfreaks.com/topic/169603-search-problem/#findComment-894806 Share on other sites More sharing options...
squiblo Posted August 10, 2009 Author Share Posted August 10, 2009 i have just noticed that the image size changes depending on the amount of characters entered into the search but the image size should change depending on the amound of results on the page Quote Link to comment https://forums.phpfreaks.com/topic/169603-search-problem/#findComment-894808 Share on other sites More sharing options...
Lyleyboy Posted August 10, 2009 Share Posted August 10, 2009 So you need to change the wring length if statement. Still think the div needs to go atthe bottom as it's using variables that you haven't set yet Quote Link to comment https://forums.phpfreaks.com/topic/169603-search-problem/#findComment-894828 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.