InNeedofHelp
06-02-2006, 07:59 PM
Hey DD,
I'm trying to create a forum page where i have a class in my PHP script so that any time i make something of that class and use Forum->Display(); it displays a table in which i would like to display the Forum title, number of topics, views, whatever, that's the idea. So my code retrieves the information from the database, and then in my class Forum function Display(), i want to be able to echo the variable containing the Forum title. But when inside the class function it won't let me echo that variable. Here's my code (the names of the functions and classes and whatnot is different):
<?php
$con = mysql_connect("localhost");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
$db = mysql_select_db("forum_db", $con);
if (!$db) {
$sql = "create database forum_db";
if (mysql_query($sql,$con)) {
$db = mysql_select_db("forum_db", $con);
}
}
$sql = "insert into Forums
(ForumTitle, NumTopics)
values
('General', 0)";
$allow = mysql_query($sql,$con);
if (!$allow) {
$sql = "CREATE TABLE Forums
(
ForumTitle varchar(25),
NumTopics int(5),
LastPerson varchar(25)
)";
$tab = mysql_query($sql,$con);
$sql = "insert into Forums
(ForumTitle, NumTopics)
values
('General', 0)";
$allow = mysql_query($sql,$con);
}
$result = mysql_query("SELECT * FROM Forums");
$row = mysql_fetch_array($result);
echo $row['ForumTitle'];
echo "<br>";
echo $row['NumTopics'];
echo "<br>";
class Tab {
function buildTable() {
echo "<table class='TopicDisplay' cellspacing=0>";
echo "<tr>";
echo "<td class='Indicator'>";
echo "<center>Content</center>";
echo "</td>";
echo "<td class='Topic'>";
echo "<center>" . $row['ForumTitle'] . "</center>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td class='Indicator'>";
echo "<center>Content</center>";
echo "</td>";
echo "<td class='Topic'>";
echo "<center>Content</center>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td class='Indicator'>";
echo "<center>Content</center>";
echo "</td>";
echo "<td class='Topic'>";
echo "<center>Content</center>";
echo "</td></tr></table>";
}
}
mysql_close();
?>
It doesn't echo anything in that first table row where i put the echo row variable. Any suggestions?
Thanks in advance.
I'm trying to create a forum page where i have a class in my PHP script so that any time i make something of that class and use Forum->Display(); it displays a table in which i would like to display the Forum title, number of topics, views, whatever, that's the idea. So my code retrieves the information from the database, and then in my class Forum function Display(), i want to be able to echo the variable containing the Forum title. But when inside the class function it won't let me echo that variable. Here's my code (the names of the functions and classes and whatnot is different):
<?php
$con = mysql_connect("localhost");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
$db = mysql_select_db("forum_db", $con);
if (!$db) {
$sql = "create database forum_db";
if (mysql_query($sql,$con)) {
$db = mysql_select_db("forum_db", $con);
}
}
$sql = "insert into Forums
(ForumTitle, NumTopics)
values
('General', 0)";
$allow = mysql_query($sql,$con);
if (!$allow) {
$sql = "CREATE TABLE Forums
(
ForumTitle varchar(25),
NumTopics int(5),
LastPerson varchar(25)
)";
$tab = mysql_query($sql,$con);
$sql = "insert into Forums
(ForumTitle, NumTopics)
values
('General', 0)";
$allow = mysql_query($sql,$con);
}
$result = mysql_query("SELECT * FROM Forums");
$row = mysql_fetch_array($result);
echo $row['ForumTitle'];
echo "<br>";
echo $row['NumTopics'];
echo "<br>";
class Tab {
function buildTable() {
echo "<table class='TopicDisplay' cellspacing=0>";
echo "<tr>";
echo "<td class='Indicator'>";
echo "<center>Content</center>";
echo "</td>";
echo "<td class='Topic'>";
echo "<center>" . $row['ForumTitle'] . "</center>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td class='Indicator'>";
echo "<center>Content</center>";
echo "</td>";
echo "<td class='Topic'>";
echo "<center>Content</center>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td class='Indicator'>";
echo "<center>Content</center>";
echo "</td>";
echo "<td class='Topic'>";
echo "<center>Content</center>";
echo "</td></tr></table>";
}
}
mysql_close();
?>
It doesn't echo anything in that first table row where i put the echo row variable. Any suggestions?
Thanks in advance.