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.