| | |
I have problem with two value search
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2008
Posts: 6
Reputation:
Solved Threads: 0
Dear All,
I have problem with two value search, Please kindly see my code below:
My problem is when I choose the location=All location is ok but when I choose both Values it doesn't select the right criteria that I wish.
I have problem with two value search, Please kindly see my code below:
php Syntax (Toggle Plain Text)
<? require("../Dbconnect/db_connect.php");?> <form action="./" method="get"> <table width="100%" cellpadding="0" cellspacing="0" border="0" align="center"> <tr><td width="91%" align="right"> <select name="Catid"> <option value="0" selected>All Categories</option> <? $cats="select * from tbljobcat order by Catname asc"; $catre=mysql_query($cats); while($catr=mysql_fetch_array($catre)){ ?> <option value="<?=$catr['Catid']?>"><?=$catr['Catname']; ?></option><? }?> </select> <select name="Locid"> <option value="0" selected>All Locations</option> <? $locsql="select * from tbljoblocation order by Locname asc"; $locresult=mysql_query($locsql); while($locrow=mysql_fetch_array($locresult)){ ?> <option value="<?=$locrow['Locid']?>"><?=$locrow['Locname']; ?></option><? }?> </select></td><td width="9%" align="center"><input type="submit" name="Display" value="Display"></td></tr> </table></form> <? if(($Catid==0) && ($Locid==0)){ ?> <table width="100%" cellpadding="5" cellspacing="0" border="0" align="center" class="mainbrd"> <tr height="27"> <td width="25%" height="27" background="../images/bar.gif"> <strong>Job Title</strong></td> <td width="20%" background="../images/bar.gif"><strong> Company Name</strong></td> <td width="15%" background="../images/bar.gif"> <strong>Deadline</strong></td> <td width="10%" background="../images/bar.gif"> <strong>Category</strong></td> <td width="20%" background="../images/bar.gif"> <strong>Location</strong></td> </tr> <? /* Place code to connect to your DB here. */ /* Get data. */ $query = "SELECT * FROM tbljob order by Jobid desc"; $portfolio = mysql_query($query); while($item = mysql_fetch_array($portfolio)) { $bgc=($bgc=="#F7F7F7")?"#ffffff" : "#F7F7F7"; if($item['Jobclosedate']<date("Y-m-d")){ }else{ ?> <tr height="30" bgcolor="<?=$bgc?>" onMouseOver="this.bgColor='#F3F3F3';" onMouseOut="this.bgColor='';"><td class="tblline"> <a href="Jobdetail.php?Jobid=<?=$item['Jobid']?>"> <? if(strlen($item['Jobtitle'])>25){ echo substr($item['Jobtitle'],0,25)."..."; }else{ echo $item['Jobtitle'];}?></a></td><td class="tblline"> <?=$item['Jobcompany']?></td><td class="tblline"> <?=date("M d, Y",strtotime($item['Jobclosedate']));?></td><td class="tblline"> <? $Catid=$item['Catid']; $catsql="select * from tbljobcat where Catid='$Catid'"; $catresult=mysql_query($catsql); $catrow=mysql_fetch_array($catresult); echo $catrow['Catname']?></td><td class="tblline"> <? $Locid=$item['Locid']; $locsql="select * from tbljoblocation where Locid='$Locid'"; $locresult=mysql_query($locsql); $locrow=mysql_fetch_array($locresult); echo $locrow['Locname']?></td> </tr> <? } } ?> <tr><td height="1" colspan="6" bgcolor="#0066FF"> </td> </tr> </table> <? }else{ ?> <table width="100%" cellpadding="5" cellspacing="0" border="0" align="center" class="mainbrd"> <tr height="27"> <td width="25%" height="27" background="../images/bar.gif"> <strong>Job Title</strong></td> <td width="20%" background="../images/bar.gif"><strong> Company Name</strong></td> <td width="15%" background="../images/bar.gif"> <strong>Deadline</strong></td> <td width="10%" background="../images/bar.gif"> <strong>Category</strong></td> <td width="20%" background="../images/bar.gif"> <strong>Location</strong></td> </tr> <? /* Place code to connect to your DB here. $query = "SELECT * FROM tbljob where Locid like '%".$Locid."' or Catid like '%".$Catid."'; $portfolio = mysql_query($query); while($item = mysql_fetch_array($portfolio)) { $bgc=($bgc=="#F7F7F7")?"#ffffff" : "#F7F7F7"; if($item['Jobclosedate']<date("Y-m-d")){ }else{ ?> <tr height="30" bgcolor="<?=$bgc?>" onMouseOver="this.bgColor='#F3F3F3';" onMouseOut="this.bgColor='';"><td class="tblline"> <a href="Jobdetail.php?Jobid=<?=$item['Jobid']?>"> <? if(strlen($item['Jobtitle'])>35){ echo substr($item['Jobtitle'],0,35)."..."; }else{ echo $item['Jobtitle'];}?></a></td><td class="tblline"> <?=$item['Jobcompany']?></td><td class="tblline"> <?=date("M d, Y",strtotime($item['Jobclosedate']));?></td><td class="tblline"> <? $Catid=$item['Catid']; $catsql="select * from tbljobcat where Catid='$Catid'"; $catresult=mysql_query($catsql); $catrow=mysql_fetch_array($catresult); echo $catrow['Catname']?></td><td class="tblline"> <? $Locid=$item['Locid']; $locsql="select * from tbljoblocation where Locid='$Locid'"; $locresult=mysql_query($locsql); $locrow=mysql_fetch_array($locresult); echo $locrow['Locname']?></td> </tr> <? } } ?> </td></tr> <tr><td height="1" colspan="6" bgcolor="#0066FF"> </td> </tr> </table> <? }?>// code
Last edited by cscgal; Sep 28th, 2008 at 1:29 am. Reason: Added code tags
•
•
Join Date: Sep 2008
Posts: 6
Reputation:
Solved Threads: 0
•
•
•
•
Hey,
You've posted a huge code segment but not explained what it does or why it does it? Your description is rather vauge and I, for one, don't really want to dig through all that code looking for a problem I don't know about.
Chris
My problem is that I can search only both values like All=location and All category is fine
But I if select Location=Phnom Penh and Category= Computer is not show me the right criteria.
Thank so much in advance for your million help.
Kindly regards,
Bunhok
•
•
Join Date: Sep 2008
Posts: 15
Reputation:
Solved Threads: 1
Hey,
I've spotted a slight problem near the beginning of your script. The section where you loop to show the job categories writes the category ID and the category name into an option field. You have a default field named "All Categories" with the value of 0. However, in MySQL, I believe it may be possible to get an index of 0.. this would produce html like this:
I recommend you make the "All Categories" and "All Locations" values to -1, a number outside the range of what MySQL may return. This will stop any duplication problems. As I mentioned earlier, it's very difficult to read your code, so this next comment may be wildly off.
On line 33, you check to see if "All Categories" and "All Locations" has been selected and you have tailored an entire section querying the database for that, and in the corresponding else statement (Line 97), you've begun to show the HTML table code, but you've commented out everything else to do with the database from line 111 onwards?
I hope this helps,
Christopher Lord
I've spotted a slight problem near the beginning of your script. The section where you loop to show the job categories writes the category ID and the category name into an option field. You have a default field named "All Categories" with the value of 0. However, in MySQL, I believe it may be possible to get an index of 0.. this would produce html like this:
PHP Syntax (Toggle Plain Text)
<option value="0">All Categories</option> <option value="0">Category A</option> <option value="1">Category B</option>
I recommend you make the "All Categories" and "All Locations" values to -1, a number outside the range of what MySQL may return. This will stop any duplication problems. As I mentioned earlier, it's very difficult to read your code, so this next comment may be wildly off.
On line 33, you check to see if "All Categories" and "All Locations" has been selected and you have tailored an entire section querying the database for that, and in the corresponding else statement (Line 97), you've begun to show the HTML table code, but you've commented out everything else to do with the database from line 111 onwards?
I hope this helps,
Christopher Lord
![]() |
Similar Threads
- Help and support and Msconfig won't open, Search disabled (Windows NT / 2000 / XP)
- Redirect/Jump problem (Viruses, Spyware and other Nasties)
- IE Explorer/Search Engine problems! (fake/redirect search results;dysfunctional sites (Viruses, Spyware and other Nasties)
- Linked list search problems (Computer Science)
- Search Assistant problem won't go away (Viruses, Spyware and other Nasties)
- Dell dimension 3000 my way search assistant (Viruses, Spyware and other Nasties)
- Internet Explorer search problem (Windows NT / 2000 / XP)
- kinda clueless new girl - search extender won't go away (Viruses, Spyware and other Nasties)
Other Threads in the PHP Forum
- Previous Thread: Inserting delay in PHP scripts
- Next Thread: PHP progress bar
| Thread Tools | Search this Thread |
# 5.2.10 access alexa apache api array beginner broken cakephp checkbox class clean clients cms code convert cron curl database date directory display dissertation dropdown dynamic echo$_get[x]changingitintovariable... email encode error fairness file folder form forms function functions google hack href htaccess html image include indentedsubcategory ip javascript joomla legislation limit link local login mail memberships menu methods multiple multipletables mysql mysqlquery network newsletters object oop open passwords paypal pdf persist php provider query radio random redirect remote script search secure securephp server sessions simple sockets source space spam sql system table tutorial upload url user variable video voteup web youtube





