PDA

View Full Version : seemingly simple PHP problem


Dunc
20-07-2003, 22:25
I've written a small php script to change the banner ad on my site each time you refresh.
It does it by picking the picture location and link from a mySQL database, then echo the required HTML to display it.

$dbUserID="root";
$dbUserPassword="";
$dbServer="localhost";
$dbName="ads";
$ads_displayed = 1;
$conn = mysql_connect($dbServer,$dbUserID, $dbUserPassword) or die("Unable to connect to SQL server");
$db = mysql_select_db($dbName, $conn) or die("Unable to select database");
$query = "SELECT * FROM ads WHERE site = '$SERVER_NAME' ORDER BY RAND() LIMIT $ads_displayed";
$result = mysql_query($query, $conn);
while ($row = mysql_fetch_assoc($result)) {
$pic = ($row["url"]);}
echo $pic

That works fine, and you can see it working here (http://dunc.dyndns.org/xmb/banner.php).

If you view the source you can se what is being echo'd.

however, i'm trying to get this to display in an html page without much success. It seems a simple thing to do but it just wont work.

anyone?

abe
20-07-2003, 22:46
You mean in a document parsing as html? I think you really have to p**** the document as php.

You could try putting that script in a file (as it is now) and using html includes.

<!--#include virtual="banner.php" -->

Any use?

TazUk
20-07-2003, 23:10
Yep it needs to be in a .php file for it to be executed. Just add it into a standard html file and then rename it to .php ;)

Elad
23-07-2003, 21:35
Yeah like Tazuk said... Also PHP includes are:

<?php include(whatever.php); ?>

Dunc
23-07-2003, 21:37
problem sorted now :)