Omar Omar - 7 months ago 9
SQL Question

mysqli_query, mysqli_fetch_array and while loop

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>';

Answer

Replace your query with this. Make sure you have added this line before.

$db = mysql_select_db('portal');

$sqlCommand = "SELECT * FROM property";