ted_chou12 Posted December 30, 2006 Share Posted December 30, 2006 I have three input values, username, gender, photo, here i am plugging in the $user into the gender[code]<?phpif ($gender == "Boy"){$read = mysql_query("SELECT username FROM userinfo WHERE gender='Boy' AND username='$user'") or die(mysql_error());$row = mysql_fetch_array($read); $user = $row['username'];}if ($gender == "Girl"){$read = mysql_query("SELECT username FROM userinfo WHERE gender='Girl' AND username='$user") or die(mysql_error());$row = mysql_fetch_array($read); $user = $row['username'];}?>[/code]This is the photo, but i dont know how to plug the username filtered from the last one in[code]<?phpif ($photo == "Yes"){$read = mysql_query("SELECT username FROM usercus WHERE photo!='' AND username='$user'") or die(mysql_error());//I dont know if the varialbe $user is correct.$row = mysql_fetch_array($read); $user = $row['username'];}if ($photo == "No"){$read = mysql_query("SELECT username FROM usercus WHERE photo='' AND username='$row'") or die(mysql_error());//same as for this one.$row = mysql_fetch_array($read); $user = $row['username'];}Thanks Ted[/code] Link to comment https://forums.phpfreaks.com/topic/32312-solved-mysql-search/ Share on other sites More sharing options...
ted_chou12 Posted December 30, 2006 Author Share Posted December 30, 2006 Acually, I dont know what I have done wrong at all, this is all of it:[code]<?phpif(isset($_POST['searchuser'])){$user = $_POST['search_query'];$age = $_POST['age'];$gender = $_POST['gender'];$photo = $_POST['photo'];$datetime = date("Y-m-d");$ages = array('no preference' => '','under 20' => '1','20-29' => '2','30-39' => '3','40-49' => '4','50-59' => '5','60 above' => '6',);$age_select = "";foreach ($ages as $range => $year) {if ($range == $age) {$age_select = $year;}}// connect to mysql belowrequire("../mysqlconnection.php");if ($photo == "Yes"){$read = mysql_query("SELECT username FROM usercus WHERE photo!='' AND username like '%$user%'") or die(mysql_error());$row = mysql_fetch_array($read);}if ($photo == "No"){$read = mysql_query("SELECT username FROM usercus WHERE photo='' AND username like '%$user%'") or die(mysql_error());$row = mysql_fetch_array($read); $user = $row['username'];}if ($gender == "Boy"){$read = mysql_query("SELECT username FROM userinfo WHERE gender='Boy' AND username like '%$user%'") or die(mysql_error());$row = mysql_fetch_array($read); $user = $row['username'];}if ($gender == "Girl"){$read = mysql_query("SELECT username FROM userinfo WHERE gender='Girl' AND username like '%$user%'") or die(mysql_error());$row = mysql_fetch_array($read); $user = $row['username'];}if($age_select != ""){$read = mysql_query("SELECT username FROM userinfo WHERE age like '$age_select%' AND username like '%$user%'") or die(mysql_error());$row = mysql_fetch_array($read); $user = $row['username'];}?>[/code]The weird thing is that I tried for 30~39 range, it appears the 30s range as well as the 60s range, but when i searched for the 60s range, it appears only the 60s range...Can anyone help me with this, btw, the gender doesnt work at all... photo i havent try yet.ThanksTed Link to comment https://forums.phpfreaks.com/topic/32312-solved-mysql-search/#findComment-150008 Share on other sites More sharing options...
dbo Posted December 30, 2006 Share Posted December 30, 2006 Please rephrase the question, no idea what you're asking. Link to comment https://forums.phpfreaks.com/topic/32312-solved-mysql-search/#findComment-150069 Share on other sites More sharing options...
ted_chou12 Posted December 31, 2006 Author Share Posted December 31, 2006 I want to have a muti categorized search, so i can get a targeted group, like male 20~29, or female 50~59, but I dont know how to put the two categories together. My search doesnt work, I wish anyone could have a look at it and give me some suggestions.Ted Link to comment https://forums.phpfreaks.com/topic/32312-solved-mysql-search/#findComment-150377 Share on other sites More sharing options...
ted_chou12 Posted December 31, 2006 Author Share Posted December 31, 2006 Can anyone please help me with this? Thankyou... I realy need help. Link to comment https://forums.phpfreaks.com/topic/32312-solved-mysql-search/#findComment-150553 Share on other sites More sharing options...
emehrkay Posted January 1, 2007 Share Posted January 1, 2007 Ted condense your code. You're repeating the same thing over and over again. The only thing that you need to build is the where clause of the query[code]<?php$where = '';if ($photo == "No"){ $where .= 'photo='' AND ';}if($age_select != ""){ $where .= 'age like '. $age_select .'% AND '; }$read = mysql_query("SELECT username FROM userinfo WHERE ". $where ."username like '%$user%'") or die(mysql_error());$row = mysql_fetch_array($read); $user = $row['username'];?>[/code]if you do it that way, you could buld the where clause with all of those values included Link to comment https://forums.phpfreaks.com/topic/32312-solved-mysql-search/#findComment-150568 Share on other sites More sharing options...
ted_chou12 Posted January 1, 2007 Author Share Posted January 1, 2007 thanks, but I dont quite understand, what are the "." beside $where . << where for? and I think there is a syntax mistake inside, because my page doesnt show anything ( i cant configure it to make it show error.) Thanks a lot for the help by the way.Ted Link to comment https://forums.phpfreaks.com/topic/32312-solved-mysql-search/#findComment-150601 Share on other sites More sharing options...
emehrkay Posted January 1, 2007 Share Posted January 1, 2007 it is the concatenator, it adds the value of $where to iteself so if $photo == no and $age_select was set it would be"photo = '' AND age like whatevervar% AND" Link to comment https://forums.phpfreaks.com/topic/32312-solved-mysql-search/#findComment-150663 Share on other sites More sharing options...
ted_chou12 Posted January 1, 2007 Author Share Posted January 1, 2007 thanks, i understand. Link to comment https://forums.phpfreaks.com/topic/32312-solved-mysql-search/#findComment-150756 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.