vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   problem driving me mad (https://vborg.vbsupport.ru/showthread.php?t=37077)

Bald Bouncer 04-06-2002 03:42 PM

problem driving me mad
 
PHP Code:

  $users=$DB_site->query("SELECT userid,username,usertitle FROM user WHERE username LIKE '%".addslashes(htmlspecialchars($findname))."%' ORDER BY username");
  
$field=$DB_site->query("SELECT field14 FROM userfields WHERE userid=$users[userid]");
  echo 
"<table>";
  if (
$DB_site->num_rows($users)>0) {
    echo 
"<tr><td nowrap><p><b>Team Members Found:</b></p></td>".iif($perms[ismoderator] or $bbuserinfo['usergroupid']==25"<td nowrap><p>&nbsp;</p></td>""").iif($perms[ismoderator] or $bbuserinfo['usergroupid']==25"<td nowrap><p>&nbsp;</p></td>""")."</tr>\n";
    while (
$user=$DB_site->fetch_array($users)) {
      echo 
"<tr><td nowrap><p>$user[username] - $field[field14]</p></td>".iif($perms[ismoderator] or $bbuserinfo['usergroupid']==25"<td nowrap><a href=\"user.php?action=viewuser&userid=$user[userid]\"><p>[view user]</a> <a href=\"user.php?action=edituser&userid=$user[userid]\">[Edit User]</a></p></td>""")."</tr>\n";
    } 

can anyone fix this code so it will show the contents of profile field 14 next to the username....I think it needs to fetch the rray of $users and $field but Im not sure how its done :(

any help appreciated

Admin 04-07-2002 10:50 AM

You can join the user and userfield tables right in the first query:
Code:

$users = $DB_site->query("
        SELECT userid,username,usertitle,field14
        FROM user
        WHERE username LIKE '%".addslashes(htmlspecialchars($findname))."%'
        ORDER BY username
");

echo "<table>";
if ($DB_site->num_rows($users)>0) {
        echo "<tr><td nowrap><p><b>Team Members Found:</b></p></td>".iif($perms[ismoderator] or $bbuserinfo['usergroupid']==25, "<td nowrap><p>&nbsp;</p></td>", "").iif($perms[ismoderator] or $bbuserinfo['usergroupid']==25, "<td nowrap><p>&nbsp;</p></td>", "")."</tr>\n";
        while ($user=$DB_site->fetch_array($users)) {
                echo "<tr><td nowrap><p>$user[username] - $field[field14]</p></td>".iif($perms[ismoderator] or $bbuserinfo['usergroupid']==25, "<td nowrap><a href=\"user.php?action=viewuser&userid=$user[userid]\"><p>[view user]</a> <a href=\"user.php?action=edituser&userid=$user[userid]\">[Edit User]</a></p></td>", "")."</tr>\n";
        }
}
echo "</table>";

You also have this code twice in there, not sure it's supposed to be there (and if it is, use only one iif()):
Code:

iif($perms[ismoderator] or $bbuserinfo['usergroupid']==25, "<td nowrap><p>&nbsp;</p></td>", "")

Bald Bouncer 04-07-2002 06:38 PM

it will need to pull field14 from userfield not users i think....so how exactly do I use join to stick both the coloms in the same query mate?

PHP Code:

$users $DB_site->query(
SELECT userid,username,usertitle
FROM user 
WHERE username LIKE '%"
.addslashes(htmlspecialchars($findname))."%' 
ORDER BY username 
"
); 

I need to grab field14 from userfield in the above :dead:

Admin 04-07-2002 06:46 PM

Of course I forgot the JOIN line... duh.
Code:

$users = $DB_site->query("
        SELECT userid,username,usertitle,field14
        FROM user
        LEFT JOIN userfield USING (userid)
        WHERE username LIKE '%".addslashes(htmlspecialchars($findname))."%'
        ORDER BY username
");


Bald Bouncer 04-07-2002 07:13 PM

cheers for the help mate but its still not working :( dont happen to know were its going wrong do you mate?

PHP Code:

$users $DB_site->query("SELECT userid,username,usertitle,field14 FROM user LEFT JOIN userfield USING (userid) WHERE username LIKE '%".addslashes(htmlspecialchars($findname))."%' ORDER BY username");
  echo 
"<table>";
  if (
$DB_site->num_rows($users)>0) {
    echo 
"<tr><td nowrap><p><b>Team Members Found:</b></p></td>".iif($perms[ismoderator] or $bbuserinfo['usergroupid']==25"<td nowrap><p>&nbsp;</p></td>""").iif($perms[ismoderator] or $bbuserinfo['usergroupid']==25"<td nowrap><p>&nbsp;</p></td>""")."</tr>\n";
    while (
$user=$DB_site->fetch_array($users)) {
      echo 
"<tr><td nowrap><p>$user[username] - $user[field14]</p></td>".iif($perms[ismoderator] or $bbuserinfo['usergroupid']==25"<td nowrap><p>EDIT USER</p></td>""")."</tr>\n";
    }
  } else {
    echo 
"<td><p>No Team Members found</p></td>";
  }
  echo 
"</table>";



Admin 04-07-2002 07:20 PM

Ok replace "SELECT userid" with "SELECT user.userid".

Bald Bouncer 04-07-2002 07:39 PM

thanks a lot mate worked a charm!!
really appreciated!!

:p :bunny:


All times are GMT. The time now is 12:11 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01777 seconds
  • Memory Usage 1,750KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (3)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete