Jump to content

foreach help


supermerc

Recommended Posts

Hey,

 

I have a script that goes to a website using CURL and then checks for patterns within a certain area of the page like this:

 

<?php
$data = $result2;
$pattern = '#src=[\'"][^\'"]+/(.+?\.(?:png|jpe?g|gif))[\'"].+?ONMOUSEOVER=[\'"]itempopup\(event,\'(\d+)\'\)[\'"]#i';
preg_match_all($pattern, $data, $images);
$spath = $images[1][0];
$id = $images[2][0];
?>

What I want to do is for each match it finds it checks into database in a table for a match with the selected fields and if theres a match is echos out something. I already have the working code for the check and the echoing but I dont know really how to do the foreach so that it will look for each match it finds.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/158419-foreach-help/
Share on other sites

The thing is as you know ken, that my script was working before when I was checking for just the image link, but now that Im checking for image link AND id it doesnt work anymore..

 

This was my previous, working code:

<?php
f$data = $result2;
$pattern = "/src=[\"']?([^\"']?.*(png|jpg|gif))[\"']?/i";
preg_match_all($pattern, $data, $images);

     $maxItemsPerRow = 20;
      $i = 1;
foreach($images as $array) {
foreach($array as $image) {
$fun = substr($image, strrpos($image, "/")+1, -1);
	$qry =  "SELECT * from items WHERE spath = '{$fun}'";
$query = mysql_query($qry) or die (mysql_error());
$num = mysql_num_rows($query);
if($num > 0) {
while($results = mysql_fetch_array($query, MYSQL_ASSOC)) {
  echo "<td width=\"30\" height=\"30\" align=\"center\" valign=\"middle\" style=\"background-image:url(http://quiver.outwar.com/images/crewup/vault_tile.gif); width:30px; height:30px;padding:3px;\">
	                					                				<img id=\"v_item_border0\" src=\"http://quiver.outwar.com/images/{$results['spath']}\" style=\"border:0px;margin:0px;width:24px;height:24px;\" ONMOUSEOVER=\"itempopup(event,'9109629')\" ONMOUSEOUT=\"kill()\" onClick=\"checkSelect();kill();\">
	                					                				<input type=\"checkbox\" name=\"v_selected[]\" id=\"v_selected_0\" value=\"9109629\" style=\"display:none;\">
	                					                		</td>";
																if($i % $maxItemsPerRow == 0) {
            // Insert row break
            echo "</tr><tr>";
        }
        $i++;

}
} 
	}
}
?>

 

And now this is my new code where Im looking for link and ID

 

<?php
$data = $result2;
$pattern = '#src=[\'"][^\'"]+/(.+?\.(?:png|jpe?g|gif))[\'"].+?ONMOUSEOVER=[\'"]itempopup\(event,\'(\d+)\'\)[\'"]#i';
preg_match_all($pattern, $data, $images);
$spath = $images[1][0];
$id = $images[2][0];
$maxItemsPerRow = 20;
      $i = 1;
foreach($images as $array) {
foreach($array as $image) {
$fun = substr($image, strrpos($image, "/")+1, -1);
	$qry =  "SELECT * from items WHERE spath = '{$fun}'";
$query = mysql_query($qry) or die (mysql_error());
$num = mysql_num_rows($query);
if($num > 0) {
while($results = mysql_fetch_array($query, MYSQL_ASSOC)) {
  echo "<td width=\"30\" height=\"30\" align=\"center\" valign=\"middle\" style=\"background-image:url(http://quiver.outwar.com/images/crewup/vault_tile.gif); width:30px; height:30px;padding:3px;\">
	                					                				<img id=\"v_item_border0\" src=\"http://quiver.outwar.com/images/{$results['spath']}\" style=\"border:0px;margin:0px;width:24px;height:24px;\" ONMOUSEOVER=\"itempopup(event,'9109629')\" ONMOUSEOUT=\"kill()\" onClick=\"checkSelect();kill();\">
	                					                				<input type=\"checkbox\" name=\"v_selected[]\" id=\"v_selected_0\" value=\"9109629\" style=\"display:none;\">
	                					                		</td>";
																if($i % $maxItemsPerRow == 0) {
            // Insert row break
            echo "</tr><tr>";
        }
        $i++;

}
}
}
	}


?>

Link to comment
https://forums.phpfreaks.com/topic/158419-foreach-help/#findComment-835480
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.