Page 1 of 1

message board problem

Posted: Mon Nov 14, 2005 2:17 pm
by kristie380
Ok I know I'm missing something small in here but I just can't figure out what it is. I am trying to dispaly the topics posted in my message board but I'm not getting anything. Here is my php code:

Code: Select all

<? php
$conn = mysql_connect("mysql", "*****", "*****") or die(mysql_error());
mysql_select_db("alumni",$conn) or die(mysql_error());

$get_topics = "SELECT `topic_id`, `topic_title`, date_format(topic_create_time, '%b %e %Y at %r') as fmt_topic_create_time, `topic_owner` FROM `forum_topics` ORDER BY `topic_create_time` DESC";

$get_topics_res = mysql_query($get_topics,$conn) or die(mysql_error());

if (mysql_num_rows($get_topics_res) < 1) {
$display_block = "<table width=\"790px\"><tr><td align=\"center\"><p><font size=\"4\">No topics exist</font></p></td></tr></table>";

} else {

$display_block = "<table width=\"790px\" cellpadding=\"3\" cellspacing=\"1\"><tr><td width=\"80%\"><p><font size=\"4\">TOPIC TITLE</td><td width=\"20%\"># OF POSTS</td></tr>";

while ($topic_info = mysql_fetch_array($get_topics_res)) {

$topic_id = $topic_info['topic_id'];
$topic_title = stripslashes($topic_info['topic_title']);
$topic_create_time = $topic_info['fmt_topic_create_time'];
$topic_owner = stripslashes($topic_info['topic_owner']);

$get_num_posts = "SELECT count(post_id) FROM `forum_posts` WHERE `topic_id` = $topic_id";
$get_num_posts_res = mysql_query($get_num_posts,$conn) or die(mysql_error());
$num_posts = mysql_result($get_num_posts_res,0,'count(post_id)');

$display_block .= "<tr><td width=\"80%\"><a href=\"showtopic.php?topic_id=$topic_id\"><b>$topic_title</b></a><br>Created on $topic_create_time by $topic_owner</td><td width=\"20%\" align=\"center\">$num_posts</td></tr>";
}
$display_block .= "</table>";
}

?>
<html>
<head>
        
 <title>Untitled</title>

</head>
<body text="#006633">

<?php echo "$display_block"; ?>

<p><a href="addtopic.htm">Add A Topic</a></p>
</body>
</html>

Can someone see what I'm missing?



Hawleyjr Edit: Username/Password removed.

Posted: Mon Nov 14, 2005 2:45 pm
by ambivalent
I think you need to echo stuff as you loop through it. The db results are only being assigned to variables.

Posted: Mon Nov 14, 2005 2:53 pm
by Nathaniel
ambivalent, he echo's his $display_block variable at the end, there.

Posted: Mon Nov 14, 2005 2:54 pm
by Ambush Commander
No, he is echoing it.

Remove the space between < and ?php (this should be causing the script to echo your source). Give us more information on what the script outputs too.

Posted: Mon Nov 14, 2005 2:56 pm
by kristie380
Ok I re-organized it like this and it is still not working:

Code: Select all

<? php
$conn = mysql_connect("mysql", "*******", "*******") or die(mysql_error());
mysql_select_db("alumni",$conn) or die(mysql_error());

$get_topics = "SELECT `topic_id`, `topic_title`, `date_format(topic_create_time, '%b %e %Y at %r') as fmt_topic_create_time`, `topic_owner` FROM `forum_topics` ORDER BY `topic_create_time` DESC";

$get_topics_res = mysql_query($get_topics,$conn) or die(mysql_error());

while ($topic_info = mysql_fetch_array($get_topics_res)) {

$topic_id = $topic_info['topic_id'];
$topic_title = stripslashes($topic_info['topic_title']);
$topic_create_time = $topic_info['fmt_topic_create_time'];
$topic_owner = stripslashes($topic_info['topic_owner']);

$get_num_posts = "SELECT `count(post_id)` FROM `forum_posts` WHERE `topic_id` = $topic_id";
$get_num_posts_res = mysql_query($get_num_posts,$conn) or die(mysql_error());
$num_posts = mysql_result($get_num_posts_res,0,'count(post_id)');

if (mysql_num_rows($get_topics_res) < 1) {
echo "<table width=\"790px\"><tr><td align=\"center\"><p><font size=\"4\">No topics exist</font></p></td></tr></table>";

} else {

echo "<table width=\"790px\" cellpadding=\"3\" cellspacing=\"1\"><tr><td width=\"80%\"><p><font size=\"4\">TOPIC TITLE</td><td width=\"20%\"># OF POSTS</td></tr>";

echo "<tr><td width=\"80%\"><a href=\"showtopic.php?topic_id=$topic_id\"><b>$topic_title</b></a><br>Created on $topic_create_time by $topic_owner</td><td width=\"20%\" align=\"center\">$num_posts</td></tr>";
}
echo "</table>";
}

?>
oh and by the way...I'm a she :)


Username & Password removed...

Posted: Mon Nov 14, 2005 2:57 pm
by ody
try changing:

while ($topic_info = mysql_fetch_array($get_topics_res))

to use mysql_fetch_assoc as you are accessing $topic_info in an associative mannner.

Posted: Mon Nov 14, 2005 2:58 pm
by kristie380
still nothing - i'm just getting no output at all...a blank screen

Posted: Mon Nov 14, 2005 2:58 pm
by Ambush Commander
Sorry, should have read your sn.

You still haven't fixed the space between < and ?php

Code: Select all

<?php
$conn = mysql_connect("mysql", "****", "****") or die(mysql_error());
mysql_select_db("alumni",$conn) or die(mysql_error());
Edit - Ack, and stop posting your user/pass!

Posted: Mon Nov 14, 2005 2:59 pm
by ambivalent
Nathaniel wrote:ambivalent, he echo's his $display_block variable at the end, there.
woops....missed that

Posted: Mon Nov 14, 2005 3:08 pm
by ody
You have back ticks around your entire column definition, you should only have the ticks around the column name `fmt_topic_create_time`.

copy and paste this to see if it works.

$get_topics = "SELECT `topic_id`, `topic_title`, date_format(topic_create_time, '%b %e %Y at %r') as `fmt_topic_create_time`, `topic_owner` FROM `forum_topics` ORDER BY `topic_create_time` DESC";

Posted: Mon Nov 14, 2005 3:13 pm
by kristie380
problem solved...thanks!

Posted: Mon Nov 14, 2005 3:15 pm
by Ambush Commander
Now, if you had just posted that there was an SQL error in your script... :roll:

Posted: Mon Nov 14, 2005 3:16 pm
by Nathaniel
The odd thing is, he should have gotten the error output with his die(mysql_error()) call, instead of a blank screen.