Jump to content

php mysql compare checked boxes help


flimflam

Recommended Posts

Hey, I'm new to this stuff. But I'm calling a Table with a list of products, I want people to be able to compare the products they checked. what is the best way of doing this with the code below?

I put "blah" for everything except for the compare table and calls. This code seemed to work the best for the look I wanted for it. They all call the checkbox from 'Compare' in the mysql table.

 

Thanks!

 

$result = mysql_query("SELECT * from Compare_Tool ORDER BY Blah ASC");

//Table starting tag and header cells

 

echo "<table border='1'><tr><th>Compare</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th></tr>";

 

while($row = mysql_fetch_array($result)){

 

?>

 

<tr>

 

<td align="center"><input name="checkbox[]" type="checkbox" Compare="checkbox[]" value="<? echo $row['Compare']; ?>"></td>

 

<td ><? echo $row['blah']; ?></td>

 

<td ><? echo $row['blah']; ?></td>

 

<td ><? echo $row['blah']; ?></td>

 

<td ><? echo $row['blah']; ?></td>

 

<td ><? echo $row['blah']; ?></td>

 

<td ><? echo $row['blah']; ?></td>

 

<td ><? echo $row['blah']; ?></td>

 

<td ><? echo $row['blah]; ?></td>

 

<td ><? echo $row['blah]; ?></td>

 

<td ><? echo $row['blah]; ?></td>

 

<td ><? echo $row['blah]; ?></td>

 

</tr>

 

<?php }  echo "</table>";

 

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/247610-php-mysql-compare-checked-boxes-help/
Share on other sites

I have no idea why you have a "Compare" field in your database. Here is a brief outline of how I would do a compare process:

 

Int he pages where I list products I would provide a checkbox for each product. The checkboxes would be an array and each checkbox  value would be the ID of the record.

Compare <input type="checkbox" name="compare[]" value="<?php echo $recordID; ?>" />

 

Then when you submit the page you will have an array of all the products the user wants to compare in the POST data. You just use that to then query the database for those products. Example:

$compareIDs = implode(', ', $_POST['compare']);
$query = "SELECT * FROM table WHERE id IN ($compareIDs)"; 

 

Note that I left off a lot of validation that should be done, but that is the rough process.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.