Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7986475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:51:51+00:00 2026-06-04T11:51:51+00:00

Here is the updated code. classifieds table id | title | description | state_id

  • 0

Here is the updated code.

classifieds table

id | title | description | state_id | city_id |

1 Ford | ford for sell| 1 | 1

2 Ford | ford explorer| 2 | 1

state table

id | name |

1 Texas
2 Arizona

city table


id | name | state_id

1 Arlington 1
2 Globe 2

The code that does the search and prints the results is all here:

So this file called search.php

enter  <?php
   $conn = mysql_connect('localhost', 'root','');
  $db = mysql_select_db('files',$conn);
  $input = $_GET['query'];
  $state = $_POST['state'];
 $city = $_POST['city'];
 if (isset($input) && $input != "" ) {
 $select = "SELECT * FROM classifieds";
 $where = " WHERE (title like '%" . $input . "%'  OR description like '%" . $input .   

 "%')";
if (!empty($city)) {
$select .= " LEFT JOIN city ON classifieds.city_id=city.id";
$where .= " AND city.name = '" . $city . "'";
}
if (!empty($state)) {        
$select .= " LEFT JOIN state ON classifieds.state_id=state.id";
$where .= " AND state.name = '" . $state . "'";
}    
$q = $select . $where . ' ORDER BY date DESC';
$r = mysql_query($q);
$rows = mysql_num_rows($r);
}
echo $rows; ?> Search Results For: <?PHP echo $input; 
if ($rows > 0) {
while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) {
$description = $row['description'];
echo "  <tr  >
<td ><a href='classified-" . $row['adid'] . ".htm' >" . $row['title'] . "</a><br />
 <span><em><a href='category-" . $cat . ".php'>" . $catname . "</a></em><br/>" .    
$description . "...</span></td>
 </tr>
  ";
  }
   }
  ?>
   <form action="search.php" method="get">
   <input type="text" name="query" />
  <input type="submit" name="Submit" value="Search" />
   <select name="state" >
<option value="null"></option>
<?php
//POPULATE DROP DOWN MENU WITH STATES FROM A GIVEN REGION, COUNTRY
$sql = "SELECT id, statename FROM state";
$states = mysql_query($sql,$conn);
while($row = mysql_fetch_array($states))
{
    echo ("<option value=".$row[id]." >$row[statename]</option>");
}
?>
</select>
<select name="city" >
<option value="null"></option>
<?php
$sql = "SELECT id, city FROM city  ";
$cities = mysql_query($sql,$conn);
while($row = mysql_fetch_array($cities))
{
    echo ("<option value=".$row[id].">$row[city]</option>");
}
?>  here
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:51:53+00:00Added an answer on June 4, 2026 at 11:51 am

    You basically need to check if state and/or city are set (by the way, you have GET set as a method in form, yet you check $_POST for city and state – is that correct?) and add them to sql query accordingly:

    $select = "SELECT * FROM classifieds";
    $where = " WHERE (title like '%" . $input . "%'  OR description like '%" . $input . "%')";
    
    if (!empty($city)) {
        $select .= " LEFT JOIN city ON classifieds.city_id=city.id";
        $where .= " AND city.name = '" . $city . "'";
    }
    
    if (!empty($state)) {        
        $select .= " LEFT JOIN state ON classifieds.state_id=state.id";
        $where .= " AND state.name = '" . $state . "'";
    }    
    
    $q = $select . $where . ' ORDER BY date DESC';
    

    Note the parentheses for title and description – without them OR would take precendence over AND.

    As a sidenote, you don’t need to query database twice for the same data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've updated my code here. I've put the range inside the unavailableDays function which
Here is source code: @OneToOne(fetch = FetchType.LAZY) @Cascade({SAVE_UPDATE, EVICT, DELETE}) @JoinColumn(name = A_ID, nullable
EDIT: Here is my updated code: #!/bin/sh files=`ls` if [ $# -ne 1 -o
UPDATED CODE: Now, I have this code: <h2>Testing</h2> <input type=checkbox name=fruit1 id=id1 class=box>Banana<br /><br
Here is the updated code: private function myFillFunction(element:ChartItem, index:Number, item:Object, fieldName:String):IFill { var c:SolidColor
Here's my updated code trying to get my form to send me the email.
Here is my upsert code: UPDATE LastTicket SET LastTicketNumber=LastTicketNumber+1 OUTPUT INSERTED.LastTicketNumber WHERE CategoryId='1'; IF
Here is my chunk of code: var update_shipping_methods = function(methods) { $(methods).each( function(i) {
UPDATE: Based on suggestions here, I've modified my code. To get a handle on
I'm trying to update an element in the XML document below: Here's the code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.