PHP/MySQL Quick help please

Discussion in 'PHP' started by Crayz, Feb 14, 2007.

  1. #1
    Hello, I was wondering if its possible to determine inside the SELECT function if an entry exists inside the table,

    Say I had a row named oID and inside that row there would be this data:

    57,81,90,45,108

    Now, what I want to do is select the results from a query that do not include the ID $id1 where $id1 = 81

    Is this possible to do inside only the select statement? If not, what would be your suggestion.

    Thanks :)
     
    Crayz, Feb 14, 2007 IP
  2. Munk

    Munk Peon

    Messages:
    56
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    select * from oID where id != $id1
    Code (markup):
     
    Munk, Feb 14, 2007 IP
  3. Crayz

    Crayz Well-Known Member

    Messages:
    708
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    120
    #3
    Ok cool, the ! mark makes it select everything that doesn't include the $id1 ?

    Edit:

    I am using a code similar to below:
    
    $array = split(",", "$ids");
    $complete = "false";
    $fid = $rowsSet['fid'];
     
    foreach($array as $key => $value)
    {
    if (trim($value) == $fid){ 
    $complete = "true";
    }
    }
    Code (markup):
    And was wondering if I would be able to use to select function aswell as this combined to be able to pick out all the id's that are inside the database and display the ones that arent.

    The variable $ids would contain things such as.. 7632,734232,123565,237834,23546 etc.
     
    Crayz, Feb 14, 2007 IP
  4. SilkySmooth

    SilkySmooth Well-Known Member

    Messages:
    1,583
    Likes Received:
    269
    Best Answers:
    0
    Trophy Points:
    180
    #4
    Crayz, yes the exclamation does indeed mean "does not equal".

    You can also use the SELECT query inside of your foreach loop to determine if an ID exists in the database table... here is a quick example:

    
    <?php
    foreach($array as $key => $value)
    {
    $query="SELECT * FROM tablename WHERE oid = '".trim($value)."'";
    $result=mysql_query($query);
    // Check the result
    if (mysql_num_rows($result)>0)
       {
       echo "The ID is in the table";
       }else
       {
       echo "The ID is NOT in the table";
       }  
    }
    ?>
    
    Code (markup):
    HTH
     
    SilkySmooth, Feb 14, 2007 IP