MySQL Forums
Forum List  »  PHP

Warning: mysql_fetch_assoc()
Posted by: Jonathan Conner
Date: October 31, 2015 04:49PM

Hello,

I'm trying to display records from a MySQL Database with PHP. I'm kind of new when it comes to PHP. But I made a code for display the record..

now this is my first time doing this. but instead of it working I received the below warning message...

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /home/vuyaezcu/public_html/page1.php on line 34


And this is my PHP code that I just made:


<?php

//make connection
mysql_connect('localhost', 'xxxxxxx','xxxxxxxxx');

//select db
mysql_select_db('kunder');

$sql="SELECT * FROM APARTMENTS";

$records=mysql_query($sql);



?>

<html>

<head>
<title>Lediga Lägenheter</title>
</head>

<body>

<table width="600" border="1" cellpadding="1" cellpadding="1">
<tr>

<th>Objekt</th>
<th>Yta</th>
<th>ID</th>
<th>Kommun</th>
<tr>

<?php

while($apartments=mysql_fetch_assoc($records)){

echo "<tr>";

echo "<td>".$apartments['objekt']."</td>";

echo "<td>".$apartments['yta']."</td>";

echo "<td>".$apartments['id']."</td>";

echo "<td>".$apartments['kommun']."</td>";

echo "</tr>";


}//end while


?>

</table>
</body>
</html>



Does anyone know why this is happening?

I have been trying to find out for my self, but don't seem to find anything helpful..

Thank you Girls and Guys;)!

/J

Options: ReplyQuote


Subject
Written By
Posted
Warning: mysql_fetch_assoc()
October 31, 2015 04:49PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.