RE: [PHP] How to optimize this MySQL command?

2003-06-05 Thread James Lobley
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



RE: [PHP] How to optimize this MySQL command?

2003-06-05 Thread PHP4 Emailer
Wouldn't it be easier to SELECT * from bt_member WHERE ch='$ch' 
id='$result[mid]',$db);
//I'm not sure of the exact syntax there since I'm a newbie, but wouldn't it
be easier to do that and then do a pulling of the fields that you want?
//ie...
while ($result = mysql_fetch_object($resultb)){
print TR\n;
print td width=90 valign=\top\$row-id/td\n;
print td width=90 valign=\top\$row-mid/td\n;
print td valign=\top\$row-nick/td\n;
print /tr\n;

}
print /Table\n;
print /Center\n;

I took this from an example that I have now for something similar, it uses
fetch_object, you could still use fetch_array, and just use a $row['id'] or
something too. Good luck with this, maybe someone who knows correct syntax
could clean this up a bit. I guess my opinion is that it slows the processor
down having to pull only certain fields from the database compared to just
pulling all of them from a certain table. Most tables shouldn't be that big,
if they are you should be using primary keys and making other tables that is
the point of a relational database. ;)  You can always join tables in the
end. (ramblin again!!, sigh)
Best of luck,
David

-Original Message-
From: Erick [mailto:[EMAIL PROTECTED]
Sent: Wednesday, June 04, 2003 7:12 AM
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



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



RE: [PHP] How to optimize this MySQL command?

2003-06-05 Thread PHP4 Emailer
YEAH, disregard my message, I was doing what James was doing but didn't see
that you where using 2 seperate tables already, sigh been a great
morning already. but there's my idea anyhow!!  hehe
David :)

-Original Message-
From: James Lobley [mailto:[EMAIL PROTECTED]
Sent: Wednesday, June 04, 2003 8:22 AM
To: 'Erick'; [EMAIL PROTECTED]
Subject: RE: [PHP] How to optimize this MySQL command?
Importance: High


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



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



Re: [PHP] How to optimize this MySQL command?

2003-06-05 Thread Erick
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



RE: [PHP] How to optimize this MySQL command?

2003-06-05 Thread James Lobley
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



Re: [PHP] How to optimize this MySQL command?

2003-06-05 Thread Sunil Samuel
This is actually more an sql questions. ;-)  Take a look at Joins in 
sql.  Should be something like the following:

SELECT mesg.id, mesg.mid, memb.nick
FROM bt_message mesg,  bt_member memb
WHERE mesg.ch='$ch' AND memb.id=mesg.mid
Erick wrote:

$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


Re: [PHP] How to optimize this MySQL command?

2003-06-04 Thread Jomi Garrucho
 try this if it works
SELECT nick FROM bt_member LEFT JOIN bt_message ON
bt_member.id=bt_message.mid WHERE bt_message.ch ='$ch'
- Original Message -
From: Sunil Samuel [EMAIL PROTECTED]
To: Erick [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Wednesday, June 04, 2003 11:09 PM
Subject: Re: [PHP] How to optimize this MySQL command?


 This is actually more an sql questions. ;-)  Take a look at Joins in
 sql.  Should be something like the following:

 SELECT mesg.id, mesg.mid, memb.nick
 FROM bt_message mesg,  bt_member memb
 WHERE mesg.ch='$ch' AND memb.id=mesg.mid

 Erick wrote:

 $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



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