well... I have this code...

<?php function ARG_FF() {?>
<!--AIR RESTRICTION GAUGE-->
<td><select name="gauge">
    <option value="8">8</option>
    <option value="11">11</option>
    <option value="15">15</option>
    <option value="22">22</option>
    <option value="25">25</option>
</select></td>
<!--FUEL FILTER-->
<td><select name="filter">
    <option value="20">20%</option>
    <option value="40">40%</option>
    <option value="60">60%</option>
    <option value="80">80%</option>
</select></td>
<?php }?>

and I use it multiple times....

then here comes mysql:

$gauge=$_POST['gauge'];
$filter=$_POST['filter'];


$gaugeFilter="INSERT INTO abc (ARG,Fuel_Filter) VALUES ('$gauge','$filter')";



 if (!mysql_query($gaugeFilter,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added</br>";

...as I said earlier I'm using my php function multiple times but I want to save the data I selected to each selected tag separately but on the same db table but not being merge or overwritten...
**
**I was thinking to create select tag with different names but having the same content,..but that will be long...
and thats my problem I don't know what to do to make shorter....????...

Recommended Answers

All 4 Replies

you could use arrays in the element names ... eg: <select name="filter[0]"> access via $_POST['filter'][0] etc.

...can you explain it...I'm not sure how to use it, ... can you give an example...???...

Ok... so I will use your image as an example of what we could do.

First lets add an index parameter to your function.

<?php function ARG_FF($index) {?>
<tr>
    <!--AIR RESTRICTION GAUGE-->
    <td><select name="gauge[<?php echo $index; ?>]">
        <option value="8">8</option>
        <option value="11">11</option>
        <option value="15">15</option>
        <option value="22">22</option>
        <option value="25">25</option>
    </select></td>
    <!--FUEL FILTER-->
    <td><select name="filter[<?php echo $index; ?>]">
        <option value="20">20%</option>
        <option value="40">40%</option>
        <option value="60">60%</option>
        <option value="80">80%</option>
    </select></td>
</tr>
<?php }?>

Then we create a loop in the form to call the function and print the select controls.

<table>
    <tr><th>Air Restriction Guage</th><th>Fuel Filter</th></tr>
    <?php for ($i = 1; $i <= 8; $i++) { 
        ARG_FF($i);
    } ?>
    <!-- I'm not sure what your table footers are, but you can add a row here -->
</table>

This produces output like the following:

<table>
    <tr><th>Air Restriction Guage</th><th>Fuel Filter</th></tr>
        <tr>
    <!--AIR RESTRICTION GAUGE-->
    <td><select name="gauge[1]">
        <option value="8">8</option>
        <option value="11">11</option>
        <option value="15">15</option>
        <option value="22">22</option>
        <option value="25">25</option>
    </select></td>
    <!--FUEL FILTER-->
    <td><select name="filter[1]">
        <option value="20">20%</option>
        <option value="40">40%</option>
        <option value="60">60%</option>
        <option value="80">80%</option>
    </select></td>
</tr>
    <tr>
    <!--AIR RESTRICTION GAUGE-->
    <td><select name="gauge[2]">
        <option value="8">8</option>
        <option value="11">11</option>
        <option value="15">15</option>
        <option value="22">22</option>
        <option value="25">25</option>
    </select></td>
    <!--FUEL FILTER-->
    <td><select name="filter[2]">
        <option value="20">20%</option>
        <option value="40">40%</option>
        <option value="60">60%</option>
        <option value="80">80%</option>
    </select></td>
</tr>
    <tr>
    <!--AIR RESTRICTION GAUGE-->
    <td><select name="gauge[3]">
<!-- etc.... (cropped for brevity) -->

Then we just need to put your page code into a loop to process the mysql for each iteration.

for ($i = 1; $i <= 8; $i++) { 
    $gauge=$_POST['gauge'][$i];
    $filter=$_POST['filter'][$i];
    $gaugeFilter="INSERT INTO abc (ARG,Fuel_Filter) VALUES ('$gauge','$filter')";

    if (!mysql_query($gaugeFilter,$con))
    {
        die('Error: ' . mysql_error());
    }
}
echo "$i records added</br>";

oh man it worked!
Thank you....your totally a great help....
Thank you :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.