Jump to content

executing the query once


php_begins

Recommended Posts

I have the following query where $userid is about 100,000 userids separated by commas.

 

<?
$getpostid=mysql_query("SELECT DISTINCT post.username,post.threadid,thread.threadid,thread.forumid from post,thread WHERE post.username='$username' AND post.threadid=thread.threadid AND post.userid IN ($userid) AND thread.forumid IN ($forumids)") or die (mysql_error());
?>

can i just print all the usernames from above result separated by ';' without looping it multiple times?

 

Could someone help me out how to do above in an efficient manner?

Link to comment
https://forums.phpfreaks.com/topic/252064-executing-the-query-once/
Share on other sites

    I need to see if the user has posted at least 1 post in one of these forums; 12, 9, 96, 176

    and last activity is more then six months ago, meaning they have not logged in within the last 6 months. and then print those usernames

  Given current table structure of post,thread,user and forum. This is the only way i could think of so far.Here is my complete code:

 

$forumids='12,9,96,176';
$getusername=mysql_query("SELECT userid from user WHERE posts >=1 AND lastactivity <='$newDate' ORDER by lastactivity") or die (mysql_error());
if(mysql_num_rows($getusername) > 0)
{
   $flag=1;
   while($getusername_result=mysql_fetch_assoc($getusername))
   {
      if($flag == 1)
      {
         $userid=$getusername_result['userid'];
         $flag=2;
      }
      else
      {
         $userid.=",".$getusername_result['userid'];
      }
   }
}
else
{
  //Nothin
}
echo $userid;
      //$getpostid=mysql_query("SELECT DISTINCT post.username,post.threadid,thread.threadid,thread.forumid from post,thread WHERE post.username='$username' AND post.threadid=thread.threadid AND post.userid IN ($userid) AND thread.forumid IN ($forumids)") or die (mysql_error());
      while($getpostid_result=mysql_fetch_assoc($getpostid))
      {

         $postusername=$getpostid_result['username'];
         echo $postusername."<br>";

      }


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.