Forum Moderators: coopster

Message Too Old, No Replies

Getting Info from a Database!

I`m in all sorts of problems....

         

dreamcatcher

8:51 pm on May 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi guys,

I`ve set up a database to hold some site info and I want to retrieve it and display it on a page. In this case, its a header option of a text description or a banner.

I`ve created a INT field called h_banner which holds the value 0 or 1, 1 for a banner, 0 for no banner. Then I`ve added some more fields to hold the banner width, height, and the text description if the h_banner field is set to 0 (false).

I`ve then done a function for the header as follows:

function guestbookHeader() {

$query = "SELECT * FROM mg_website";
$result = mysql_query($query) or die ("Error connecting to database.");

while ($row = mysql_fetch_array($result));

{

if ($row['h_banner'] == false)

{

echo "<html><head>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">";
echo "<title>$row['w_name'] Guestbook</title>";
include ("styles.php");
echo "</head>";
echo "<body>";
echo "<p align=\"center\">$row['h_text']</p>";
echo "<br>";

}

else

{

echo "<html><head>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">";
echo "<title>$row['w_name'] Guestbook</title>";
include ("styles.php");
echo "</head>";
echo "<body>";
echo "<p align=\"center\"><img src=\"$row['h_bannerurl']\" width=\"$row['h_bannerwidth']\" height=\"$row['h_bannerheight']\" border=\"0\">";
echo "<br>";

}

}

}

Now basically it doesn`t work. At the moment I`m getting T_STRING errors, but if I correct those, still nothing appears on the page. Neither a text link or a banner. As you can see I`m doing a guestbook script. Well, trying too.

I`m not really sure on the database info.

Any help would be appreciated, thank you.

:)

jatar_k

8:54 pm on May 17, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



first problem

while ($row = mysql_fetch_array($result));

there should be no semi colon at the end

jatar_k

9:01 pm on May 17, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Does the query only generate a single result?

If not then you will be outputting your <html><head> etc once for each row there is.

dreamcatcher

9:11 pm on May 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks very much for the help jatar_k, I`m ok now, it was the semi colon that was the problem. Phew, and to think I`ve been sitting here for nearly 3 hours scratching my head!

Thanks again!

:)