#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    11
    Rep Power
    0
    I have created a script to search for data by state. It works - but will only bring up one listing. How do I make this search loop so I will get all results of search instead of just the first one?

    This is what I have at present:
    <?php
    include("required.php3");

    $connection = mysql_connect($ip, $user, $password) or die ("Couldn't
    connect to server.");

    $db = mysql_select_db($dataname, $connection) or die ("Couldn't select
    database.");

    if ($state == "")
    {$state = '%';}

    $result = mysql_query ("SELECT name, address, city, state, zip, email, phone, url, parktype, rec, open
    FROM park
    WHERE state LIKE '$state%'");

    if ($row = mysql_fetch_array($result)) {

    echo "<table WIDTH=400 align=center>n";
    // format results by row


    $name = $row["name"];
    $address = $row["address"];
    $city = $row["city"];
    $state = $row["state"];
    $zip = $row["zip"];
    $email = $row["email"];
    $phone = $row["phone"];
    $url = $row["url"];
    $parktype = $row["parktype"];
    $rec = $row["rec"];
    $open = $row["open"];
    echo "<CENTER><TR><TD ALIGN=CENTER WIDTH=400><B><a href="$url">$name</a></B></TD></TR><TR><TD ALIGN=CENTER WIDTH=400>$address, $city $state $zip</TD></TR><TR><TD ALIGN=CENTER WIDTH=400>To send this park E-Mail <a href=mailto:"$email">click here</A></TD></TR><TR><TD ALIGN=CENTER WIDTH=400>$phone</TD></TR><TR><TD ALIGN=CENTER WIDTH=400>$parktype</TD></TR><TR><TD><B>Recreation Opportunities Available</B></TD></TR><TR><TD ALIGN=CENTER WIDTH=400>$rec</TD></TR><TR><TD><B>Park Description</B></TD></TR><TR><TD ALIGN=CENTER WIDTH=400 BORDER=1>$open<HR></TD></TR>";
    }
    echo "<HR></TABLE><HR>";


    ?>


    ------------------
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    18
    Just replace the if with while.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    11
    Rep Power
    0
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by rod k:
    Just replace the if with while.[/quote]
    My Hero!
    I knew I was close - but that makes all the difference )

    Mary

  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    11
    Rep Power
    0
    The change to 'while' works just fine with IE, but when I tried in wth Netscape Navigator I only got one result from my search.
    Now what?
    Please help!


    ------------------
  8. #5
  9. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    <<
    if ($row = mysql_fetch_array($result)) {

    echo "<table WIDTH=400 align=center>n";
    // format results by row
    >>


    print the "table" tag before your while loop.


    try this...


    echo "<table width="400" align="center">n";
    // format results by row
    while($row = mysql_fetch_array($result)) {

    $name = $row["name"];
    $address = $row["address"];
    $city = $row["city"];
    $state = $row["state"];
    $zip = $row["zip"];
    $email = $row["email"];
    $phone = $row["phone"];
    $url = $row["url"];
    $parktype = $row["parktype"];
    $rec = $row["rec"];
    $open = $row["open"];

    echo "<CENTER><TR><TD ALIGN=CENTER WIDTH="400"><B>n";
    echo "<a href="$url">$name</a></B></TD></TR>n";

    echo "<TR><TD ALIGN="CENTER" WIDTH="400">$address, $city $state $zip</TD></TR>n";
    echo "<TR><TD ALIGN="CENTER" WIDTH="400">To send this park E-Mail <a href=mailto:"$email">click here</A></TD></TR>n";
    echo "<TR><TD ALIGN="CENTER" WIDTH="400">$phone</TD></TR>n";
    echo "<TR><TD ALIGN="CENTER" WIDTH="400">$parktype</TD></TR>n";
    echo "<TR><TD><B>Recreation Opportunities Available</B></TD></TR>n";
    echo "<TR><TD ALIGN="CENTER" WIDTH="400">$rec</TD></TR>n";
    echo "<TR><TD><B>Park Description</B></TD></TR>n";
    echo "<TR><TD ALIGN="CENTER" WIDTH="400" BORDER="1">$open<HR></TD></TR>n";
    }
    echo "</TABLE><HR>n";
    ?>




    ------------------
    SR -
    webshiju.com
    www.jobxyz.com-IT Career Portal
    ezipindia.com--WebStudio


    "The fear of the LORD is the beginning of knowledge..."
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Seattle, WA USA
    Posts
    23
    Rep Power
    0
    I've made this simular error... EI will correct your typos for you, Netscape will not.

    Check out this site: http://watson.addy.com/

    It will check your html code for errors! Site for finding EI/Netscape error, along with upload times etc.


    Carl Sweetland
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    11
    Rep Power
    0
    OK - the form now works perfectly in IE - but it still won't accept apostraphies and commas (pardon spelling please) in Netscape.
    What am I missing?

    <?php


    $q1 = "INSERT INTO park (ID, name, address, city, state, zip, email, phone, url, parktype, REC, open) VALUES('$ID', ('$name'), ('$address'), ('$city'), '$state', '$zip', '$email', ('$phone'), '$url', '$parktype', ('$REC'), ('$open'))";

    Thanks a bunch!

    [This message has been edited by camparoo (edited September 02, 2000).]
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    11
    Rep Power
    0
    I checked at: http://watson.addy.com/
    but it did not find the PHP3 error (
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Pune, Maharashtra, India
    Posts
    86
    Rep Power
    14
    Use the striplashes function with the variables before adding into the database.


    ------------------
    Nikunj
    MYSQL/PHP/XML
    ** Expertise comes with experiece ** Nikunj
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    14
    The correct format for your query should look like this: And if single quotes are producing errors ie everything after the single quote is truncated from the string upon entry to the db, its addslashes() not stripslashes() that you are after


    $q1 = "INSERT INTO park (ID, name, address, city, state, zip, email, phone, url, parktype, REC, open) VALUES('$ID', '$name', '$address', '$city', '$state', '$zip', '$email', '$phone', '$url', '$parktype', '$REC', '$open')";

Similar Threads

  1. Frames hijacked after remote search
    By Telejoke in forum Antivirus Protection
    Replies: 2
    Last Post: September 26th, 2007, 09:32 AM
  2. Problem with search script
    By riotx in forum PHP Development
    Replies: 4
    Last Post: February 2nd, 2004, 08:16 AM
  3. Replies: 0
    Last Post: January 27th, 2004, 10:11 AM
  4. Cgi Search feature script
    By butsy_7 in forum Perl Programming
    Replies: 5
    Last Post: January 22nd, 2004, 07:43 PM
  5. How can I enable a power user to run this script?
    By Yamadatroy in forum Visual Basic Programming
    Replies: 2
    Last Post: January 19th, 2004, 09:39 PM

IMN logo majestic logo threadwatch logo seochat tools logo