I have a large array. Is there an alternate method to check if $value in the array is present in the MySql table vote and if not then insert $value into vote. This is what i am doing currently. Is there a better method?

foreach($rowids as $value) {


        $select = mysql_query("SELECT voteid FROM vote WHERE username='$username' AND voteid='$value' LIMIT 1",$this->connect);

            if(mysql_num_rows($select)==0) {

        $insert = mysql_query("INSERT INTO vote VALUES ('','$value','$username')",$this->connect);

            }
        }

You could use a unique index on the unique field combination an then use "INSERT IGNORE" without a prior check for doublettes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.