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 are the same field names that are below usr_tbl_ssid... as I do to display only the value of contacts_form_name, Whatsapp and on the side the names of the fields 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 show them in a totally ugly way, like this
<?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’t limit which fields I will see in mysql search because not six which fields each user created, so I have to run a show Columns.
the first part I think helps a lot in what I need, I will test as soon as possible, already the parts below do not know if it will help because the problem is, I do not know what are the fields that the user created, Whatsapp, Messenger and email is just example, each database has the fields that the user determines, in this case, where are the names of the field that you put i = n• this would have to be dynamic, but can by external emulators yes.
– flourigh
then, looking at the emulator, this is exactly what I wanted for the first part, this was the one I was not able to elaborate, but, as it would be for an infinite number, instead of putting 1...6 as it would be to be infinite and take the name of array1, in array1 are the names of the fields that the user wrote and in the array2 that you did are the values.
– flourigh
@Sorry to keep you waiting. But, I took a look again at your question and I think now I understand (I think you get very flustered when you type, before "Press Enter", reads your own text, because it will make it easier for those who answer). If your question was what you wanted to show for example: contacts_form_name : Fye Flourigh was only to use the element
if
, take "id" from the elements of the variable$columns_content
and synchronize with the ID’s$data_content
. Example:echo $columns_content[$i] . " : " . $data_content[$i] . "\n";
– иѳbιң
The answer link above on Ideone
– иѳbιң
Its code is very good, but I am in extreme difficulty, my array does not look beautiful like yours, it is all full of information, I think multidimensional, as I do to leave the array of this example http://ideone.com/FrHa2K like yours?
– flourigh
one of the arrays I got, but Columns which is very complex is very difficult
– flourigh
@Nobih got it thanks to another question I asked, it worked well when I joined yours with his [link = http://answall.com/questions/125271/diminur-um-array-multidimencional/125283#125283]decrease-an-array-multidimencional[/link]
– flourigh