Forum Moderators: coopster
I do not need removing dupes I just need to know if a value from post exists already in the table
why: (FYI) if it exists I increment a count by 1, if not it's a simple insert new row.
how will I find a match and simply return 1 or true?
(IMPORTANT: some rows might hold a single value, others could be made of mutilple values comma separated)
Using in array or intersect did not work unless I did it poorly (I am no spe with tough array deal :) )
// this is $dupe
/*
$tags=trim($_POST["tags"]);
$tags=explode(",",$tags); //print_r($tags);
*/
$dupe=$tags;
$db->connect($host, $un, $pw);
$db->query($db_db);
$result_tags = $db->query("
SELECT
tag
FROM
tags_quest
WHERE
head_cate_quest_id='$head_cate_quest_id'
");
$tags_num=$db->num_rows($result_tags); //echo"NUM: $tags_num<P>";
$i=0;
while ($i <$tags_num)
{
$tag_check=mysql_result($result_tags,$i,"tag");
$tag_check=array_merge(array($tag_check)); // print_r($tag_check);
// here is the checking part
// and I cannot figure it out!
$i++;
}
I fixed my previous problem
first thing first
when entering comma separated tags
just after $_POST explode the POST value
do the usual security stuffs
serialize(), sanitize before DB insert
Then here is the system I use to check if a value within POST exists already in the DB
$result_tags = $db->query("
SELECT
tag
FROM
aaaaaaa
WHERE
head_cate_quest_id='$head_cate_quest_id'
");
$tags_num=$db->num_rows($result_tags);
$i=0;while ($i <$tags_num)
{
$tag_check=mysql_result($result_tags,$i,"tag");
$tag_check=unserialize($tag_check);
$tag_check=array_merge($tag_check); // print_r($tag_check);$i++;
}
foreach($dupe as $key => $v)
{
if($tag_check[$key] != $v) {
$tag_check = false;
break;
}
}
if($tag_check === false) {
echo 'No match';
}
else
{
echo"match";
}