Forum Moderators: coopster
In my script I extract these lines using the fgets function and insert them into the database like so:
$handle = fopen("/home/mytext.txt", "r");
while (!feof($handle))
{
$buffer = fgets($handle);
$insertData = mysql_query("INSERT INTO Address (page, result) VALUES ('$buffer', '0')") or die(mysql_error());
}//end while
Now I would like to open all these sites in new windows using javascript like so:
$getUrl = mysql_query("SELECT page FROM Address Where pageId BETWEEN '1' and '12' ");
$url = mysql_fetch_array($getUrl);
while ($url)
{
$newPage = $url[page];
echo "<script language = \"javascript\">
<!--
window.open('$newPage');
// -->
echo </script>";
$url = mysql_fetch_array($getUrl);
}//end while
However, the windows do not open and the page source for the javascript keeps coming up funny. It looks like this:
<script language =" javascript">
<!--
window.open('http://www.google.com/
');
// -->
echo </script>
What is the problem here? I'm thinking its some type of newline or something but I'm not sure. I've tried removing the last element in the string (and a few other tricks) but that has done nothing....Is fgets doing something I'm not aware of?
--Nick
$newPage = trim($url["page"]);
;)
Additionally, if you want to create window.open statments for all the URLs in the database, your looping code is wrong. You want
while($url= mysql_fetch_array($getUrl)){...} Finally, if you download one of the Mozilla browsers (Firefox, etc.), you can use the built in Javascript console to catch errors in your javascript. In the current Firfox release this feature is under Tools -> Javascript Console