flimflam Posted September 21, 2011 Share Posted September 21, 2011 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>"; ?> Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 21, 2011 Share Posted September 21, 2011 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. Quote Link to comment Share on other sites More sharing options...
flimflam Posted September 21, 2011 Author Share Posted September 21, 2011 I took out where it calls the compare table in the db. And have the checkboxes there in the compare field for the results shown. any other little tid-bits of help you can pass on my way? Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.