eddlandos Posted June 19, 2011 Share Posted June 19, 2011 Anyone know why this won't work ? SELECT * FROM username a LEFT JOIN profilepicture b ON a.username = b.username WHERE a.sexuality NOT LIKE '$sexuality' OR a.sexuality = '$sexuality' AND bodytype LIKE '$bodytype' OR bodytype NOT LIKE '$bodytype' AND `default` =1 Quote Link to comment https://forums.phpfreaks.com/topic/239825-confused-on-how-to-do-searches-with-mysql-code/ Share on other sites More sharing options...
ebmigue Posted June 20, 2011 Share Posted June 20, 2011 If you could tell us what you are trying to achieve, maybe we could help. It is difficult to guess your intended results by just looking at the posted SQL expression (i.e., query), since it might be incorrect. Also, please provide a sample SQL script with the sample data, for testing purposes (of course we do not need the whole data, as it might be very large; a small sample will do.). Quote Link to comment https://forums.phpfreaks.com/topic/239825-confused-on-how-to-do-searches-with-mysql-code/#findComment-1232011 Share on other sites More sharing options...
fugix Posted June 20, 2011 Share Posted June 20, 2011 Your syntax is wrong, you are trying to specify an alias in the wrong place. Look here for correct syntax Quote Link to comment https://forums.phpfreaks.com/topic/239825-confused-on-how-to-do-searches-with-mysql-code/#findComment-1232025 Share on other sites More sharing options...
eddlandos Posted June 20, 2011 Author Share Posted June 20, 2011 it should be able to grab the form input when it sees the word Any from the form input it doesn't search for it Quote Link to comment https://forums.phpfreaks.com/topic/239825-confused-on-how-to-do-searches-with-mysql-code/#findComment-1232241 Share on other sites More sharing options...
fugix Posted June 20, 2011 Share Posted June 20, 2011 Perhaps if you post a bigger chunk of code surrounding the error we can be of more assistance Quote Link to comment https://forums.phpfreaks.com/topic/239825-confused-on-how-to-do-searches-with-mysql-code/#findComment-1232287 Share on other sites More sharing options...
eddlandos Posted June 20, 2011 Author Share Posted June 20, 2011 function searchadvanced($sexuality) { if(isset($_POST['Submit'])) { $this->connect(); $sexuality = $_POST['txtSexuality']; $bodytype = $_POST['txtBodyType']; $sql = mysql_query("SELECT * FROM username a LEFT JOIN profilepicture b ON a.username = b.username WHERE sexuality NOT LIKE '$sexuality' OR sexuality = '$sexuality' AND bodytype LIKE '$bodytype' OR bodytype NOT LIKE '$bodytype' AND `default` =1"); $result=mysql_query($sql); echo "<h4>Results</h4>"; while ($numrows=mysql_fetch_assoc($sql)) { $picturethumb = $numrows['small']; $username = $numrows['username']; echo '<a href="viewprofile.php?username='.$username.'"><img src="' .$picturethumb. '"/></a>'; echo '<a href="viewprofile.php?username='.$username.'">'.$username.'</a>'; } } $this->close(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> </head> <body> <div id="wrapper"> <div class="cent"><h1>Search Advanced</h1></div> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" name="search"> Username <br /> <input name="Username" type="text" value="" size="30" maxlength="30" /><br /> Location <br /> <input name="Location" type="text" value="" size="30" maxlength="30" /><br /> <?php echo 'Looking For <br />'; $options = array( 'Relationship' => 'Relationship', 'Dating' => 'Dating', 'Friends' => 'Friends', 'Fun' => 'Fun' ); echo '<select name="txtLookingfor">'; foreach ($options as $key=>$val) { echo '<option value="' . $key . '" >' . $val . '</option>'; } echo '</select><br />'; echo 'Height <br />'; $options = array( 'Short' => 'Short', 'Medium' => 'Medium', 'Tall' => 'Tall' ); echo '<select name="Height">'; foreach ($options as $key=>$val) { echo '<option value="' . $key . '">' . $val . '</option>'; } echo '</select><br />'; echo 'Status <br />'; $options = array( 'Single' => 'Single', 'Open Relationship' => 'Open Relationship', 'Not Single' => 'Not Single', 'Looking For Friends' => 'Looking For Friends' ); echo '<select name="txtStatus">'; foreach ($options as $key=>$val) { echo '<option value="' . $key . '" >' . $val . '</option>'; } echo '</select><br />'; echo 'Smoker <br />'; $options = array( 'Non-Smoker' => 'Non-Smoker', 'Regular' => 'Regular', 'Lots' => 'Lots', 'Social Smoker' => 'Social Smoker' ); echo '<select name="Smoker">'; foreach ($options as $key=>$val) { echo '<option value="' . $key . '" >' . $val . '</option>'; } echo '</select><br />'; echo 'Bodytype <br />'; $options = array( 'Any' => 'Any', 'Thin' => 'Thin', 'Athletic' => 'Athletic', 'Average' => 'Average', 'Extra Padding' => 'Extra Padding', 'BBW' => 'BBW' ); echo '<select name="txtBodyType">'; foreach ($options as $key=>$val) { echo '<option value="' . $key . '" >' . $val . '</option>'; } echo '</select><br />'; // lots of options that need LIKE IN mysql query $options = array( 'Any' => 'Any', 'Straight' => 'Straight', 'Bisexual' => 'Bisexual', 'Open-Minded' => 'Open-Minded', 'Gay/Lesbian' => 'Gay/Lesbian' ); echo 'Sexuality <br /><select name="txtSexuality">'; foreach ($options as $key=>$val) { echo '<option value="' . $key . '" >' . $val . '</option>'; } echo '</select><br /><br />'; ?> <input name="Submit" type="submit" value="Search" /> </form> <br /> </div> </body> </html> <?php } Quote Link to comment https://forums.phpfreaks.com/topic/239825-confused-on-how-to-do-searches-with-mysql-code/#findComment-1232296 Share on other sites More sharing options...
fugix Posted June 20, 2011 Share Posted June 20, 2011 Have you tried debugging your query quickly? $result = mysql_query($sql) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/239825-confused-on-how-to-do-searches-with-mysql-code/#findComment-1232298 Share on other sites More sharing options...
eddlandos Posted June 20, 2011 Author Share Posted June 20, 2011 yeah just returns white... Quote Link to comment https://forums.phpfreaks.com/topic/239825-confused-on-how-to-do-searches-with-mysql-code/#findComment-1232299 Share on other sites More sharing options...
fugix Posted June 20, 2011 Share Posted June 20, 2011 Do you have error reporting set to show all errors. error_reporting(-1) And display errors on ini_set('display_errors','On'); Quote Link to comment https://forums.phpfreaks.com/topic/239825-confused-on-how-to-do-searches-with-mysql-code/#findComment-1232302 Share on other sites More sharing options...
eddlandos Posted June 20, 2011 Author Share Posted June 20, 2011 Warning: mysql_close() expects parameter 1 to be resource, null given in /var/www/dating/class.search.php on line 246 Quote Link to comment https://forums.phpfreaks.com/topic/239825-confused-on-how-to-do-searches-with-mysql-code/#findComment-1232303 Share on other sites More sharing options...
eddlandos Posted June 20, 2011 Author Share Posted June 20, 2011 fixed myself basically what I needed to use is % for the form input, because mysql doesn't use * for everything... Quote Link to comment https://forums.phpfreaks.com/topic/239825-confused-on-how-to-do-searches-with-mysql-code/#findComment-1232352 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.