0

If I do this kind of query:

<?php
SELECT * FROMloginwhereemail = 'something@something.com';
$result = mysqli_query($connection, $query) or die("Query error");
while ($row = mysqli_fetch_array($result)) {
    $id = $row['id'];
    $email = $row['email'];
    $first_name = $row['first_name'];
    //(......)
}
?>

is there a way that the MySQL result can be with different variable names? I mean:

SELECT (first_name as foo) FROM login where email = 'something@something.com';

$first_name = $row['foo'];
karel
  • 5,489
  • 46
  • 45
  • 50
  • What happened when you tried that? – user3783243 Mar 03 '19 at 17:22
  • Probably a duplicate of https://stackoverflow.com/questions/14456529/mysqli-fetch-array-while-loop-columns – Bharat Geleda Mar 03 '19 at 17:27
  • 1
    You should always use prepared statements when using any data in a query, no matter what the source of the data otherwise you leave yourself vulnerable to SQL Injection attacks – SpacePhoenix Mar 03 '19 at 18:07
  • What you're doing should work... but on the other hand, your first snippet doesn't. Please try to create a [minimal, complete and verifiable example](https://stackoverflow.com/help/mcve) so we can help you out. – aaaaaa123456789 Mar 04 '19 at 04:35

0 Answers0