Having similar records only display once with a mysql database using PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • WiseG1rly
    New Member
    • Jul 2007
    • 5

    Having similar records only display once with a mysql database using PHP

    Hey everyone!

    I am completley new and I will start off by saying that I am not a programmer - figuring out this search took so long! I am debugging now and would appreciate any help :)

    Anyways, I am creating a website where I have a database of pet listings in california. Each record lists the Type of Listing (eg. dog grooming or vet) the the Area it is in (so state, county etc.), a Name, Description, and Address.

    I created a search so there are three pages. The first one has a pulldown menu where the user selects the type of listing they are looking for. Next, they select the area they wish to view, and then the records are all displayed that match those two critera (aka all dog grooming in san fran.)

    Okay so here is my issue: There are about 45 Dog Grooming records, 240 Vets etc. And they ALL show up in the pulldown menus. Same with the areas.

    is there a clause I can add to my code so once dog grooming is listed, it is no longer shown, yet still selects all of the records with dog grooming in it?

    Please tell me if this does not make sense. And here is my code (please don't laugh, I am sure it is very messy! I am a designer :) not a coder ha. THANKS SO MUCH!


    SEARCH.php
    [CODE=php]<?php
    $username="forp et";
    $password="dogr nnr2";
    $database="forp et";

    mysql_connect(l ocalhost,$usern ame,$password);
    @mysql_select_d b($database) or die("Unable to select database");

    ?>

    <form method="POST" action="search2 .php">

    <?php $sql = mysql_query("SE LECT type FROM listings ORDER BY type ASC"); while ($row = mysql_fetch_arr ay($sql)) { ?>

    Type of Listing:
    <select name="type">
    <option name="<?php echo $row['type']; ?>" id="<?php echo $row['type']; ?>"> <?php echo $row['type']; ?> </option> <?php } ?>
    </select>
    <input type="submit" value="Continue Search"><br><br >
    </form>[/CODE]

    SEARCH2.PHP
    [CODE=php]<?php
    $username="forp et";
    $password="dogr nnr2";
    $database="forp et";

    mysql_connect(l ocalhost,$usern ame,$password);
    @mysql_select_d b($database) or die("Unable to select database");

    ?>

    <form method="POST" action="results .php">

    <?php

    $sql = mysql_query("SE LECT * FROM listings WHERE type LIKE '$type'");
    while ($row = mysql_fetch_arr ay($sql)) { ?>

    Type of Listing:
    <select name="type">
    <option name="<?php echo $type; ?>" id="<?php echo $type; ?>"> <?php echo $type; ?> </option> <?php } ?>
    </select>
    <br>
    <br>

    <?php

    $sql = mysql_query("SE LECT * FROM listings WHERE type LIKE '$type'");
    while ($row = mysql_fetch_arr ay($sql)) { ?>

    Area/Location:
    <select name="area">
    <option name="<?php echo $row['area']; ?>" id="<?php echo $row['area']; ?>"> <?php echo $row['area']; ?> </option> <?php } ?>
    </select>
    <input name="" type="submit" value="Display Listings">

    </form>[/CODE]

    RESULTS.PHP
    [CODE=php]<?php
    $username="forp et";
    $password="dogr nnr2";
    $database="forp et";

    mysql_connect(l ocalhost,$usern ame,$password);
    @mysql_select_d b($database) or die("Unable to select database");

    $query="SELECT * FROM listings WHERE area LIKE '$area' AND type LIKE '$type'";
    $result=mysql_q uery($query);

    $num=mysql_numr ows($result);

    mysql_close();

    echo "<b><center>Res ults for $type in $area</center></b><br><br>";

    $i=0;
    while ($i < $num) {

    $type=mysql_res ult($result,$i, "type");
    $area=mysql_res ult($result,$i, "area");
    $name=mysql_res ult($result,$i, "name");
    $content=mysql_ result($result, $i,"content");
    $address=mysql_ result($result, $i,"address");

    echo "<b>$name</b><br>$content< br>$address<br> <hr><br>";

    $i++;

    }

    ?>[/CODE]

    THANK YOU SO MUCH!
    -Stephanie

    Originally posted by Ajaxrand

    For php, CODE tags should be like this.
    [code=php]
    Not Just
    [code]

    Anyway thanks for using [CODE] Tags.
  • WiseG1rly
    New Member
    • Jul 2007
    • 5

    #2
    okay i figured this out - all i needed was a DISTINCT clause. :)

    Comment

    • ak1dnar
      Recognized Expert Top Contributor
      • Jan 2007
      • 1584

      #3
      Originally posted by WiseG1rly
      okay i figured this out - all i needed was a DISTINCT clause. :)
      Hi Stephanie,
      Glad to hear that you've figured it out your self.Welcome to TSDN anytime.

      Comment

      • banning
        New Member
        • Aug 2007
        • 42

        #4
        Originally posted by WiseG1rly
        okay i figured this out - all i needed was a DISTINCT clause. :)

        LOL that makes me so mad, i hate it when its a stupid easy answer to stuff like this haha... i had the exact same problem and i was just thinking about how retarded it was that the solution has to be simple.

        its a good thing i ran across your question on here i hate having to word my problems out for people on message boards n stuff lol

        thanks :P

        Comment

        Working...