I am currently learning to program in PHP for some tutorials on YouTube from "the newboston" (maybe they know it) and I am in the database part of mySQL.
In my program I try to query data from a table in mySQL but it throws me an error that says the following: Warning: mysql_fetch_array () expects parameter 1 to be resource, array given.
this is my code:
By the template
<?php
$con_error='Could not connect';
$mysql_host='localhost';
$mysql_user='root';
$mysql_pass='';
$mysql_db='new_database';
/*connect to server / database*/
$mysqlcon=@mysql_connect($mysql_host, $mysql_user, $mysql_pass) or die($con_error);
/*select database*/
mysql_select_db($mysql_db, $mysqlcon) or die($con_error);
From the page that runs it
require 'database.php';
$query="SELECT * FROM comida ORDER BY id";
if ($query_run = @mysql_query($query)) {
while ($query_run= mysql_fetch_array($query_run)) {
$platillo=$query_run['platillo'];
$calorias=$query_run['calorias'];
echo ' <br> platillo '.$platillo.' ofrece '.$calorias.'<br>';
}
} else {
echo '<br> could not connect <br>';
}
I hope you can help me with this. Thanks in advance for the answers!