bwcc Posted December 11, 2006 Share Posted December 11, 2006 Ok - I have this code thus far - the first query ($r_m) picks all users where the manage column equals a number. The WHILE statement puts the array into a dropdown list. What I want to do is then color-code the user names pending if they have a blank "adate" field. I hate to run a query in a WHILE statement, but I can't think of another way to run this right now - any help would be appreciated![code]$r_m = @mysql_query("SELECT * FROM users WHERE manage = '{$r_u['account']}'"); while ($row_m = mysql_fetch_array($r_m)) { $r_n = @mysql_fetch_array(mysql_query("SELECT adate FROM entries WHERE account='{$row_m['account']}' AND adate=''")); if ($r_n) { echo '<option value="manage.php?account='.$row_m['account'].'&m=1" style="color:green;">'.$row_m['name'].'</option>'; }else{ echo '<option value="manage.php?account='.$row_m['account'].'&m=1">'.$row_m['name'].'</option>'; }}[/code] Quote Link to comment Share on other sites More sharing options...
btherl Posted December 12, 2006 Share Posted December 12, 2006 Try this:[code=php:0]SELECT name, adate = '' AS pending FROM users JOIN entries ON (account) WHERE manage = '{$r_u['account']}'[/code]Your results will be 2 columns, name and pending. Pending will be true if adate = '' for that user. The join on account just means "Match up rows where account is matching". Quote Link to comment Share on other sites More sharing options...
bwcc Posted December 13, 2006 Author Share Posted December 13, 2006 I had to amend the query to :[code]SELECT DISTINCT users.name, entries.adate = '' AS pending FROM users JOIN entries ON entries.account=users.account WHERE users.manage = '05107111'[/code]inorder to get any sort of result, but it dropped one user - so looks like it's better off - thanks! Quote Link to comment Share on other sites More sharing options...
btherl Posted December 14, 2006 Share Posted December 14, 2006 Sorry, I messed up the syntax :)What do you mean by "it dropped one user"? Quote Link to comment Share on other sites More sharing options...
bwcc Posted December 14, 2006 Author Share Posted December 14, 2006 NP - it pointed me in the right direction ;DIt dropped a user because of the entries.account = users.accountThe user it dropped did not have an entries.account entry as of yet, so the query works the way it's suppose to.Thanks again Quote Link to comment Share on other sites More sharing options...
btherl Posted December 15, 2006 Share Posted December 15, 2006 Aha, I get it. You're welcome :)If you want to include the dropped user, use LEFT JOIN instead of JOIN. That will include rows which exist in the left table but not the right table. The right table's columns will be filled with nulls for that row. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.