Some PHP help please

Hello,

I am having trouble with a “refine search” feature that I have on a website.

I was able to accomplish it here: http://www.saddlesblazin.com/find-store.php

But for some reason, on this new website, when I tried to switch the criteria from STATES to CITIES, I am not having much luck. This example is here: http://www.alexialozano.com/amaregal/find-store.php

I was hoping someone could look at the source code and help me out.

Thanks.

Need the code to help. Guessing the city, state, and state abbreviation is stored in a database separately?

The city_id and state_id, along with name, phone number, address…etc are in one table in the database and the cities listed with names and ids are in another.

Here is the code for the search-results.php:

[php]

Select City <?php $result = @mysql_query("SELECT * FROM bk_city"); while ($city=mysql_fetch_array($result)){ ?> selected <?php } ?> ><?php echo $city['name']; ?> <?php } ?>
      <input type="submit" value="Go" id="locSearch" />
  </form>
<?php if($_GET['criteria']=='city'){ $sql_get_store = "SELECT * FROM bk_stores WHERE city_id = '$_GET[city]' ORDER BY `bk_stores`.`city` ASC"; $result_get_store = @mysql_query($sql_get_store); }elseif($_GET['address']=='' && $_GET['city']!=='' && $_GET['zip']=='' && $_GET['state']=''){ $sql_get_store = "SELECT * FROM bk_stores WHERE city_id = '$_GET[city]' ORDER BY `bk_stores`.`city` ASC"; $result_get_store = @mysql_query($sql_get_store); }else{ $sql_get_store = "SELECT * FROM bk_stores WHERE ( address LIKE '%$_GET[address]' AND zip LIKE '%$_GET[zip]' AND city LIKE '%$_GET[city]' ) ORDER BY `bk_stores`.`city` ASC"; $result_get_store = @mysql_query($sql_get_store); } ?> <?php if(mysql_num_rows($result_get_store)==0 && $_REQUEST['state']=='5'){ ?>
Tommy Carter for management opportunities!.
<? }elseif(mysql_num_rows($result_get_store)==0){ ?>
No match found.
<?php }else{ while($row_get_store=mysql_fetch_array($result_get_store)){ ?>

<?php echo $row_get_store['store'];?>

<?php echo $row_get_store['city'];?>

<?php echo $row_get_store['address']; ?>

<?php echo $row_get_store['city']; ?>, <?php if($row_get_store['city_id']==1){ echo 'TX'; }elseif($row_get_store['city_id']==2){ echo 'TX'; }elseif($row_get_store['city_id']==3){ echo 'Test'; } ?>  <?php echo $row_get_store['zip']; ?>

<?php echo $row_get_store['phone'];?>
<?php } } ?> [/php]
  1. You need to update away from mysql_ functions.
  2. You should not be suppressing errors and warnings in development.
  3. You have a logic error here:
    [php] }elseif($_GET[‘address’]==’’ && $_GET[‘city’]!==’’ && $_GET[‘zip’]==’’ && $_GET[‘state’]=’’){[/php]

Thank you for your help and your reply.

What should I use in place of mysql_functions?

My preference is PDO, but mysqli is an alternative.

Do I need to install PDO drivers before I can edit the PHP and have it work correctly?

If your php versions is even remotely recent, it cows with them.

Thank you again for all of your help. I was able to get it to work!

Have a good day!

Sponsor our Newsletter | Privacy Policy | Terms of Service