I am doing a foreach on an array. Within the foreach, I am first testing to see if the value is already in the MySQL table. If it is, I want to save the id of that select result into a new array. If the the value is not in the table, I'd like to add it to the table and extract the new id and put it into the same new array.
After the foreach statement, I'd like to insert the array of ids into a different table.
Within the foreach I am also incrementing a variable so that I can build the location string where the array of ids will go.
I've been unable to pull the results correctly. The most trouble I'm having seems to be looping through the query and insert and getting all of the results into a new array to be exploded later. Here's one of the incarnation of my attempts to give you an idea:
$i=0;
foreach ($selecting_typeid as $each_typeid) {
$check_for_type = mysql_query("SELECT typeid FROM type WHERE typename like '$each_typeid%' ") or die("Can't execute check type.");
if ($result=mysql_fetch_array($check_for_type)) {
$type = array();
$type = array_push($type, $result[typeid]);
} else {
mysql_query("INSERT INTO type (typename) VALUES ('$each_typeid')");
$type = "".mysql_insert_id()."";
$type = array($type);
}
$i++;
$where_insert_typeid .= "typeid$i,";
}
$list = implode("/", $type);
mysql_query("INSERT INTO ingredient (ingname, status, $where_insert_typeid warning) VALUES ('$ingname', '$status', '$list' '$warning')") or die("Couldn't execute ingredient insertion1.");
Please help me figure out a graceful way to do this.
Thanks