Hi,
Okay, so I now have a while loop which will pull the <title> from the HTML for every URL and print it. However, I can't add an "update" query to the loop without either "Parse Errors" or some kind of "expecting 'T-STRING' in line x" error.
This one works fine, the one below doesn't:
<?php
# First script, this one works
require_once("/prod/scritch/apache/phpincludes/mysql.inc");
# Pull in the link_url from the database
$query = "select link_url from links where link_id between 10 and 20";
$query_db = @mysql_query($query, $db_connection);
$row = @mysql_fetch_object($query_db);
# Pull the title for each URL
while ($row=mysql_fetch_array($query_db)) {
$fp = fopen($row["link_url"], "r");
if ($fp) {
// grab the TITLE from the URL
while(!feof($fp)) {
if(preg_match('/<title>([^<]*)<\/title>/i', fgets($fp, 1024), $matches)) {
$urltitle = substr($matches[1],0,40);
# Print each URL
echo "URL = <b>".$row["link_url"]."</b> and Title = <b>".$urltitle."</b><br>";
break;
}
}
fclose($fp);
}
else {
echo "URL = <b>".$row["link_url"]."</b> and Title = <b>irretrievable</b><br>";
}
}
?>
However, as soon as I add something to update the database, I get errors like:
PHP Parse error: parse error, expecting T_STRING' orT_VARIABLE' or `T_NUM_STRING' in bla/bla/bla/xxx.php on line 21
This is the script:
<?php
# Second script, this one does not work
require_once("/prod/scritch/apache/phpincludes/mysql.inc");
# Pull in the link_url from the database
$query = "select link_url from links where link_id between 10 and 20";
$query_db = @mysql_query($query, $db_connection);
$row = @mysql_fetch_object($query_db);
# Pull the title for each URL
while ($row=mysql_fetch_array($query_db)) {
$fp = fopen($row["link_url"], "r");
if ($fp) {
// grab the TITLE from the URL
while(!feof($fp)) {
if(preg_match('/<title>([^<]*)<\/title>/i', fgets($fp, 1024), $matches)) {
$urltitle = substr($matches[1],0,40);
# Print each URL to the screen
echo "URL = <b>".$row["link_url"]."</b> and Title = <b>".$urltitle."</b><br>";
$query2 = "update links set link_title='$urltitle' where link_url='$row["link_url"]'";
$query_db2=@mysql_query($query2, $db_connection) or die("Could not run SQL query");
# If the query works, then say so
if ($query_db2) {
echo "Your title has been added successfully to URL $row["link_url"].<br>";
} else {
echo "ERROR. There was some problem with adding the URL.<br>";
}
*/
break;
}
}
fclose($fp);
}
else {
echo "URL = <b>".$row["link_url"]."</b> and Title = <b>irretrievable</b><br>";
}
}
?>
Can anyone help me out in what's wrong with my update statement inside the loop?
Thanks in advance!!!
Sam