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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.