Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Help with sql query search
Old 01-18-2005, 07:44 PM Help with sql query search
Junior Talker

Posts: 2
Trades: 0
Hi i am trying to have a search box on my site where there is a different search variables such as man looking for woman in drop down boxes and country in a drop down box and state which is a text field for them to type in the name. The problem with it is, is that when i do a search it wont find any results unless there is the exact state which a user is in the database like say ontario as state
so run down i am searching
man
looking for woman both drop downs
country drop down box canada
state text box i put nothing
my results i get are no results found

but if i search doingthe same with state as ontario then the ontario results are displayed
in other words all fields must be filled in and must be exact i would like it so if they put nothing in the state field the canada people would still be found from the database but also if they do decide to put ontario as stae then the canada ontario results would be found specifically
Thanks for anyhelp in advanced
btw i am new to php so take it easy on me lol

$tabsearch=true;
$tabempty=false;
$tabdating=false;
$tabdatingpic=false;



if(isset($result)){
$end=+$search_result;
$start=$result*$end;
}


if($search){

if(!empty($pic)){
$sqlSearchPic=mysql_query("SELECT DISTINCT (i.userid) AS id, p.ptitle,i.imgstatus, p.adddate FROM datingwa_profile p, datingwa_userimage i
WHERE p.userid = i.userid AND p.psex = '$sex2' AND p.country = '$country' OR p.state LIKE '%*%' AND i.imgstatus = '2'
GROUP BY id ORDER BY p.adddate DESC ");
if(!empty($sqlSearchPic)){
$picnum=mysql_num_rows($sqlSearchPic);
if($picnum >=1){
$tabdatingpic=true;
}else if($picnum==0){
$tabempty=true;
}
}
}
else if(empty($pic)){

$sqlSearchAlle=mysql_query("SELECT * FROM datingwa_profile WHERE psex = '$sex2' AND pcountry = '$country' OR p.state LIKE '%*%' order by adddate desc");

if(!empty($sqlSearchAlle)){
$allenum=mysql_num_rows($sqlSearchAlle);
if($allenum >=1){
$tabdating=true;
}else if($allenum==0){
$tabempty=true;
}
}
}
}
?>
<html>
<head>
<title> search </title>
<?php include("metatag.php"); ?>
<link href="style.css" rel="stylesheet" type="text/css">
</head>

<body>
<table width="790" align="center">
<tr>
<th width="790" height="100" colspan="2" align="left" valign="top" scope="col"><?php include("head.php"); ?></th>
</tr>
<tr>
<th width="790" height="100" colspan="2" align="left" valign="top" scope="col"><table width="790" border="0" cellpadding="0" cellspacing="0" bordercolor="#000000">
<tr>
<th align="left" valign="top" scope="col"><table width="788" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="200" bgcolor="#B9D3EE"><?php include("tablogin.php"); ?></td>
<td width="590" bgcolor="#B9D3EE" align="center"><?php include("main_top.php"); ?></td>
</tr>
</table></th>
</tr>
</table></th>
</tr>
<tr>
<th width="200" height="500" align="left" valign="top" scope="col"><?php include("main_left.php"); ?></th>
<th width="580" align="center" valign="top" scope="col"><table width="570" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<th width="570" align="center" scope="col"><table width="350" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000">
<tr>
<th width="350" bgcolor="#B9D3EE" scope="col"><?php print "$Search_MSG";?></th>
</tr>
<tr>
<th width="350" border="1" bordercolor="#ff0000" align="center" scope="col">

<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">
<?php if($tabsearch){ ?>
<form action="<?php print "$PHP_SELF"; ?>" method="post">
<table width="350" border="0" cellspacing="5" cellpadding="0">
<tr>
<td width="350"><table width="350" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="150" align="right"><?php print "$Search_Iam_MSG";?></td>
<td width="200"><select name="sex1" >
<option value="<?php print "$Add_Pro_Male";?>"><?php print "$Search_Man_MSG";?>
<option value="<?php print"$Add_Pro_Female"; ?>"><?php print "$Search_Women_MSG"; ?>
</select></td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="350" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="150" align="right"><?php print "$Search_search_MSG";?></td>
<td width="200"><select name="sex2" >
<option value="<?php print"$Add_Pro_Female"; ?>"><?php print"$Search_Women_MSG"; ?>
<option value="<?php print "$Add_Pro_Male";?>"><?php print "$Search_Man_MSG";?>
</select></td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="350" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="150" align="right"><?php print "$Search_Country_MSG";?></td>
<td width="200" align="left"><select name="country">
<?php $Sql_country=mysql_query("select* from datingwa_country order by country asc ");
if(!empty($Sql_country)){
while($row_country=mysql_fetch_array($Sql_country) ){
$country_name=$row_country["country"];
$country_id=$row_country["countryid"];
?>
<option value="<?php print"$country_name" ?>"><?php print "$country_name";?></option>
<?php
}
}
?>
</select></td>
</tr>
</table></td>
</tr>
<td><table width="350" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="150" align="left"><?php print "$Search_State_MSG"; ?></td>
<td width="200" align="left"><input name="state" type="text" value="<?php print "$state" ?>" size="20" maxlength="39"></td>
</td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="350" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="40" align="center"><input name="pic" type="checkbox" ></td>
<td width="310" align="left"><?php print "$Search_Showpic_MSG";?></td>
</tr>
</table></td>
</tr>
<tr>
<td align="center"><input name="search" type="submit" value="<?php echo"$Search_Submit_MSG";?>"></td>
</tr>
</table>
</form>
<?php } ?>
</td>
</tr>
<tr>
<td align="center"><?php if($tabempty){ ?>
<table width="350" border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="375" scope="col"><?php print "$Search_Empty_MSG";?> </th>
</tr>
</table>
<?php } ?></td>
</tr>
</table>
</th>
</tr>
</table></th>
</tr>
<tr>
<td width="570" align="center"><?php if($tabdatingpic){ ?>
<table width="552" border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="590" scope="col"><table width="550" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000">
<tr>
<th width="550" align="left" bgcolor="#B9D3EE" scope="col"><table width="550" cellspacing="0" cellpadding="0">
<tr>
<th width="325" align="left" scope="col"><?php print "$Dating_Titel"; ?></th>
<th width="140" scope="col"><?php print "$Dating_Date"; ?></th>
<th width="85" scope="col"><?php print "$Dating_Pic"; ?></th>
</tr>
</table></th>
</tr>
<tr>
<td width="550" align="left" bordercolor="#FF0000"><table width="550" align="center" cellpadding="0" cellspacing="0">
<?php

if($picnum >=1){
while($rowprofil=mysql_fetch_array($sqlSearchPic)) {
$img_userid=$rowprofil["id"];
$profil_title=$rowprofil["ptitle"];
$profil_adddate=$rowprofil["adddate"];
$img_status=$rowprofil["imgstatus"];

if($img_status==2){
$pic=$Dating_Pic_yes;
}else{
$pic=$Dating_Pic_no;
}
?>
<tr>
<th width="325" align="left" scope="col"><a href="<?php print "dating.php?userid=$img_userid"?>" target="_blank"><?php print "$profil_title"; ?></a></th>
<th width="140" scope="col"><?php print "$profil_adddate"; ?></th>
<th width="85" scope="col"><?php print "$pic"; ?></th>
</tr>
<?php } } ?>
</table></td>
</tr>
</table></th>
</tr>
<tr>
<td align="center">&nbsp;</td>
</tr>
</table>
<?php } ?></td>
</tr>
<tr>
<td width="570" align="center"><?php if($tabdating){ ?>
<table width="550" border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="590" align="center" scope="col"><table width="550" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000">
<tr>
<th width="550" align="left" bgcolor="#B9D3EE" scope="col"><table width="550" cellspacing="0" cellpadding="0">
<tr>
<th width="325" align="left" scope="col"><?php print "$Dating_Title"; ?></th>
<th width="140" scope="col"><?php print "$Dating_Date"; ?></th>
<th width="85" scope="col"><?php print "$Dating_Pic"; ?></th>
</tr>
</table></th>
</tr>
<tr>
<td width="550" bordercolor="#FF0000"><table width="550" align="center" cellpadding="0" cellspacing="0">
<?php

if($allenum >=1) {
while($rowprofil2=mysql_fetch_array($sqlSearchAlle )){
$profil_userid=$rowprofil2["userid"];
$profil_title=$rowprofil2["ptitle"];
$profil_adddate=$rowprofil2["adddate"];


$Sqlimage2=mysql_query("select* from datingwa_userimage where userid='$profil_userid' AND imgstatus='2' ");
if(!empty($Sqlimage2)){
$numimg=mysql_num_rows($Sqlimage2);
if($numimg==1){
$pic=$Dating_Pic_yes;
}else{
$pic=$Dating_Pic_no;
}
}
?>
<tr>
<th width="325" align="left" scope="col"><a href="<?php print "dating.php?userid=$profil_userid"?>" target="_blank"><?php print "$profil_title"; ?></a></th>
<th width="140" scope="col"><?php print "$profil_adddate"; ?></th>
<th width="85" scope="col"><?php print "$pic"; ?></th>
</tr>
<?php } } ?>
</table></td>
</tr>
</table></th>
</tr>
<tr>
<td align="center">&nbsp;</td>
</tr>
</table>
<?php } ?></td>
</tr>
</table></th>
</tr>
<tr align="right" valign="top">
<th width="200" height="13" scope="col">&nbsp;</th>
<th width="590" height="13" align="center" scope="col"><?php include("footer.php"); ?></th>
</tr>
</table>
</body>
</html>
davediab is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-18-2005, 07:46 PM
Junior Talker

Posts: 2
Trades: 0
PS if you need to view what i am talking about for better example you can view it here
http://takeachance.ta.funpic.org/dat...1.5/search.php
davediab is offline
Reply With Quote
View Public Profile
 
Old 01-18-2005, 08:18 PM
foobar's Avatar
Extreme Talker

Posts: 225
Trades: 0
I don't have the time to check that out right now, but next time, please, PLEASE use the tags at your disposal to display your code.
foobar is offline
Reply With Quote
View Public Profile Visit foobar's homepage!
 
Reply     « Reply to Help with sql query search
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23783 seconds with 12 queries