0

so this is what I have so far.

$query = mysql_query("SELECT * FROM tablename ORDER BY id");
while($r = mysql_fetch_array($query)){
extract($r);

echo $variables;
}

The error I get cause of above reason

Notice: Undefined variable: variables in

I've got honestly no idea how to do it ._ .

Harugawa
  • 539
  • 5
  • 19
  • 1
    Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Feb 09 '16 at 15:35
  • 2
    You do not need to `extract()` anything. You just echo or assign `$r['identifier']` to something, where 'identifier' is the column name. This is PHP and MySQL 101. – Jay Blanchard Feb 09 '16 at 15:37
  • @JayBlanchard Thank you, guess I should do more reasearch on mysql before using it. There is tons of outdated guides ;l – Harugawa Feb 09 '16 at 16:10

1 Answers1

0

You should use fetch_assoc() since it returns an associative array with the names and values of the rows. This would allow extract() to generate the correct symbol names and therefor if there is a column called variables the variable $variables would exist.

A more common approach is just to access the data by $r['columnname'];. Note that I updated your code with mysqli functions (since mysql_* is not so good..).

$query = $DB->query("SELECT * FROM tablename ORDER BY id");
while($r = $query->fetch_assoc()){
    extract($r);
    echo $variables;
}
Niki van Stein
  • 10,564
  • 3
  • 29
  • 62