I need some help I am trying to build a script that takes multiple keywords and explodes them then compares them to whats in a database and if the keyword exists just update the table adding a number to a field, but if the keyword doesn't exist then add the keyword and add the number the the field.
This is a basic idea I suppose of what I want to do it "sort" of works.
<?php
$dbHost = 'localhost';
$dbUser = 'spaztast';
$dbPass = '*********';
$dbName = 'spaztast_spazweb';
mysql_connect($dbHost,$dbUser,$dbPass);
mysql_select_db($dbName);
$var = "book programming";
$var2 = explode(" ", $var);
$result = mysql_query("SELECT * from tbl_keyword");
$i = 0;
while($r = mysql_fetch_array($result))
{
if($var2[$i] == $r['k_word'])
{
echo "Key Exist's";
}
else{
echo $r['k_word'] . "<br>";
}
$i = $i++;
}
?>
Now heres the thing the table looks like this:
+---------+-------------+-------+
| word_id | k_word | pd_id |
+---------+-------------+-------+
| 1 | palm | 11 |
| 2 | programming | 17 |
| 3 | C# | 18 |
| 4 | book | 18 |
+---------+-------------+-------+
This is the output when the script is run:
palm
programming
C#
Key Exist's
I guess what I am asking is, how I loop one exploded value against all the keys in the database? I think thats what I want too do just unsure of how to do it.