简体   繁体   中英

How can I get a result from mysql_fetch_row (or mysql_fetch_array)

$sqlQuery = "SELECT * FROM allowedUsers WHERE UserID = '" . $kUserID . "'";
$result=mysql_query($sqlQuery, $db);
if(!result)
{
    echo "Error running query <br>" . mysql_error();
    exit;
}
while($row = mysql_fetch_array($result))
{
    echo $row[2];
}

I run the SQLQuery in phpMyAdmin and I am getting a valid result (1 row) the table (allowedUsers) has 6 fields I can't get anything out of the DB.

Any help is appreciated.

if(!result)应该是if(!$result)

According to PHP.net's documentation , you don't need to pass $db to mysql_query() . Take a look at the example code:

<?php
    mysql_connect("localhost", "mysql_user", "mysql_password") or
        die("Could not connect: " . mysql_error());
    mysql_select_db("mydb");

    $result = mysql_query("SELECT id, name FROM mytable");

    while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
        printf("ID: %s  Name: %s", $row[0], $row[1]);  
    }

    mysql_free_result($result);
?>

It may be helpful to see your connection code, ensure you've selected a database, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM