I'm really new at this after trying to move from ASP, can anyone help me. I'm reading from the database but keep getting stuck in an infinte loop or displaying nothing at all. I suspect the line:
while($rs = mysql_fetch_assoc($result)){
is to blame but don't know enough to be sure, the full code is:
<?php
// whatever your database is here, im assuming its an access db or something??
$db = mysql_connect("localhost", "plaz1_plaz", "mouse25"
;
// select database
mysql_select_db("plaz1_forums",$db);
// set SQL string
$sql = "SELECT DISTINCT (phpbb_posts.topic_id) AS topics FROM phpbb_posts INNER JOIN phpbb_posts_text ON phpbb_posts.post_id = phpbb_posts_text.post_id WHERE (((phpbb_posts.forum_id)=3))ORDER BY phpbb_posts.topic_id DESC LIMIT 7";
// put the recordset into a variable.
$result = mysql_query($sql ,$db) or die (mysql_error());
$rs = mysql_fetch_assoc($result);
// start output of records
while($rs = mysql_fetch_assoc($result)){
?>
<b></b>
<table width="550" border="1" cellspacing="2" cellpadding="4" bgcolor="#333333" bordercolor="#333333" align="center">
<tr>
<td bgcolor="#222233" height="10" bordercolor="#000000">
<p><b>
<?php
// construct 2nd SQL query
$sql2 = "SELECT phpbb_users.username, phpbb_posts.post_time, phpbb_posts_text.post_subject, phpbb_posts_text.post_text, phpbb_posts.topic_id ";
$sql2 = $sql2 . "FROM (phpbb_posts_text INNER JOIN phpbb_posts ON phpbb_posts_text.post_id = phpbb_posts.post_id) INNER JOIN phpbb_users ON phpbb_posts.poster_id = phpbb_users.user_id ";
$sql2 = $sql2 . "WHERE (((phpbb_posts.topic_id)=" . $rs["topics"] . "
)" ;
// put result into a variable
$result2 = mysql_query($sql2 ,$db) or die (mysql_error());
$rs2 = mysql_fetch_assoc($result2);
// print field from result set
echo $rs2["post_subject"];
?>
</b></p>
</td>
</tr>
<tr>
<td bgcolor="#666666" height="18" bordercolor="#000000">
<p align='right'>
<?php
// think this should show your date in 01-Jan-2003 format?
echo "Added on " . date("d-M-Y", $rs2["post_time"]) . " by " . $rs2["username"];
?></p>
<p align='justify'>
<?php
// this bit might not work, not sure how the VBCrLF should be handled
echo str_replace("VBCrLF", "<BR>", $rs2["post_text"]);
?>
</p>
<?php
// put topic id into a variable? is this needed?
$topicid = $rs2["topic_id"];
// set third SQL statement
$sql3 = "Select COUNT(post_id) as comments from phpbb_posts where topic_id =" . $rs["topics"];
// put result of third query into variable
$result3 = mysql_query($sql3 ,$db) or die (mysql_error());
$rs3 = mysql_fetch_assoc($result3);
// print link to page (doesnt have an end </a> tag btw)
echo "<p align='right'><b><a href=' . $topicid . "' target='_parent'>" . intval($rs3["comments"]-1) . " comments...";
?>
</td>
</tr>
</table>
<br>
<?php
// end of 1st record set output loop
}
?>
-GTM Consult, Home of USITE-
-=
while($rs = mysql_fetch_assoc($result)){
is to blame but don't know enough to be sure, the full code is:
<?php
// whatever your database is here, im assuming its an access db or something??
$db = mysql_connect("localhost", "plaz1_plaz", "mouse25"

// select database
mysql_select_db("plaz1_forums",$db);
// set SQL string
$sql = "SELECT DISTINCT (phpbb_posts.topic_id) AS topics FROM phpbb_posts INNER JOIN phpbb_posts_text ON phpbb_posts.post_id = phpbb_posts_text.post_id WHERE (((phpbb_posts.forum_id)=3))ORDER BY phpbb_posts.topic_id DESC LIMIT 7";
// put the recordset into a variable.
$result = mysql_query($sql ,$db) or die (mysql_error());
$rs = mysql_fetch_assoc($result);
// start output of records
while($rs = mysql_fetch_assoc($result)){
?>
<b></b>
<table width="550" border="1" cellspacing="2" cellpadding="4" bgcolor="#333333" bordercolor="#333333" align="center">
<tr>
<td bgcolor="#222233" height="10" bordercolor="#000000">
<p><b>
<?php
// construct 2nd SQL query
$sql2 = "SELECT phpbb_users.username, phpbb_posts.post_time, phpbb_posts_text.post_subject, phpbb_posts_text.post_text, phpbb_posts.topic_id ";
$sql2 = $sql2 . "FROM (phpbb_posts_text INNER JOIN phpbb_posts ON phpbb_posts_text.post_id = phpbb_posts.post_id) INNER JOIN phpbb_users ON phpbb_posts.poster_id = phpbb_users.user_id ";
$sql2 = $sql2 . "WHERE (((phpbb_posts.topic_id)=" . $rs["topics"] . "

// put result into a variable
$result2 = mysql_query($sql2 ,$db) or die (mysql_error());
$rs2 = mysql_fetch_assoc($result2);
// print field from result set
echo $rs2["post_subject"];
?>
</b></p>
</td>
</tr>
<tr>
<td bgcolor="#666666" height="18" bordercolor="#000000">
<p align='right'>
<?php
// think this should show your date in 01-Jan-2003 format?
echo "Added on " . date("d-M-Y", $rs2["post_time"]) . " by " . $rs2["username"];
?></p>
<p align='justify'>
<?php
// this bit might not work, not sure how the VBCrLF should be handled
echo str_replace("VBCrLF", "<BR>", $rs2["post_text"]);
?>
</p>
<?php
// put topic id into a variable? is this needed?
$topicid = $rs2["topic_id"];
// set third SQL statement
$sql3 = "Select COUNT(post_id) as comments from phpbb_posts where topic_id =" . $rs["topics"];
// put result of third query into variable
$result3 = mysql_query($sql3 ,$db) or die (mysql_error());
$rs3 = mysql_fetch_assoc($result3);
// print link to page (doesnt have an end </a> tag btw)
echo "<p align='right'><b><a href=' . $topicid . "' target='_parent'>" . intval($rs3["comments"]-1) . " comments...";
?>
</td>
</tr>
</table>
<br>
<?php
// end of 1st record set output loop
}
?>
-GTM Consult, Home of USITE-
-=