Is there anyway to select rows that match multiple values? Like something like

select * from table where column = 1,2,3

like, any one that matches 1 or 2 or 3 will also be selected?

    $users = mysql_query("SELECT author_id FROM users WHERE name LIKE '%$query%'");

    this is my query for certain artists

    $sql_text = "select * from $choice where author_id IN ($artist_array) $extra";

    then i want to select all author ids that matched that first query with $sql_text. What kind of array would i use?

      $array = array(1,2,3,4,5,6,7,8,9);
      $result = mysql_query('SELECT * FROM table WHERE field IN(' . implode(',', $array) . ')');
      

        Okay i got something like this set up

        $series = mysql_query("SELECT series_id FROM layout_series WHERE series LIKE '%$query%'");

        //create blank array
        $series_array = array();

        while($row = mysql_fetch_array($series)) {
        //Add ids to the blank array
        $series_id = $row['series_id'];
        array_push($series_array, "$series_id");
        }

        //implode the array by comma
        $separated = implode(",", $series_array);
        echo $separated;

        //select from the table where the array is imploded
        $sql_text = "select * from $choice where series_id IN ($separated) $extra";

        My problem however, is that it works to a certain extent, but doesn't compute spaces! Like if I type "hello world", the code produces an error!

          Try putting this before $series;

          $series = mysql_escape_string($series);

            nope, now ive been testing this, and im running around the basics....why isnt this simple code not working for me??

            If it's not a problem with the code, I'll go look at my database for holes...

            $series = mysql_query("SELECT series_id FROM layout_series WHERE series = 'Chobits'");

            while($row = mysql_fetch_array($series)) {
            $series_id = $row[series_id];
            echo $series_id;
            }

              Oh! I figured out my problem. The database stored the strings like this "Hello_world" instead of "Hello world", so all I had to do was convert the string. Doh. -_-; Thanks for your help.

              The only thing I want to know is, why didn't the above code work?

                $sql_series = mysql_query("SELECT series_id FROM layout_series WHERE series='Chobits'") or die(mysql_error());
                
                while(($row = mysql_fetch_array($series)) !== FALSE) {
                $series_id = $row['series_id'];
                echo $series_id;
                }
                

                Try that.

                  Probably becuase you never told your while statement when to stop.

                  i.e. !== FALSE

                    Also, in your code above:

                    //select from the table where the array is imploded
                    $sql_text = "select * from $choice where series_id IN ($separated) $extra";

                    Might produce an error since you never assigned a value to $extra;

                      Write a Reply...