try this:

$resultb = mysql_query("SELECT bt_message.id, bt_message.title,
bt_message.mid,
bt_message.lastedit, bt_message.hit, bt_message.reply, bt_message.`lock`,
bt_member.nick
FROM bt_message, bt_member WHERE bt_member.id=bt_message.mid ch='$ch'
ORDER BY bt_message.top,bt_message.lastedit DESC LIMIT $limit,30",$db);
while ($result = mysql_fetch_array($resultb)) {
        ..........
}

If field names are explicit (ie, only in one table), you can get away
without specifying
the table name (as in "SELECT title, mid,...") but be carefull with that -
from your
original example, I see you have field 'id' in both tables...

I would suggest taking a look at the mysql manual at the select & join
sections...


James


-----Original Message-----
From: Erick [mailto:[EMAIL PROTECTED]
Sent: 04 June 2003 14:45
To: [EMAIL PROTECTED]
Subject: Re: [PHP] How to optimize this MySQL command?


So, how about this?

$resultb = mysql_query("SELECT id,title,mid,lastedit,hit,reply,`lock` FROM
bt_message where ch='$ch' ORDER BY top,lastedit DESC LIMIT $limit,30",$db);
while ($result = mysql_fetch_array($resultb)) {
$result2b = mysql_query("SELECT nick FROM bt_member where id
='$result[mid]'",$db);
$result2 = mysql_fetch_array($result2b);
mysql_free_result($result2b);
..........
}

-- 

"James Lobley" <[EMAIL PROTECTED]>
???????:[EMAIL PROTECTED]
> I'd guess at:
>
> $resultb = mysql_query("SELECT bt_member.nick FROM bt_member, bt_message
> WHERE bt_member.id=bt_message.mid AND bt_message.ch='$ch'", $db);
> $result2 = mysql_fetch_array($resultb);
> .........
>
>
> -----Original Message-----
> From: Erick [mailto:[EMAIL PROTECTED]
> Sent: 04 June 2003 13:12
> To: [EMAIL PROTECTED]
> Subject: [PHP] How to optimize this MySQL command?
>
>
> $resultb = mysql_query("SELECT id,mid FROM bt_message where ch='$ch'
",$db);
> while ($result = mysql_fetch_array($resultb)) {
> $result2b = mysql_query("SELECT nick FROM bt_member where id
='$result[mid]'
> ",$db);
> $result2 = mysql_fetch_array($result2b);
> .........
> }
>
> Can combine together?
>
>
>
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> This email is only intended for the person(s) to whom it is addressed and
> may contain confidential information.  Unless stated to the contrary, any
> opinions or comments are personal to the writer and do not represent the
> official view of the company.  If you have received this e-mail in error,
> please notify us immediately by reply e-mail and then delete this message
> from your system.  Please do not copy it or use if for any purposes, or
> disclose its contents to any other person.
>
> We make every effort to keep our network free from viruses. You should
> independently check this e-mail and any attachments for viruses, as we
> can take no responsibility for any computer viruses that might be
> transferred by way of this e-mail.
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


This email is only intended for the person(s) to whom it is addressed and
may contain confidential information.  Unless stated to the contrary, any
opinions or comments are personal to the writer and do not represent the
official view of the company.  If you have received this e-mail in error,
please notify us immediately by reply e-mail and then delete this message
from your system.  Please do not copy it or use if for any purposes, or
disclose its contents to any other person.

We make every effort to keep our network free from viruses. You should 
independently check this e-mail and any attachments for viruses, as we 
can take no responsibility for any computer viruses that might be 
transferred by way of this e-mail. 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to