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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with PHP code

Status
Not open for further replies.

zrazzaq

MIS
Apr 13, 2005
102
US
Hi all:
I just took over a new position and learning PHP at my company. We have a forum and currently it list the topic or thread of the most recent thread answered. I need it to list out all the threads in the forum that are there period. How do I do this?
The current code is:(PS the person who wrote this is no longer with the company)...
Code:
$forum_sql="select forum_id from $tb_forums where forum_lock='y'";
$forum_qry=mysql_query($forum_sql) or die(mysql_error());
$forum_res_cnt=mysql_num_rows($forum_qry);
$fcnt=1;
while( $forum_res=mysql_fetch_array($forum_qry))
{
   $forum_res_qry.="forum_id<> ".$forum_res[0];
   if ($fcnt < $forum_res_cnt) { $forum_res_qry .=" and ";} 
   $fcnt++;
}
if ($forum_res_cnt>0) { $where=" where $forum_res_qry "; }

$sql = "
        select
                *
        from
                $tb_threads

	 $where 

        order by
                timestamp desc limit 0,$num_lastlog_image
";
$query = mysql_query($sql) or die(mysql_error());

$forum_topics = "<tr><td><table width=100%><tr>
			<td><br></td>
		 </tr>

		 <tr><td width=100%>
			<table border=1 width=100% cellspacing=0 cellpadding=0>
			    <tr><td class=s10 width=100% colspan=2>&nbsp;<b>Forum Topics</b></td></tr>
	                    <tr><td width=50%> <table border=0 width=100% cellspacing=0 cellpadding=0>
				";

while($array = mysql_fetch_array($query))
{

	$alt = $i % 2 ? "alt1" : "alt2";
	$i++;
	$thread_name = get_thread_name($array["thread_id"]);

	$forum_topics.="<tr><td class=s10 width=100%>&nbsp;
				<a href=\"$base_url/posts.php?t=$array[thread_id]\">$thread_name</a></td></tr>";
}


$forum_topics.="</table></td>
<td width=50%> <table border=0 width=100% cellspacing=0 cellpadding=0> ";
$sql = "
        select
                *
        from
                $tb_threads

        	  $where

        order by

                timestamp desc limit 10,10
";


$query = mysql_query($sql) or die(mysql_error());
while($array = mysql_fetch_array($query))
{

	$alt = $i % 2 ? "alt1" : "alt2";
	$i++;

	$thread_name = get_thread_name($array["thread_id"]);
	$forum_topics.="<tr><td class=s10 width=100%>&nbsp;
             				<a href=\"$base_url/posts.php?t=$array[thread_id]\">$thread_name</a></td></tr>";
}

$forum_topics .="</table> </td> </tr></table></td></tr>
		<tr><td><br></td></tr>
		";
Thanks
Z
 
I believe it just a metter of changing this query:

Code:
$sql = "
        select
                *
        from
                $tb_threads

     $where

        order by
                timestamp desc limit 0,$num_lastlog_image
";

To Select every record instead of specific ones, but as I don't know what your table structure looks like I'm not going to venture a query that might not work. You' have to find out how the DB is set up, and then just Issue a Standard select statement based on that.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top