I'm very new to php and I have this code. I can't tell if the data is being taken from the database.
$sql = mysql_query("SELECT id,question,date,user,numberofcomments FROM questions");
if (!$sql) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$result = mysql_fetch_row($sql);
echo '<table border="1">
<tr>
<th>Title 1</th>
<th>Title 2</th>
</tr>';
while($row = mysql_fetch_assoc($result))
{
echo '<tr>';
echo '<td class="leftpart">';
echo '<h3><a href="topic.php?id=' . $row[id] . '">' . $row['question'] . '</a><h3>';
echo '</td>';
echo '<td class="rightpart">';
echo $row['date'];
echo '</td>';
echo '</tr>';
}
I'm getting this error.
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, array given in
Can someone explain this error. I commented out the while($row... and there was no error and the data did not show up making me assume the data isn't being taken from my database correctly. I'm not sure exactly how these functions work and the help file is confusing me so I came here.
What did I do wrong and what can I change?
EDIT:
I am connected to the database (I've pulled out information for usernames and passwords already)