mysql query...need expert advice

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

mysql query...need expert advice

Post by scarface222 »

Ok let me try to word my last problem in a simpler manner.

this function determines the number of active users viewing each topic

Code: Select all

 
function usersCount1($pgcod,$topic_id)
{
$qryuserscount="SELECT * FROM scrusersonline WHERE usersonlineusrip!='1' AND id!='0' AND topic_id='$topic_id'";
$userscount=mysql_query($qryuserscount);
 
$count = mysql_num_rows($userscount);
return("$count");
}
This query displays the topic and its information, notice the function from the first query is used to display the number of users viewing each page in the while statement

Code: Select all

$sql="SELECT * FROM topic ORDER BY user_number DESC LIMIT $start, $limit";
while($row = mysql_fetch_array($result))
        {
echo usersOnline(1,$topic_id);
}
I want to delete the field 'user_number' used in the second query and somehow order the information instead by the variable $userscount determined by the external query since it displays the same information. Is this in anyway possible? (to order mysql query by external information?) PS both tables share the field topic_id.
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: mysql query...need expert advice

Post by scarface222 »

I tried something like this with no luck but I am getting closer. Each time a user enters a topic, an entry is put into the table scrusersonline. The number of users per topic is thus a count of the number of entries for that topic_id. What I tried to do was see which topic has the biggest count by counting the entries per topic_id (id for each topic) which I thought could be accomplished by a group command and counting each entry 'id' which is unique for every entry. I tried to order it by that id count with no luck. Let me know if anyone knows the correct syntax, or if this can even be done. Thanks in advance.

Code: Select all

 
$qryuserscount2="SELECT * FROM scrusersonline WHERE usersonlineusrip!='1' AND id!='0' GROUP BY topic_id ORDER BY COUNT(id) DESC";
        while($row = mysql_fetch_array($qryuserscount2))
        {
            $topic_id=$row['topic_id'];
    $sql="SELECT * FROM topic ORDER BY user_number DESC LIMIT $start, $limit";
        }
jacksonp
Forum Newbie
Posts: 3
Joined: Thu Feb 11, 2010 3:45 am

Re: mysql query...need expert advice

Post by jacksonp »

Hi all,
Thanks to useful guidelines post
I have a minor problem that I can't work out (and to add insult to injury, it'll probably be bleeding obvious too!).
I'm used to setting a cookie for domains, i.e it becomes '.domain.tld' in the setcookie() function. However, I've just ported this app over to my Ubuntu Server at home, and whatever I change the domain too, it just won't work! I've tried .web and web (it's server name internally) as well as it's IP. Currently, the only way I can get it to work is by forgetting about defining a domain part. Is this the only way, or what is the bleeding obvious I'm missing?
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: mysql query...need expert advice

Post by scarface222 »

LMAO why the <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> are you posting questions of your own that aren't even related in my topic JACKSONP haha. Create a new topic bro. Figure out how to use a forum before you start posting stuff or even think about coding in php hahaha, you might hurt yourself.
Last edited by scarface222 on Fri Feb 12, 2010 12:31 am, edited 1 time in total.
Post Reply