PHP: Control Id Row []

-1

Is there a way to control the id's of the data coming from Row []?

Example:

Imagining that I want it to show ID1 data

$Nome = '<p>Nome: '.$row[18].'</p>' ;
$DataNascimento = '<p>Data Nascimento: '.$row[19].'</p>' ;
$Morada = '<p>Morada: '.$row[20].'</p>' ;
$Email = '<p>Email: '.$row[21].'</p>' ;

Sometimes it will fetch the data from other id's and I wonder if the way around it. Something like $ Row [18] .id

    
asked by anonymous 14.08.2014 / 17:03

1 answer

3

For a better view and maintenance I recommend using the name of attributes rather than using your positions .

Selecting the data in the way you want $ row [position] [name] is not possible unless the returned position is also an array that would be an array!

If you are using the mysql or mysqli methods ( recommend reading over PDO ) instead of fetch_row you can use fetch_array that allows you to access the data through the names.

$row["id"];

You can use fetch_object allowing you to access +/- as you want , it would look like this:

$row->id;
    
14.08.2014 / 17:39