PHP: Control Id Row[]

Asked

Viewed 48 times

-1

There is a way to control the id’s of the data coming from the Row[] ?

Example:

Assuming I want him to show me the 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 fetches data from other id’s and I want to know if the way around that. Something like $Row[18]. id

  • do print_r array $row and put here an example

1 answer

3

For a better view and maintenance recommend using the attribute name instead of using their positions.

Select the data the way you want it $Row[position][name] is not possible unless the return of the accessed position is also an array that in this case would be an array!

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

$row["id"];

There is the possibility to use fetch_object allowing you to access +/- as you want, in case it would look like this:

$row->id;
  • while($Row = mysql_fetch_array($validity)){ I use it like this

  • 1

    then, instead of using $Row[position] uses direct $Row[name], ie $Row['id'], $Row['email']. The name must be the same as returned by the query. From a read on mysqli!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.