I have a PHP form that inserts in a database table what an user choose from 4 checkboxes.
This is the code that I use:
<?php
$id_language = ($_POST['id_language']);
$tot_value = "";
foreach ($id_language as $value) {
$tot_value .= "$value\n";
}
$sql_run = "I_NSERT INTO MyTable (id_language) VALUES ('$tot_value')";
$sql_result = mysql_query($sql_run);
?>
Languages:<br />
<input type="checkbox" value="Spanish" name="id_language[]">Spanish<br />
<input type="checkbox" value="English" name="id_language[]">English<br />
<input type="checkbox" value="German" name="id_language[]">German<br />
<input type="checkbox" value="French" name="id_language[]">French<br />
<br>
<input type="submit" name="submit" id="submit" value="Submit">
The checkboxes could be chosen all 4 or also 3, or 2, or 1.
As you can see the data in the database table are inserted as an array, in fact I have, for example:
Quote
id_language
English
German
French
English
German
French
Then I have a frontend part where the user can choose from 4 countires (Spain, UK, Germany, France) and after this the user can search deep.
The frontend of my "program" is a table where I print these infos stored in my database:
Category of the plant......
Name of the plant.....
Country.....
Languages.....
Instead of the languages I'd like to print the flag of the languages, something like this:
<?php
if ($id_language == "Spanish") {
?>
<img src="flags/esp.png" />
You already suggested me this way:
<?
$id_language = array("Spanish", "English", "German", "French");
if (in_array("English", $id_language)) {
?>
<img src="flags/uk.png" />
This way work, but it obviously prints all the flag.
I'd like to take the array with the X languages stored in my database table and then compare or search in it the languages insertes.
Any help?
I'm really disperate about this.
P.S.: the languages are max 4 and setted by me as checkboxes.
P.P.S: I know that "I_NSERT" is wrong but otherwise I couldn't post the thread.


Sign In
Create Account

Back to top









