I am new to PHP and I am trying to build a website using PHP. I have localhost for testing the result and I have phpmyadmin already installed on the website.
What i am trying to do now, is to list the contents of my table "property" from database "portal" and fill a table with the results.
I am using mysqli_query
, mysqli_fetch_array
and while loop. I'm getting the following error:
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\falcon\portal\forms\edit listing.php on line 15
session_start();
require_once "connect_to_mysql.php"; // where i store username and password to access my db.
$sqlCommand = "SELECT * property FROM portal"; // dbname: portal - table: propery
$query = mysqli_query($myConnection, $sqlCommand);
$Displayproperty = '';
while ($row = mysqli_fetch_array($query))
$id = $row["pid"];
$title = $row["ptitle"];
$area = $row["parea"];
$city = $row["pcity"];
$Displayproperty .= '<table width="500" border="0" cellspacing="0" cellpadding="1">
<tr>
<td>' . $id . '</td>
<td>' . $title . '</td>
<td>' . $area . '</td>
<td>' . $city . '</td>
<td><a href="forms.php?pid=' . $id . '">Upload images</a><br /></td>
</tr>
</table>';
Definition and Usage. The query() / mysqli_query() function performs a query against a database.
Definition and Usage The fetch_array() / mysqli_fetch_array() function fetches a result row as an associative array, a numeric array, or both. Note: Fieldnames returned from this function are case-sensitive.
The mysqli_query function is used to execute SQL queries. The function can be used to execute the following query types; Insert. Select.
fetch_array returns value with indexing. But Fetch_assoc just returns the the value. here array location 0 contains 11 also this location name is 'id'. means just returns the value.
Your query is wrong, so after
$query = mysqli_query($myConnection, $sqlCommand);
$query is false. That's why, you get the error.
The correct SQL Query is:
SELECT * FROM portal.property
If you need to specify the database name. Also, before doing:
while ($row = mysqli_fetch_array($query))
You should check that $query exists
if(!empty($query) {
while ($row = mysqli_fetch_array($query)) {
...
Replace your query with this. Make sure you have added this line before.
$db = mysql_select_db('portal');
$sqlCommand = "SELECT * FROM property";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With