Jump to content


Photo

is this possible?


  • This topic is locked This topic is locked
3 replies to this topic

#1 MrLarkins.com

MrLarkins.com
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 13 October 2006 - 01:31 PM

while($main = mysql_fetch_array($main)){
$id = $main['id'];
$name = $main['name'];
$email = $main['email'];

$icq = mysql_query("SELECT icq_number FROM ibf_member_extra WHERE id = $id");
$icq_number = $icq['icq_number'];

//then do html to display results
}

my question is about the mysql query within the while(), is this possible, or is there a better way?

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 13 October 2006 - 01:54 PM

Whats the query used before the while loop. You shoud use a join instead if the two tables you are querying relate.

If you use a join you dont need to do another (uneeded) query in the while loop.

#3 MrLarkins.com

MrLarkins.com
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 13 October 2006 - 01:58 PM

sorry, here is the full part

$main = mysql_query("SELECT id, name, email FROM ibf_members WHERE mgroup=4 ORDER BY id");
while($main = mysql_fetch_array($main)){ //while you have records available from the SELECT query
$id = $main['id'];
$name = $main['name'];
$email = $main['email'];

$icq = mysql_query("SELECT icq_number FROM ibf_member_extra WHERE id = $id");
$icq_number = $icq['icq_number'];

//then do html to display results
}

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 13 October 2006 - 02:19 PM

Prehaps use this as the query for $main:
SELECT m.id, m.name, m.email, me.icq_number
FROM ibf_members as m, ibf_members_extra as me WHERE m.mgroup=4, m.id = me.id ORDER BY m.id
It is untested however it should work.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users