Basically I have created a site where someone can view a table which contains information about various servers. They can also create a report from this table selecting the fields they want to see in their report. Each field can be selected through a checkbox and there are 16 different fields. The form works correctly and i used get for the method and had the 'name' for each checkbox set to an array. Here is a sample:

<td>DDMA_Location_Comp:<input type="checkbox" name="field[]" value="DDMA_Location_Comp"><br></td>
<td>Server_ID:<input type="checkbox" name="field[]" value="Server_ID"><br></td>
<td>HostName:<input type="checkbox" name="field[]" value="HostName"><br></td>
<td>Comments:<input type="checkbox" name="field[]" value="Comments"> <br></td></tr>

I am able to retrieve the table fine in my php file but i am having trouble with how to create the select statement. I can get the number of boxes that were checked but I dont see how to construct my select statement as I dont know to change it based on how many boxes were checked. It seems tedious to check and see specifically what boxes were checked so i was wondering if there was a better way to do this?

Recommended Answers

All 2 Replies

If all fields are from the same table, I would just SELECT * and use the selected fields for displaying them.

// ... omitted
$row = mysql_fetch_assoc($result);
foreach ($_POST['field'] as $column)
  echo $row[$column] . '<br/>';

If all fields are from the same table, I would just SELECT * and use the selected fields for displaying them.

// ... omitted
$row = mysql_fetch_assoc($result);
foreach ($_POST['field'] as $column)
  echo $row[$column] . '<br/>';

Hmm didnt think that i ended up just adding on to my $query variable and that worked fine but your way probably looks nicer

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.