Catch information from a foreach with another foreach

0

I have a mysql search that brings me the following array when using a foreach, I have another sql search that brings me all the fields of a table that in case they are the same field names that are below usr_tbl_ssid ... how do to display only the value of contacts_form_name, whatsapp and on the side the field names and at the same time hide the empty fields?

Array
(
    [usr_tbl_ssid] => 
    [0] => 
    [contacts_form_name] => Fye Flourigh
    [1] => Fye Flourigh
    [whatsapp] => +5521999
    [2] => +5521888
    [email] => 
    [3] => 
    [site] => 
    [4] => 
    [facebook] => 
    [5] => 
    [messenger] => 
    [6] => 
)

My code so far is like this

$statement = $conect -> prepare("SHOW COLUMNS FROM $usr_");
$statement -> execute();
$user_table_columns = $statement -> fetchAll();
foreach($user_table_columns as $user_columns => $columns) {
    $array_columns[] = $columns["Field"]; }

$statement = $conect -> prepare("SELECT * FROM $usr_ WHERE contacts_form_name = :contacts_form_name LIMIT 1");
$statement -> bindValue(":contacts_form_name", $_POST['search_content']);
$statement -> execute();
$_SESSION["search_send"] = $statement -> fetchAll();
foreach($_SESSION["search_send"] as $contacts_form => $search_data_content) {
    $array_data[] = $search_data_content; }

And I display them quite ugly, so

<?php foreach($array_columns as $index => $columns_content) { ?>
    <span><?php print_r( $columns_content ); ?></span>
<?php } ?>
<?php foreach($array_data as $index => $data_content) { ?>
    <span><?php print_r( $data_content ); ?></span>
<?php } ?>

How do I get only the fields with values and their values next to them

example

Contact name (contacts_form_name): Fye flourigh

Note: I can not limit which fields I will see in the mysql search because there are not six fields that each user has created, so I have to run a show columns.

    
asked by anonymous 23.04.2016 / 12:10

1 answer

1

First of all, I'm sorry if my answer is not what you're looking for, because I could not fully understand your question.

for($i=0;$i < count($data_content);$i++) { // Faz um loop para pegar todos os elemento da array $data_content.
if($data_content[$i] != null) { // Se o valor do elemento da array for diferente de vazio ele continua
  if($i == 1) { // Se o valor do elemento da array for um(contacts_form_name)
    echo "Nome do contato:" . $data_content[$i] . "\n";
  }
  if($i == 2) { // Se o valor do elemento da array ser dois(whatsapp)
    echo "Whatsapp do contato:" . $data_content[$i] . "\n";
  }
  if($i == 3) { // Se o valor do elemento da array ser três(email)
    echo "Email do contato:" . $data_content[$i] . "\n";
  }
  if($i == 4) { // Se o valor do elemento da array ser quatro(site)
    echo "Site do contato:" . $data_content[$i] . "\n";
  }
  if($i == 5) { // Se o valor do elemento da array ser cinco(facebook)
    echo "Facebook do contato:" . $data_content[$i] . "\n";
  }
  if($i == 6) { // Se o valor do elemento da array ser igual a seis(messenger)
    echo "Messenger do contato:" . $data_content[$i] . "\n";
  }
}
}

I do not know if it is allowed to post links from external emulators, if not someone please let me know, but here is an example link .

    
24.04.2016 / 08:42