Need to create site from a business listings mysql database

Discussion in 'MySQL' started by wavefront, Sep 24, 2007.

  1. #1
    Hey guys,

    How complicated is it to do this? I have a business listings database in mysql format, and I want to make a site from it. It's weight loss clinics, and I want the homepage to have a list of states, then if you click on a state it shows all clinics there, etc...

    How can I make a php script to do this? Any resources that would help me do so? My developer is bogged down with my other projects and I want to do this fast so let me know, thanks!!!!
     
    wavefront, Sep 24, 2007 IP
  2. SoftCloud

    SoftCloud Well-Known Member

    Messages:
    1,060
    Likes Received:
    28
    Best Answers:
    2
    Trophy Points:
    120
    #2
    Well if there is a column in the database called states then there will be a lot of work. But basically you just merge a $_GET[] string with a mysql_query, to show each states entries.

    Learn a bit how to do it by going here: http://www.tizag.com/mysqlTutorial/mysqlwhere.php
     
    SoftCloud, Sep 24, 2007 IP
  3. livingearth

    livingearth Well-Known Member

    Messages:
    1,469
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    140
    #3
    Just pass your state and city variables to something like this...

    <?php
    $db = mysql_connect("localhost", "youruser", "yourpass");
    mysql_select_db("YourDBName",$db);
    $result17 = mysql_query("SELECT * FROM YourTableName WHERE City = '$city' AND State = '$state' ");
    $num_rows = mysql_num_rows($result17);
    while ($row = mysql_fetch_array($result17)) {
    $field1 = $row["Id"];
    $field2 = $row["Keywords1"];
    $field3 = $row["Keywords2"];
    $field4 = $row["Name"];
    $field5 = $row["Address"];
    $field6 = $row["City"];
    $field7 = $row["State"];
    $field8 = $row["Zip"];
    $field9 = $row["Telephone"];
    $field10 = $row["Fax"];
    $field11 = $row["Description"];
    $field12 = $row["Contact"];
    $field13 = $row["Web"];
    $field14 = $row["Email"];
    echo "<tr><td><font face=tahoma color=black size=1><b>$field4</b></td><td align=right><font face=tahoma color=#0000aa size=1><i>$field2</i></td></tr><tr><td><font face=tahoma color=black size=1> $field5  $field6, $field7  $field8</td><td align=right><font face=tahoma color=black size=1><b> $field9 </b></td></tr>\n";
    }
    mysql_close();
    ?>
    
    Code (markup):
    Of course you will need to edit your username, password and field names etc...
     
    livingearth, Sep 24, 2007 IP
  4. wavefront

    wavefront Well-Known Member

    Messages:
    328
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #4
    Hello, LivingEarth - thanks for the script. When you say I need to pass my city and state variables to that script, what does that require that I do? I don't even know this, sorry. :)
     
    wavefront, Sep 24, 2007 IP
  5. livingearth

    livingearth Well-Known Member

    Messages:
    1,469
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    140
    #5
    Save script in wordpad. Name it "clinics.php" or whatever works for you.
    Pass the variables in url links directly to its url for example...

    yoursite.com/clinics.php?city=Boston&state=MA

    Of course you need to set up your database on your server and edit the script to match it and the fields in your database..
     
    livingearth, Sep 24, 2007 IP
  6. wavefront

    wavefront Well-Known Member

    Messages:
    328
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #6
    ohhhh thanks i didn't know I could call data in the URL instead of making a script for EACH query. :)
     
    wavefront, Sep 30, 2007 IP