Thread: php amateur...

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    Syd or UK
    Posts
    21
    Rep Power
    0

    php amateur...


    Guys, help us out here please...
    -----------------------------------
    the script...
    -----------------------------------
    <html>
    <body>
    <?php
    require("mydb.inc");

    mysql_connect("***.**.***.**",$user,$password);

    $database="ellel";
    @mysql_select_db("$database") or die( "Unable to select database");

    $sql = "SELECT company_name,link_ref,region FROM advertisers WHERE region='";


    //switch loop
    switch ($select){

    //scotland search
    case 1:
    $sql .= "Scotland'";
    break;

    //north england search
    case 2:
    $sql .= "North England'";
    break;

    //central england search
    case 3:
    $sql .= "Central England'";
    break;

    //wales search
    case 4:
    $sql .= "Wales'";
    break;

    //south east england search
    case 5:
    $sql .= "South East England'";
    break;

    //south west england search
    case 6:
    $sql .= "South West England'";
    break;

    //channel islands search
    case 7:
    $sql .= "Channel Islands'";
    break;

    //northern ireland search
    case 8:
    $sql .= "North Ireland'";
    break;

    //ireland search
    case 9:
    $sql .= "Ireland'";
    break;

    //overseas search
    case 10:
    $sql .= "Overseas'";
    break;

    //all search
    //case 11
    //$sql .= "%'";
    //break;
    }


    $query=mysql_query($sql);

    $rslt=mysql_fetch_array($query);

    //display results

    echo "<table>\n<tr>\n";
    echo "<td>Company Name</td>\n";
    echo "<td>URL</td>\n";
    echo "<td>Region</td>\n";
    echo "</tr>\n";

    while ($row = mysql_fetch_array($query)) { // or list($all, $the, $retrieved, $columns)
    echo "<tr>\n";
    echo "<td>$row[company_name]</td>\n";
    echo "<td>$row[link_ref]</td>\n";
    echo "<td>$row[region]</td>\n";
    echo "</tr>\n";
    }
    echo "</table>\n";


    ?>
    </body>
    </html>
    -----------------------------------
    returns...
    -----------------------------------
    Warning: Supplied argument is not a valid MySQL result resource in /home/christianh/public_html/out3.php on line 76

    Warning: Supplied argument is not a valid MySQL result resource in /home/christianh/public_html/out3.php on line 86

    Company Name URL Region

    -----------------------------------
    HELP?? i cant pick anything wrong with this current syntax...
    much appreciated
    JD
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Posts
    266
    Rep Power
    14
    Keep in mind I am fairly new to php as well. But I will give it a shot.

    The first thing is it is not your php but your MYSQL queries which are failing.

    $sql = "SELECT company_name,link_ref,region FROM advertisers WHERE region='";

    There are no () around your query plus in the section "WHERE region = '"; it looks like you only have one ' instead of ' '

    $sql = ("SELECT company_name,link_ref,region FROM advertisers WHERE region=''";

    I hope that helps

    E.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Posts
    1
    Rep Power
    0
    I'm new to php also, but i think this will work:

    echo "<td>" . $row["company_name"] . "</td>\n";
    echo "<td>" . $row["link_ref"] . "</td>\n";
    echo "<td>" . $row["region"] . "</td>\n";


    I hope this helps.
    Last edited by undodigital; June 2nd, 2001 at 01:23 PM.
  6. #4
  7. No Profile Picture
    ,-)
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Location
    Germany
    Posts
    13
    Rep Power
    0
    theeggman should be right - almost...

    don't need brackets around your query, but supplied argument is missing (or misspeled), thats the key.

    try:

    //switch loop
    switch ($select){

    //scotland search
    case 1:
    $selection="Scotland";
    break;

    and so on...

    $sql = "SELECT company_name,link_ref,region FROM advertisers WHERE region='$selection'";

    should be easier with the variable rather than adding something to the querystring



    bombel

    problem solved already?

    just post a "worked" or something so no one bothers with your questions anymore
    Last edited by bombel; June 10th, 2001 at 03:43 PM.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    Syd or UK
    Posts
    21
    Rep Power
    0
    working, thanx all

IMN logo majestic logo threadwatch logo seochat tools logo