Jump to content

Confused on how to do searches with mysql code


eddlandos

Recommended Posts

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

Link to comment
Share on other sites

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.).

Link to comment
Share on other sites

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
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.