PDA

View Full Version : Is there an equivalent in php to the MySQL "IN" phrase?



kuau
09-02-2008, 04:08 AM
I'm trying to do this:


DISPLAY all the categories and echo " checked" WHERE cat_id IN (SELECT cat_id FROM eventcategories WHERE event_id = $event_id);

I can't believe this could be such a difficult thing to do. I just can't get past it. Please help.

Also, my page hangs there grinding away with the message "one item remaining." How do I find out what is causing that? and what is the one item?

Mahalo, e

codeexploiter
09-02-2008, 04:58 AM
Plz post the PHP source code so that the correct SQL statements you uses can be viewed.

kuau
09-02-2008, 05:49 AM
Well, here is the code that correctly lists the categories and the checkboxes:


$sql = "SELECT cat_id, category FROM category ORDER BY category";
$result_cat = mysql_query($sql,$connection) or die("Couldn't execute $sql query. <br> mysql error: ".mysql_error());
$count=0;
while ($row = mysql_fetch_array($result_cat))
{
$count++;
echo '<td width="253"><input type="checkbox" name="cats[]" value="'.$row['cat_id'].'">' .$row['category'].'</td>';
if (($count % 3) == 0){
echo "</tr>";
}
}

To get the categories for a particular event_id I tried this but it didn't work:


$sql = "SELECT * FROM eventcat WHERE event_id = '".$_GET['event_id']."' ";
$result_evcat = mysql_query($sql,$connection) or die("Couldn't execute $sql query. <br> mysql error: ".mysql_error());
while($row = mysql_fetch_array($result_evcat))
{ $count++;
$evcat_id = $row['cat_id'];
}

with this in the output line:


<td width="253"><input type="checkbox" name="cats[]" value="<?php echo $row['cat_id'];?>"<?php if($row['cat_id'] == $evcat_id){echo " checked";}?>> <?php echo $row['category'];?></td>';