i have an array called MyArray i want to insert its data into mysql but first need to check if it exist in mysql already. could any one tell me how i can loop through array and how to reference each variable inside the array then insert those data in to mysql?
$MyArray[] = array(
"usernameVar" => htmlspecialchars($usernameVar),
"profPic" => htmlspecialchars($profPic),
"idVar" => htmlspecialchars($idVar),
"standardResolution" => htmlspecialchars($standardResolution),
"imagePageLink" => htmlspecialchars($imagePageLink),
"createdTimeVal" => htmlspecialchars($createdTimeVal),
"imageTags" => htmlspecialchars($imageTags),
);
$MyArray = array_reverse( $MyArray );
//now i need to loop through array and insert non duplicate data in to mysql
$result = mysql_query("SELECT imageUrl FROM mytable WHERE imageUrl = '$standardResolution'");
if (!$result) {
die('Invalid query: ' . mysql_error());
}
if(mysql_num_rows($result) == 0) {
$j++;
echo "<a href='".$imagePageLink."'><img src='".$standardResolution."' width='150' height='150' border='0'></a><br> ";
// row not found, do stuff...
echo "New Users(".$i."):";
echo "<br>User Name(".$i."):".$usernameVar;
$result2 = mysql_query("INSERT INTO mytable (ID, username, profile_picture, instaId, imageUrl,imagePageURL, CreatedTime, imageTags, date) VALUES('$ID','$usernameVar','$ProfilePicVar','$idVar','$standardResolution','$imagePageLink','$createdTimeVal','$imageTags',NOW())");
if (!$result2) {
die('Invalid query: ' . mysql_error());
}
}
else
{
$m++;
// do other stuff...
echo "Already Added Users(".$i."):";
echo "<br>User Name(".$i."):".$usernameVar;
};