Jump to content

how to pull the right data in my function


tomwi

Recommended Posts

hello everyone, this is my function...

 

WHERE forum_id = 1 limit 2(i changed this for forum_id=1 just to make it not error)

This is obviously pulling all the topics in forum_id 1 limited to 2 results.  What I want is for it to pull 2 of the forum topics in each forum_id... WHERE forum_id = forum_id doesn't seem to pull the right thing.

 

ex:

forum1

-forum1 topic 1

-forum1 topic 2

forum2

-forum2 topic 1

-forum2 topic 2

etc...

 

how would I do that?

 

 

 

function wp_bb_get_discuss_test() {
global $table_prefix,$wpdb;
$forum_slimit = get_option('wpbb_limit');

if (get_option('wpbb_exdb')) {
	$exbbdb = new wpdb(get_option('wpbb_dbuser'), get_option('wpbb_dbpass'), get_option('wpbb_dbname'), get_option('wpbb_dbhost'));
	$bbforum_test = $exbbdb->get_results("SELECT * FROM ".get_option('wpbb_bbprefix')."forums WHERE forum_parent = 0 ORDER BY forum_order");
}
else {
	$bbforum_test = $wpdb->get_results("SELECT * FROM ".get_option('wpbb_bbprefix')."forums WHERE forum_parent = 0 ORDER BY forum_order");
}
if ($bbforum_test) {
	echo '
		<div id="discussions">
		<table id="latest">
	';
	foreach ( $bbforum_test as $bbforum_test ) {
		$forum_text = wpbb_trim($bbforum_test->forum_name, get_option('wpbb_slimit'));
		echo "
			<tr class=\"alt\">
		";
		if (get_option('wpbb_permalink')) {
			echo '<td><a href="' . get_option('wpbb_path') . '/topic/' . $bbforum->forum_id . '"><h3>' . __("$forum_text") . '</h3></a></td>';
		}
		else {
			echo '<td><a href="' . get_option('wpbb_path') . '/forum.php?id=' . $bbforum_test->forum_id . '"><h3>' . __("$forum_text") . '</h3></a></td>';
		}

		echo "
			</tr>
		";

if (get_option('wpbb_exdb')) {
	$exbbdb = new wpdb(get_option('wpbb_dbuser'), get_option('wpbb_dbpass'), get_option('wpbb_dbname'), get_option('wpbb_dbhost'));
	$bbtopic = $exbbdb->get_results("SELECT * FROM ".get_option('wpbb_bbprefix')."topics WHERE forum_id = 1 AND topic_status = 0 ORDER BY topic_time DESC LIMIT 2");
}
else {
	$bbtopic = $wpdb->get_results("SELECT * FROM ".get_option('wpbb_bbprefix')."topics WHERE forum_id = 1 AND topic_status = 0 ORDER BY topic_time DESC LIMIT 2");
}


	foreach ( $bbtopic as $bbtopic ) {
		$title_text = wpbb_trim($bbtopic->topic_title, get_option('wpbb_slimit'));
		echo "
			<tr class=\"alt\">
		";
		if (get_option('wpbb_permalink')) {
			echo '<td><a href="' . get_option('wpbb_path') . '/topic/' . $bbtopic->topic_id . '">-' . __("$title_text") . '</a></td>';
		}
		else {
			echo '<td><a href="' . get_option('wpbb_path') . '/topic.php?id=' . $bbtopic->topic_id . '">-' . __("$title_text") . '</a></td>';
		}

		echo "
			</tr>
		";
	}


	}
	echo "</table></div>";
}
}

that makes sense, thanks for the help.  the code is long, but i believe all of it would be required to help.

 

 

function wp_bb_get_discuss_test() {
   global $table_prefix,$wpdb;
   $forum_slimit = get_option('wpbb_limit');

   if (get_option('wpbb_exdb')) {
      $exbbdb = new wpdb(get_option('wpbb_dbuser'), get_option('wpbb_dbpass'), get_option('wpbb_dbname'), get_option('wpbb_dbhost'));
      $bbforum_test = $exbbdb->get_results("SELECT * FROM ".get_option('wpbb_bbprefix')."forums WHERE forum_parent = 0 ORDER BY forum_order");
   }
   else {
      $bbforum_test = $wpdb->get_results("SELECT * FROM ".get_option('wpbb_bbprefix')."forums WHERE forum_parent = 0 ORDER BY forum_order");
   }
   if ($bbforum_test) {
      echo '
         <div id="discussions">
         <table id="latest">
      ';
      foreach ( $bbforum_test as $bbforum_test ) {
         $forum_text = wpbb_trim($bbforum_test->forum_name, get_option('wpbb_slimit'));
         echo "
            <tr class=\"alt\">
         ";
         if (get_option('wpbb_permalink')) {
            echo '<td><a href="' . get_option('wpbb_path') . '/topic/' . $bbforum->forum_id . '"><h3>' . __("$forum_text") . '</h3></a></td>';
         }
         else {
            echo '<td><a href="' . get_option('wpbb_path') . '/forum.php?id=' . $bbforum_test->forum_id . '"><h3>' . __("$forum_text") . '</h3></a></td>';
         }

         echo "
            </tr>
         ";

   if (get_option('wpbb_exdb')) {
      $exbbdb = new wpdb(get_option('wpbb_dbuser'), get_option('wpbb_dbpass'), get_option('wpbb_dbname'), get_option('wpbb_dbhost'));
      $bbtopic = $exbbdb->get_results("SELECT * FROM ".get_option('wpbb_bbprefix')."topics WHERE forum_id = 1 AND topic_status = 0 ORDER BY topic_time DESC LIMIT 2");
   }
   else {
      $bbtopic = $wpdb->get_results("SELECT * FROM ".get_option('wpbb_bbprefix')."topics WHERE forum_id = 1 AND topic_status = 0 ORDER BY topic_time DESC LIMIT 2");
   }


      foreach ( $bbtopic as $bbtopic ) {
         $title_text = wpbb_trim($bbtopic->topic_title, get_option('wpbb_slimit'));
         echo "
            <tr class=\"alt\">
         ";
         if (get_option('wpbb_permalink')) {
            echo '<td><a href="' . get_option('wpbb_path') . '/topic/' . $bbtopic->topic_id . '">-' . __("$title_text") . '</a></td>';
         }
         else {
            echo '<td><a href="' . get_option('wpbb_path') . '/topic.php?id=' . $bbtopic->topic_id . '">-' . __("$title_text") . '</a></td>';
         }

         echo "
            </tr>
         ";
      }


      }
      echo "</table></div>";
   }
} 

hi guys, let me try again.  can anyone help me change this from pulling forum_id=1 to pulling forum_id=forum_id of the forum pulling in the previous get_results  Thanks!!

 

   if (get_option('wpbb_exdb')) {
      $exbbdb = new wpdb(get_option('wpbb_dbuser'), get_option('wpbb_dbpass'), get_option('wpbb_dbname'), get_option('wpbb_dbhost'));
      $bbtopic = $exbbdb->get_results("SELECT * FROM ".get_option('wpbb_bbprefix')."topics WHERE forum_id = 1 AND topic_status = 0 ORDER BY topic_time DESC LIMIT 2");
   }
   else {
      $bbtopic = $wpdb->get_results("SELECT * FROM ".get_option('wpbb_bbprefix')."topics WHERE forum_id = 1 AND topic_status = 0 ORDER BY topic_time DESC LIMIT 2");
   }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.