Gustavo mysql_query
is deprecated in the newer PHP version, it is unsafe but does the job.
Instead I rather give you an answer with my favorite way of query databases
PDO it is secure and it is object-oriented.
first we need to set it up
// instance of pdo
$config['db'] = array
(
'host' => '',
'username' => '',
'password' => '',
'dbname' => ''
);
$database = new PDO('mysql:host=' . $config['db']['host'] .
';dbname=' . $config['db']['dbname'],
$config['db']['username'],
$config['db']['password']);
$database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//query with a new database object
$queryObject = $database->prepare("SELECT id
FROM afunda_eleva");
//execute sql
$queryObject ->execute();
// store the results in array
$results = $queryObject->fetchAll();
//print_r results to test
print_r($results);
//after analysing the array and how its structured define
for($i=0; $i < 4; $i++)
{
echo $results[$i]
}
try that code with your database credentials on the instance, if you want to include this in a seperate db file that gets included before calling pdo make sure you call global $database;
to call upon its instance
here is a good pdo tutorials playlist, good luck
https://www.youtube.com/watch?v=XQjKkNiByCk