Getting Information

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
theanimewizard
Forum Newbie
Posts: 6
Joined: Thu Feb 19, 2004 9:15 pm

Getting Information

Post by theanimewizard »

Code: Select all

<?php
$getmembersno = explode(', ', $row['members']);
	$totalmembersno = count($getmembersno);
	for ($i = 0; $i < count($getmembersno); $i++) {

	$p1sql = "select user_id, user_class, user_clan from phpbb_users where username='$getmembersno[$i]'";
	if ( !($p1result = $db->sql_query($p1sql)) ) { message_die(GENERAL_MESSAGE, 'Fatal Error Getting User Info!'); }
	$p1row = mysql_fetch_array($p1result);
?>
How do get the data when $getmembers[] is 1, 2,3,4,5,6,7, etc...

Right now, when I use $p1row['user_id'], it only shows the data WHEN username="$getmembers[0]" ...

How do I get it when it's $getmembers[1] ?

do I use p1row['user_id'][1], I doubt it will work...
theanimewizard
Forum Newbie
Posts: 6
Joined: Thu Feb 19, 2004 9:15 pm

Post by theanimewizard »

help?
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

This might work for ya.

$p1sql = "select user_id, user_class, user_clan from phpbb_users where username in ($getmembersno[$i])";
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

<?php
$getmembersno = explode(', ', $row['members']);
$totalmembersno = count($getmembersno);
for ($i = 0; $i < count($getmembersno); $i++) {

$p1sql = "select user_id, user_class, user_clan from phpbb_users where username='$getmembersno[$i]'";
if ( !($p1result = $db->sql_query($p1sql)) ) { message_die(GENERAL_MESSAGE, 'Fatal Error Getting User Info!'); }
$p1row = mysql_fetch_array($p1result);
?>
Just looks all wrong to me :o Your trying to select users from a database who's usernames are all like 1, 2, 3 etc.. ? Sure that's not the user_id ?
You could just do something lie:

Code: Select all

$p1sql = "SELECT username, user_class, user_clan FROM phpbb_users WHERE FIND_IN_SET(user_id, '$getmembersno')";
$result = mysql_query($p1sql) or die(mysql_error());
while($row = mysql_fetch_assoc($result)){
    echo $row['username'].'<br />';
}
... unless i've totally misunderstood your question ;)
Post Reply