I’m trying to grab some data off of a list of webpages and display it to the page. The list of urls are from a mysql table and I then use the curl function to grab the data. The only problem is that I only get the first row.
Can anyone please tell me what I am doing wrong? mysql_num_rows displays 86 rows and when I substitute the $row variable from the mysql_fetch_row with an array I built with all of the urls and put that into the foreach statement it works fine but, of course, I would rather get the urls from mysql.
Here is the code:
$query = "select website from vtiger_account where website <> ''";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
echo $num_rows . ' rows found<br />';
echo '<table border ="1">
<th>District</th><th>Version</th>';
while ($row = mysql_fetch_row($result))
{
foreach ($row as $url)
{
echo '<tr><td>'.$url.'</td>';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
$data = curl_exec ($ch);
curl_close ($ch);
$length=strpos($data,"Version: ");
$result=substr($data,$length +9,32);
if (preg_match("/Version:/", $data))
{
echo '<td>'.$result . '</td></tr>';
}
else
{
echo '<td>No version found</td></tr>';
}
}
}
echo '</table>';