PDA

View Full Version : Pulling a list of users based on a field in their profile.


jcroft
10 Dec 2001, 23:18
Ok, I'm trying to created a list of users who have data entered in their "field8" in the "userfield" table.

I did this:


require("/home/newbeetle/public_html/vbulliten/admin/config.php");

$db=mysql_connect($servername,$dbusername,$dbpassword);
mysql_select_db($dbname);

$query = "SELECT * FROM userfield WHERE field8 = ''";
$resultlatest = mysql_query($query,$db);

while ($latest_array = mysql_fetch_array($resultlatest)) {
echo "<A HREF=\"http://forums.newbeetle.org/member.php?action=getinfo&userid=$latest_array[userid]\">$latest_array[username]</A>
}


Now, the problem is that the field I need for the link, username, isn't IN the userfield table, it's in user. Well, I'm not familiar enough with SQL queries to figure out how I can get it to do this. I guess I need it to check for data in field8, then match those userids to userids in the user table, and pull out THOSE username.

Any help?

Thanks so much in advance!

Jeff Croft
NewBeetle.org

JamesUS
11 Dec 2001, 07:01
Change your query to this:

SELECT * FROM userfield LEFT JOIN user ON user.userid=userfield.userid WHERE userfield.field8='';

:)

jcroft
11 Dec 2001, 21:17
Thanks so much. That worked beautifully. :D