Visually Comparing Rows of a MySQL database
Moderator: General Moderators
Visually Comparing Rows of a MySQL database
Essentially what I need to do is give a user the option to check a box to "compare" the desired items (up to 3), then submit that form and have the options visually represented on a single page. I have the table all set up with the desired values but I'm having a hard time figuring out a script to make it work. Any help would be greatly appreciated.
Re: Visually Comparing Rows of a MySQL database
Say the user wants rows A, B, and C. Your form looks like this...
When this is submitted, your PHP page can handle the array like so...
You can handle the array of data POSTed just as you'd handle any other array.
Code: Select all
<input type='checkbox' name='items[]' value='A' />
<input type='checkbox' name='items[]' value='B' />
<input type='checkbox' name='items[]' value='C' />
Code: Select all
$sql = "SELECT * FROM `items` WHERE ";
foreach ($_POST['items'] as $key => $val)
{
$sql .= "`id` = '$val' OR ";
}
$sql = substr($sql,0,-4);
$result = mysql_query($sql);
while ($items = mysql_fetch_assoc($result))
{
// looping through your items to display them
}
Re: Visually Comparing Rows of a MySQL database
Awesome, worked like a charm. Thanks a ton!