I have problem with two value search

Reply

Join Date: Sep 2008
Posts: 6
Reputation: Bunhok is an unknown quantity at this point 
Solved Threads: 0
Bunhok Bunhok is offline Offline
Newbie Poster

I have problem with two value search

 
0
  #1
Sep 28th, 2008
Dear All,

I have problem with two value search, Please kindly see my code below:
  1. <? require("../Dbconnect/db_connect.php");?>
  2.  
  3.  
  4.  
  5. <form action="./" method="get"> <table width="100%" cellpadding="0" cellspacing="0" border="0" align="center">
  6. <tr><td width="91%" align="right">
  7. <select name="Catid">
  8. <option value="0" selected>All Categories</option>
  9. <?
  10.  
  11. $cats="select * from tbljobcat order by Catname asc";
  12. $catre=mysql_query($cats);
  13. while($catr=mysql_fetch_array($catre)){
  14. ?>
  15. <option value="<?=$catr['Catid']?>"><?=$catr['Catname']; ?></option><? }?>
  16. </select>&nbsp;
  17.  
  18. <select name="Locid">
  19. <option value="0" selected>All Locations</option>
  20. <?
  21.  
  22. $locsql="select * from tbljoblocation order by Locname asc";
  23. $locresult=mysql_query($locsql);
  24. while($locrow=mysql_fetch_array($locresult)){
  25. ?>
  26. <option value="<?=$locrow['Locid']?>"><?=$locrow['Locname']; ?></option><? }?>
  27. </select></td><td width="9%" align="center"><input type="submit" name="Display" value="Display"></td></tr>
  28.  
  29. </table></form>
  30.  
  31. <?
  32.  
  33. if(($Catid==0) && ($Locid==0)){
  34. ?>
  35.  
  36. <table width="100%" cellpadding="5" cellspacing="0" border="0" align="center" class="mainbrd">
  37.  
  38. <tr height="27">
  39. <td width="25%" height="27" background="../images/bar.gif">&nbsp;&nbsp;<strong>Job Title</strong></td>
  40. <td width="20%" background="../images/bar.gif"><strong>&nbsp;&nbsp;Company Name</strong></td>
  41. <td width="15%" background="../images/bar.gif">&nbsp;&nbsp;<strong>Deadline</strong></td>
  42. <td width="10%" background="../images/bar.gif">&nbsp;&nbsp;<strong>Category</strong></td>
  43. <td width="20%" background="../images/bar.gif">&nbsp;&nbsp;<strong>Location</strong></td>
  44. </tr>
  45.  
  46.  
  47.  
  48. <? /*
  49. Place code to connect to your DB here.
  50. */
  51.  
  52.  
  53.  
  54. /* Get data. */
  55. $query = "SELECT * FROM tbljob order by Jobid desc";
  56. $portfolio = mysql_query($query);
  57.  
  58.  
  59.  
  60. while($item = mysql_fetch_array($portfolio))
  61. {
  62. $bgc=($bgc=="#F7F7F7")?"#ffffff" : "#F7F7F7";
  63.  
  64. if($item['Jobclosedate']<date("Y-m-d")){
  65.  
  66. }else{
  67. ?>
  68.  
  69.  
  70. <tr height="30" bgcolor="<?=$bgc?>" onMouseOver="this.bgColor='#F3F3F3';" onMouseOut="this.bgColor='';"><td class="tblline">
  71. &nbsp;&nbsp;<a href="Jobdetail.php?Jobid=<?=$item['Jobid']?>">
  72. <?
  73. if(strlen($item['Jobtitle'])>25){ echo substr($item['Jobtitle'],0,25)."..."; }else{ echo $item['Jobtitle'];}?></a></td><td class="tblline">&nbsp;&nbsp;
  74. <?=$item['Jobcompany']?></td><td class="tblline">&nbsp;&nbsp;<?=date("M d, Y",strtotime($item['Jobclosedate']));?></td><td class="tblline">&nbsp;&nbsp;<?
  75. $Catid=$item['Catid'];
  76. $catsql="select * from tbljobcat where Catid='$Catid'";
  77. $catresult=mysql_query($catsql);
  78. $catrow=mysql_fetch_array($catresult);
  79. echo $catrow['Catname']?></td><td class="tblline">&nbsp;&nbsp;<?
  80. $Locid=$item['Locid'];
  81. $locsql="select * from tbljoblocation where Locid='$Locid'";
  82. $locresult=mysql_query($locsql);
  83. $locrow=mysql_fetch_array($locresult);
  84. echo $locrow['Locname']?></td>
  85. </tr>
  86.  
  87. <? }
  88. }
  89. ?>
  90.  
  91.  
  92. <tr><td height="1" colspan="6" bgcolor="#0066FF">&nbsp;
  93.  
  94. </td>
  95. </tr>
  96. </table>
  97. <? }else{
  98. ?>
  99. <table width="100%" cellpadding="5" cellspacing="0" border="0" align="center" class="mainbrd">
  100.  
  101. <tr height="27">
  102. <td width="25%" height="27" background="../images/bar.gif">&nbsp;&nbsp;<strong>Job Title</strong></td>
  103. <td width="20%" background="../images/bar.gif"><strong>&nbsp;&nbsp;Company Name</strong></td>
  104. <td width="15%" background="../images/bar.gif">&nbsp;&nbsp;<strong>Deadline</strong></td>
  105. <td width="10%" background="../images/bar.gif">&nbsp;&nbsp;<strong>Category</strong></td>
  106. <td width="20%" background="../images/bar.gif">&nbsp;&nbsp;<strong>Location</strong></td>
  107. </tr>
  108.  
  109.  
  110.  
  111. <? /*
  112. Place code to connect to your DB here.
  113.  
  114. $query = "SELECT * FROM tbljob where Locid like '%".$Locid."' or Catid like '%".$Catid."';
  115. $portfolio = mysql_query($query);
  116.  
  117. while($item = mysql_fetch_array($portfolio))
  118. {
  119. $bgc=($bgc=="#F7F7F7")?"#ffffff" : "#F7F7F7";
  120.  
  121. if($item['Jobclosedate']<date("Y-m-d")){
  122.  
  123. }else{
  124. ?>
  125.  
  126.  
  127.   <tr height="30" bgcolor="<?=$bgc?>" onMouseOver="this.bgColor='#F3F3F3';" onMouseOut="this.bgColor='';"><td class="tblline">
  128.   &nbsp;&nbsp;<a href="Jobdetail.php?Jobid=<?=$item['Jobid']?>">
  129.   <?
  130. if(strlen($item['Jobtitle'])>35){ echo substr($item['Jobtitle'],0,35)."..."; }else{ echo $item['Jobtitle'];}?></a></td><td class="tblline">&nbsp;&nbsp;
  131.   <?=$item['Jobcompany']?></td><td class="tblline">&nbsp;&nbsp;<?=date("M d, Y",strtotime($item['Jobclosedate']));?></td><td class="tblline">&nbsp;&nbsp;<?
  132. $Catid=$item['Catid'];
  133. $catsql="select * from tbljobcat where Catid='$Catid'";
  134. $catresult=mysql_query($catsql);
  135. $catrow=mysql_fetch_array($catresult);
  136. echo $catrow['Catname']?></td><td class="tblline">&nbsp;&nbsp;<?
  137. $Locid=$item['Locid'];
  138. $locsql="select * from tbljoblocation where Locid='$Locid'";
  139. $locresult=mysql_query($locsql);
  140. $locrow=mysql_fetch_array($locresult);
  141. echo $locrow['Locname']?></td>
  142.   </tr>
  143.  
  144.   <? }
  145. }
  146. ?>
  147.  
  148.  
  149.   </td></tr>
  150.  
  151.   <tr><td height="1" colspan="6" bgcolor="#0066FF">&nbsp;
  152.  
  153.   </td>
  154.   </tr>
  155.   </table>
  156.  
  157.   <? }?>// code
  158.  
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.
Last edited by cscgal; Sep 28th, 2008 at 1:29 am. Reason: Added code tags
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 15
Reputation: heenix is an unknown quantity at this point 
Solved Threads: 1
heenix heenix is offline Offline
Newbie Poster

Re: I have problem with two value search

 
0
  #2
Sep 28th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 6
Reputation: Bunhok is an unknown quantity at this point 
Solved Threads: 0
Bunhok Bunhok is offline Offline
Newbie Poster

Re: I have problem with two value search

 
0
  #3
Sep 28th, 2008
Originally Posted by heenix View Post
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
Thanks so much for Mr. Heenix for commenting my post.

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
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 15
Reputation: heenix is an unknown quantity at this point 
Solved Threads: 1
heenix heenix is offline Offline
Newbie Poster

Re: I have problem with two value search

 
0
  #4
Sep 28th, 2008
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:

  1. <option value="0">All Categories</option>
  2. <option value="0">Category A</option>
  3. <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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC