Hi everyone. I'm getting confused with the syntax when php and javascript is put together on one page. I wonder if someone can help with this.
I have a file called pull.php with the following contents.
<script src="source.php" type="text/JavaScript"></script>
Then I have a file called source.php with the following contents:
<?
$adid=$_REQUEST ['adid'];
include ("db.php");
$query = "SELECT * FROM ads";
$columns = 2;
$result = mysql_query($query);
//we add this line because we need to know the number of rows
$num_rows = mysql_num_rows($result);
echo "<TABLE BORDER=\"1\">\n";
//changed this to a for loop so we can use the number of rows
for($i = 0; $i < $num_rows; $i++) {
$row = mysql_fetch_array($result);
if($i % $columns == 0) {
//if there is no remainder, we want to start a new row
echo "<TR>\n";
}
echo "<TD width='100' valign='top' height='100'><span class='adHeadline'>". $row['ad_url'] . "</span><br /> <span class='adText'>". $row['ad_text'] ."</span></TD>\n";
if(($i % $columns) == ($columns - 1) || ($i + 1) == $num_rows) {
//if there is a remainder of 1, end the row
//or if there is nothing left in our result set, end the row
echo "</TR>\n";
}
}
echo "</TABLE>\n";
?>
My problem is that I need to insert the javascript's document.write somewhere above but I'm not sure where or how to do it as the syntax is baffling me. The end result I want to achive is that if you call pull.php, the outputted html from source.php must display on pull.php. Everything I have tried has either displayed nothing on pull.php (even if source.php parses correctly) or I get a host of parse errors in source.php.
Can anybody help please?
Regards
Anwaraa
P/S: The php code above parses correctly as is.






Bookmarks