#1
  1. No Profile Picture
    quickdesign
    Guest
    Devshed Newbie (0 - 499 posts)
    I got this error message:
    "Warning: 0 is not a MySQL result index"

    I use the following code:

    $connection = mysql_connect("localhost", "username", "password");
    mysql_select_db("qdesign", $connection);


    $query = "SELECT * FROM guestbook WHERE id=$display ";
    $result = mysql_query($query, $connection);


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

    print("<b>n");
    print($row["subject"] . "<br>n");
    print("</b>n");
    print($row["name"] . "<br>n");
    print($row["email"] . "<br>n");
    print($row["url"] . "<br><br>n");
    print("<table border=0><tr><td width=300>nn");
    print($row["msg"] . "<br><br><br>n");
    print("</td></tr></table>nn");
    print("<a href="guestbook.php3?what=view">Go back to the guestbook</a>");

    }


    what's wrong...

    When I enter the page I have a query with me.
    Like this

    www.server.com/page.php3?display=1

    I want to view the same id in the database
    as in the display variable.

    Thanks.
  2. #2
  3. No Profile Picture
    rod k
    Guest
    Devshed Newbie (0 - 499 posts)
    After your query add the following line:

    print mysql_error();

    to see what's wrong. The 0 result index means that mysql returned an error.

    It's not readily apparent from your code what the error might be.
  4. #3
  5. No Profile Picture
    moderator
    Guest
    Devshed Newbie (0 - 499 posts)
    test . . .please ignore
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 1999
    Location
    Rochester, NY, United States
    Posts
    9
    Rep Power
    0
    you query is flawed

    $query = "SELECT * FROM myTable WHERE myField = 'ThisItem'";
    ThisItem must be enclosed in quotes...

    - Regards
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 1999
    Posts
    2
    Rep Power
    0
    The query is not flawed if id is a column which uses a numeric data type (*int, which is probably what it is). Only strings must be enclosed in quotes.
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Location
    NY, NY,USA
    Posts
    18
    Rep Power
    0
    I'm having trouble with these lines:
    $dept_name = mysql_query ("SELECT department_name FROM dept_info WHERE dept_id = '$row["dept_id"]'");
    print $dept_name;

    It seems to be printing the array index, and not a result from the mysql_query. The Query works if I type it in the command line with an explicit value substituted for the $row["dept_id"]

    This line :
    print $row["dept_id"];
    is printing the correct value to HTML.

    Here's the code:

    $result = mysql_query ("SELECT * FROM jobs");

    print ("<table>");
    if ($row = mysql_fetch_array($result)) {
    do {
    print ("<tr><td bgcolor=#cccccc>");
    print $row["position_name"];
    print ("</td><td>");
    print ("<b>");
    print $row["dept_id"];
    print ("</b>");
    $dept_name = mysql_query ("SELECT department_name FROM dept_info WHERE dept_id = '$row["dept_id"]'");
    print $dept_name;
    print ("</td></tr>"); }
    while($row = mysql_fetch_array($result)); }
    else {print "Sorry, no records were found!";}

    print ("</table>");



    [This message has been edited by brett_webb (edited February 02, 2000).]
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 1999
    Location
    Netherlands
    Posts
    77
    Rep Power
    15
    Hi,

    There are 'conflicting' double-quotes in the string, you can try:

    $selectquery = "SELECT department_name FROM dept_info WHERE dept_id = " . $row["dept_id"];
    $dept_name = mysql_query($selectquery);

    Peter

Similar Threads

  1. Check MySQL Version thru PHP
    By wolftrap1 in forum PHP Development
    Replies: 2
    Last Post: February 11th, 2004, 08:51 PM
  2. Replies: 5
    Last Post: February 11th, 2004, 02:18 AM
  3. Replies: 0
    Last Post: February 10th, 2004, 11:44 PM
  4. Replies: 0
    Last Post: January 30th, 2004, 01:22 PM
  5. PHP 5 (MYSQL vs. SQLite)
    By ignition in forum PHP Development
    Replies: 1
    Last Post: January 23rd, 2004, 12:13 PM

IMN logo majestic logo threadwatch logo seochat tools logo