Results 1 to 3 of 3

Thread: Is there an equivalent in php to the MySQL "IN" phrase?

  1. #1
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default Is there an equivalent in php to the MySQL "IN" phrase?

    I'm trying to do this:

    Code:
    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
    Last edited by kuau; 09-02-2008 at 04:08 AM. Reason: forgot code tags

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Plz post the PHP source code so that the correct SQL statements you uses can be viewed.

  3. #3
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    Well, here is the code that correctly lists the categories and the checkboxes:

    Code:
    $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:

    Code:
    $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:

    Code:
    <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>';

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •