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

    Join Date
    Jun 2000
    Posts
    2
    Rep Power
    0
    I am a total newbie and I am having problems retrieving multiple rows from a database...

    when I try to get a printout of the whole table, I get the following error:

    Warning: 0 is not a MySQL result index in C:HTTPDHTDOCStest.php3
    My code is as follows:

    <?php
    $db = mysql_connect("localhost", "root");
    mysql_select_db("test",$db);
    if ($myrow = mysql_fetch_array($result)) {
    echo "<table border=1>n";
    echo "<tr><td>Name</td><td>Position</td></tr>n";
    do {
    printf("<tr><td>%s %s</td><td>%s</tr>n", $myrow["first"], $myrow["last"], $myrow["address"]);
    } while ($myrow = mysql_fetch_array($result));
    echo "</table>n";
    } else {
    echo "Sorry, no records were found!";
    }
    ?>

    Any help would be appreciated.

    Thanks...
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    63
    Rep Power
    15
    You need to run a query againsts the database before you try to get any records.

    $db = mysql_connect("localhost", "root");
    mysql_select_db("test",$db);
    $sql = "select * from customers" // selects all fields all rows from the customer table
    $result = mssql_query($sql, $db);

    if ($result)
    {
    // now you have a result so you can get the data using mssql_fetch_array or mssql_result
    }

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

    Join Date
    Jun 2000
    Posts
    2
    Rep Power
    0
    doh..... I must have accidentally deleted that line initially. Thank you!

Similar Threads

  1. Need advice designing a usage tracking database (MySQL)
    By Randolpho in forum Database Management
    Replies: 0
    Last Post: February 13th, 2004, 05:11 PM
  2. Replies: 3
    Last Post: February 11th, 2004, 09:30 AM
  3. Replies: 14
    Last Post: February 8th, 2004, 02:28 PM
  4. MYSQL database
    By isheikh in forum MySQL Help
    Replies: 3
    Last Post: January 14th, 2004, 11:58 PM
  5. Writing Japanese unicode text to a mysql database
    By jayhay in forum PHP Development
    Replies: 3
    Last Post: January 13th, 2004, 09:10 AM

IMN logo majestic logo threadwatch logo seochat tools logo