I'm not sure how to go about this. I have a nested foreach that I'm attempting to build an insert query from.
preg_match_all('/...../', $text, $matches);
foreach ($foo[0] as $bar){
$item1 = $bar
preg_match_all('/..'/, $bar, $result){
foreach($result[0] as $link){
something here
}
$insertstuff = "insert ignore into table (field1, field1) values (value1, value2)..etc
mysql_query($insertstuff, $con);
}
So here is my question. There will be anywhere from 0 - 10 links returned in the nested foreach. How do I build the query to take those links and insert them into the respective column, ie link1, link2 --> link10. This is just a barebones example, I just am not sure how to structure the query to take into account the unknown number of things to insert.
To update: I have it working but i'm not sure if it's the most efficient.
$i=1;
foreach ($result[0] as $link) {
if ($i=1)
{$link1 = $link;}
elseif ($i=2)
{$link2 = $link;}
elseif ($i=3)
{$link3 = $link;}
etc down to 10.
$i++;
}
Thank you