Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Php problem displaying variables

Status
Not open for further replies.

rninja

Technical User
Apr 11, 2001
381
0
0
US
I have been running over the code time and time again, and I cannot seem to find the culprit. The other topic_title variable comes up fine, but the others post_title, post_text do not. I have tried many things and they are still not showing up on the page...

I appreciate any help with this!

I figure the problem to be in this segment of code but I am not sure and have also included the entire code for perusal.

// Gather the posts
$get_posts = "select post_text, post_id, date_format(post_create_time, '%b %e %Y at %r')
as fmt_post_create_time, post_owner from Faq_Posts where topic_id = $_GET[topic_id] order by post_create_time asc";
$get_posts_res = mysql_query($get_posts,$conn) or die(mysql_error());

// Create the display string
$display_block = &quot;<p>Showing answer to the <b>$topic_title</b> topic:</p>
<table width=\&quot;100%\&quot; cellpadding=3 cellspacing=1 border=0><tr><th>Author</th><th>Post</th></tr>&quot;;

while($posts_info = mysql_fetch_array($get_posts_res)){
$post_id = $posts_info['post_id'];
$post_text = nl2br(stripslashes($posts_info['post_text']));
$post_create_time = $posts_info['fmt_post_create_time'];
$post_owner = stripslashes($posts_info['post_owner']);


:::::::::::::::::::FULL CODE BELOW:::::::::::::::::::::

<?php

// Check for required info from the query string
if(!$_GET[topic_id]){
header(&quot;Location: topiclist.php&quot;);
exit;
}

// Connect to DB
include('dbconf.php');

// Verify the topic exists
$verify_topic = &quot;select topic_title from Faq_Topics where topic_id = $_GET[topic_id]&quot;;
$verify_topic_res = mysql_query($verify_topic,$conn) or die(mysql_error());

if(mysql_num_rows($verify_topic_res) < 1){
// This topic does not exist
$display_block = &quot;<p><b>You have selected an invalid topic</b>. Please <a href=\&quot;topiclist.php\&quot;> Try
again</a>.</p>&quot;;
}else{

// Get topic title
$topic_title = stripslashes(mysql_result($verify_topic_res,0,'topic_title'));

// Gather the posts
$get_posts = &quot;select post_text, post_id, date_format(post_create_time, '%b %e %Y at %r')
as fmt_post_create_time, post_owner from Faq_Posts where topic_id = $_GET[topic_id] order by post_create_time asc&quot;;
$get_posts_res = mysql_query($get_posts,$conn) or die(mysql_error());

// Create the display string
$display_block = &quot;<p>Showing answer to the <b>$topic_title</b> topic:</p>
<table width=\&quot;100%\&quot; cellpadding=3 cellspacing=1 border=0><tr><th>Author</th><th>Post</th></tr>&quot;;

while($posts_info = mysql_fetch_array($get_posts_res)){
$post_id = $posts_info['post_id'];
$post_text = nl2br(stripslashes($posts_info['post_text']));
$post_create_time = $posts_info['fmt_post_create_time'];
$post_owner = stripslashes($posts_info['post_owner']);

// Add to display
$display_block .= &quot;<tr><td width=35% valign=top>$post_owner<br>[$post_create_time]</td>
<td width=65% valign=top>$post_text<br></td></tr>&quot;;
}

// Close up the table
$display_block .=&quot;</table>&quot;;
}
?>

<html>
<head>
<title>Posted FAQ Answers</title>
</head>
<body>
<h3>Posted Answers in Topic</h3>
<?php print $display_block; ?>
<br><br>
<a href=&quot;topiclist.php&quot;>Return to topic list</a>
<body>
</html>


Rninja

smlogo.gif

 
About line 11 :

Code:
from Faq_Topics where topic_id = $_GET[topic_id]&quot;;

$_GET[topic_id] - you should always use quotes around an associative array index. As it is, it is an undefined constant, and has to be evaluated to a string value. It's POSSIBLE that it isn't evaluating correctly in your SQL statement.

BTW -

Are you sure you are getting a result from your query? Just to check, insert an echo line before your table, like:

Code:
$rowsreturned = mysql_num_rows(get_posts_res);
echo &quot;Rows returned from query - $rowsreturned&quot;;

That'll tell you if you're even getting back usable info from your query in the first place.
 
Thank you for your assistance, but the code was fine, it turned out to be a mysql/php issue wherby one of the table fields is not updated when a new post is submitted. instead of assigning the id the same id as the title table, it makes the id field a &quot;0&quot;, and I am getting impatient!!!

lol

Thanks

Rninja

smlogo.gif

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top