I got this error: "Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\dome.php on line 29" on localhost:69/dome.php I thought I have wrote query wrong but I think it is good because when I type it in phpmyadmin I got one result just like expected. So can someone help me where the problem is. Ok so I just updated my code and now I got this error "Connection succesfull! 1046: No database selected".
So I finally found the solution thanks to a guy @Lock the problem was that I was using two diffrent libaries i mixed my_sql* and my_sqli* in one connection.
//old code
public function GenerirajRandomMode()
{
if($conn = new mysqli("localhost", "root", "", "modedb"))
{
echo "Connection succesfull";
$qt = "SELECT * FROM mode ORDER BY RAND() LIMIT 1";
$results = mysql_query($qt);
if ($results)
{
while ($row = mysql_fetch_assoc($results)) //line 29
{
echo '<tr>';
foreach($row as $field)
{
echo '<td>' . htmlspecialchars($field) . '</td>';
}
echo '</tr>';
}
}
else
{
echo "</br>" . mysql_errno() . ": " . mysql_error();
}
}
else
{
echo "Connection error";
}
}
-----Working code:-----
//new code (working)
public function GenerirajRandomMode()
{
if($conn = new mysqli("localhost", "root", "", "modedb"))
{
echo "Connection succesfull!";
$qt = "SELECT * FROM mode ORDER BY RAND() LIMIT 1";
$results = $conn->query($qt);
if ($results)
{
while ($row = $results->fetch_assoc())
{
echo '<tr>';
foreach($row as $field)
{
echo '<td>' . htmlspecialchars($field) . '</td>';
}
echo '</tr>';
}
}
else
{
echo "</br>" . mysql_errno() . ": " . mysql_error();
}
}
else
{
echo "Connection error!";
}
}