I am trying to display my vbulletin usergroup ids for each user who posts an ad in my photopost classifieds. in doing this I can execute my code based on that usergroup id. I have been working on this for 3 days now and I just can't get it to work.

This is the code on the page that dfines each listing:

                $gallery['hasimage'][$count] = "$catimage";
                $gallery['prodlink'][$count] = "<a href=\"". construct_newppurl( "showproduct.php", array( 'product' => $id, 'title' => $title, 'cat' => $pcat) ) ."\">$title</a>";
                if ($issticky != 99999 ) $gallery['prodlink'][$count] .= "<img src=\"{$Globals['idir']}/sticky.gif\" alt=\"sticky\" align=\"right\" />";
                $gallery['views'][$count] = $views;
                $gallery['rating'][$count] = $rating;

                list( $numstars, $overall ) = get_user_rating( $tuserid );
                $ratingicon = "";
                if ( $numstars > 0 ) $ratingicon = "&nbsp;<img src=\"{$Globals['idir']}/stars-$numstars.gif\" border=\"0\" alt=\"$numstars {$pp_phrase['stars']}\" />";

                $gallery['username'][$count] = "<a href=\"". construct_newppurl( "member.php", array( 'uid' => $tuserid, 'username' => $tuser) ) ."\">$tuser</a>$ratingicon";
                $gallery['userid'][$count] = "$tuserid";

I attempted to use the following query but it just returns the word 'array':

$users = $vbulletin->db->query_read("SELECT membergroupids FROM 1user WHERE userid = '$tuserid'"); 
while($user= mysql_fetch_array( $users )) {
$membergroupid = $user['membergroupids']; 
} 

That very query works perfectly on the "showproduct" page because the userid is constant. I am attempting to get it to work on the "showcat" page, which lists each of the product in that category. I want to display the usergroup beside each listing displayed.

I know I am looking at this all wrong but just can't wrap my head around why everything I have done hasn't worked and now I am reaching out for help. For those interested, my photopost classifieds is integrated with my vbulletin 4 and uses my member tables and registration system.

Thank you to anyone who can help stop me from pulling out what little hair I have left.

Dani AI

Generated

Since marked this solved but did not post the fix, common causes and a clear pattern are provided so future readers encountering the same symptom ("Array" appearing where a usergroup id should be) can diagnose and fix it quickly.

Typical culprits

  • The variable being printed is actually an array or an object (echoing it yields the word "Array").
  • Mixing vBulletin DB wrapper calls with raw mysql_* functions (use the wrapper's fetch methods).
  • Wrong table name/prefix or the userid variable is not a scalar (e.g., an array or empty).
  • Doing a DB query inside a tight loop for many listings (performance and logic errors).

Quick diagnostics

  • Inspect the variables with var_dump()/print_r() to confirm whether the userid and the DB row are scalars or arrays.
  • Confirm the real vBulletin user table name (replace the placeholder below with the actual table name/prefix).
  • Use vBulletin DB helpers to fetch rows rather than raw mysql_fetch_* when working inside vBulletin code.

Example patterns (replace yourprefix_user with the actual table name)

$tbl = 'yourprefix_user';
$row = $vbulletin->db->query_first("SELECT membergroupids FROM $tbl WHERE userid = " . intval($tuserid));
$membergroupids = $row['membergroupids'];    // string like "2,6" — not an array

Batch approach for lists (better performance)

$uids = array_unique($uids);                      // collected userid values
$in = implode(',', array_map('intval', $uids));
$result = $vbulletin->db->query_read("SELECT userid, membergroupids FROM yourprefix_user WHERE userid IN ($in)");
while ($r = $vbulletin->db->fetch_array($result)) {
  $groups_map[$r['userid']] = $r['membergroupids'];
}

Notes and cautions

  • Sanitize with intval() to avoid injection.
  • membergroupids is often a comma-separated string; use explode(',', $membergroupids) when individual IDs are needed.
  • If the primary group is required, use the usergroupid column instead of membergroupids.

If posts the exact fix used, it will help others match these patterns to the real cause.

Recommended Answers

All 2 Replies

This question has been resolved. I am only posting this to prevent anyone who might come across it in the future from attempting to help. (Good thing I looked for help elsewhere since I didn't get any here.)

Would you share your solution, so it may help others in the future?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.