[SOLVED] Mysqli ?
Posted: Tue May 09, 2006 3:26 pm
Hey guys,
I'm trying to use an associative array to set vars fetched from a mysql db..For some reason I keep getting:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in C:\wamp\www\SAT\question.php on line 32
No rows found!0
The table does have one entry, so it shouldn't be null or empty...When I use the while loop to fetch the array in the db.php file it works...but when I try in questions.php (while require(db.php)) it doesn't work.....? why?
Here is my database connection php file:
Here is the loop (code fragment) i'm using in question.php to set the associative array:
Help appreciated, thanks!
I'm trying to use an associative array to set vars fetched from a mysql db..For some reason I keep getting:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in C:\wamp\www\SAT\question.php on line 32
No rows found!0
The table does have one entry, so it shouldn't be null or empty...When I use the while loop to fetch the array in the db.php file it works...but when I try in questions.php (while require(db.php)) it doesn't work.....? why?
Here is my database connection php file:
Code: Select all
<?php
// set server access variables
$host = "XXXXXXXXXXX";
$user = "XXXXXXXXXXX";
$pass = "XXXXXXXXXXX";
$db = "XXXXXXXXXX";
// open connection
$connection = mysqli_connect($host, $user, $pass, $db) or die ("Unable to connect!");
// create query
$query = "SELECT * FROM questions";
// execute query
$result = mysqli_query($connection, $query) or die ("Error in query: $query. ".mysqli_error());
// free result set memory
mysqli_free_result($result);
// close connection
mysqli_close($connection);
?>Code: Select all
/* Default Constructor
*
*/
public function __construct() {
// see if any rows were returned
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
$id = $row['id'];
}
}
else {
// no
// print status message
echo "No rows found!";
}
}