943,907 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 498
  • PHP RSS
Sep 28th, 2008
0

I have problem with two value search

Expand Post »
Dear All,

I have problem with two value search, Please kindly see my code below:
php Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Bunhok is offline Offline
6 posts
since Sep 2008
Sep 28th, 2008
0

Re: I have problem with two value search

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
Reputation Points: 10
Solved Threads: 1
Newbie Poster
heenix is offline Offline
15 posts
since Sep 2008
Sep 28th, 2008
0

Re: I have problem with two value search

Click to Expand / Collapse  Quote originally posted by heenix ...
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Bunhok is offline Offline
6 posts
since Sep 2008
Sep 28th, 2008
0

Re: I have problem with two value search

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:

PHP Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 1
Newbie Poster
heenix is offline Offline
15 posts
since Sep 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Inserting delay in PHP scripts
Next Thread in PHP Forum Timeline: Linking username to profile...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC