I am using PHP5 and mysqli OOP style.
So here is what i have:
// create mysqli object
// open connection
$mysqli = new mysqli($host, $user, $pass, $db);
// check for connection errors
if (mysqli_connect_errno())
{
die("Unable to connect!");
}
// create query
$query = "SELECT * FROM cars";
// execute query
if ($result = $mysqli->query($query)) {
// see if any rows were returned
if ($result->num_rows > 0) {
// yes
// print them one after another
echo "<table cellpadding=10 border=1>";
while($row = $result->fetch_array()) {
[B]for ($x = 0; $x < $result->field_count(); $x++)[/B]
{
echo "<tr>";
echo "<td>".$row[$x]."</td>";
echo "</tr>";
}
}
echo "</table>";
}
else {
// no
// print status message
echo "No rows found!";
}
// free result set memory
$result->close();
}
else {
// print error message
echo "Error in query: $query. ".$mysqli->error;
}
// close connection
$mysqli->close();
and get the following error:
Fatal error: mysqli::field_count() must be derived from mysqli_result::field_count in Unknown on line 0
I changed it to:
for ($x = 0; $x < $mysqli->field_count(); $x++)
But that didnt work
I even tried using it like this:
for ($x = 0; $x < mysqli_field_count($result); $x++)
and that didnt work
I was hoping that field_count could know how many columns it had