Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8081113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:37:40+00:00 2026-06-05T16:37:40+00:00

My problem in here ( probably ) is that $db->fetch_array won’t show all the

  • 0

My problem in here (probably) is that $db->fetch_array won’t show all the results from the db. I don’t know what happens but I just get 1 of the 3 results, I tried many things even I changed the query a bit. Do you have any ideas why I can’t get all the results in here?

It’s for vBulletin 3.8 btw.

Thanks people.

if ($_REQUEST['do'] == 'showthis') {


    $rel = $db->query_first("
        SELECT *
        FROM " . TABLE_PREFIX . "anexampletable
        WHERE fromuserid OR touserid = " . $vbulletin->userinfo['userid'] . "
        AND confirmstatus =1
    ");


if ($rel)  {

$queryrel = $db->query_read("
                SELECT *
        FROM " . TABLE_PREFIX . "anexampletable
        WHERE fromuserid OR touserid = " . $vbulletin->userinfo['userid'] . "
        AND confirmstatus =1
        ");            

while ($queryre = $db->fetch_array($queryrel)) { 

if ($queryre['reltype'] == '1') {

               $ty = " is something else ";

} else if ($queryre['reltype'] == '2') {

               $ty = " is something ";

} else if ($queryre['reltype'] == '3') {

               $ty = " is something else ";

} else if ($queryre['reltype'] == '4') {

               $ty = " is something ";

} else if ($queryre['reltype'] == '5') {

               $ty = " is something ";

} else if ($queryre['reltype'] == '6') {

               $ty = " is something ";

} else if ($queryre['reltype'] == '7') {

               $ty = " is something ";

} else if ($queryre['reltype'] == '8') {

               $ty = " is something ";

} else if ($queryre['reltype'] == '9') {

               $ty = " is something ";

} else if ($queryre['reltype'] == '10') {

               $ty = " is something ";

} else if ($queryre['reltype'] == '11') {

               $ty = " is something else ";

} else if ($queryre['reltype'] == '12') {

               $ty = " is something else ";

} else if ($queryre['reltype'] == '13') {

               $ty = " is something ";

} else if ($queryre['reltype'] == '14') {

               $ty = " is something ";
} else {

$ty = " is default ";

}

$sender = $queryre['fromusername'];
$receiver = $queryre['tousername'];
$showit = $sender . $ty . $receiver;

}

eval('print_output("' . fetch_template('relationships') . '");');

}

}   
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T16:37:42+00:00Added an answer on June 5, 2026 at 4:37 pm

    Your query is saying:

    WHERE `fromuserid` has any value 
    
    OR (touserid = $vbulletin->userinfo['userid']).
    

    If you want the rows where either fromuserid matches the userid or touserid matches the userid, try this:

    $queryrel = $db->query_read("
            SELECT * FROM " . TABLE_PREFIX . "anexampletable
    
            WHERE (fromuserid = " . $vbulletin->userinfo['userid'] . ") 
            OR (touserid = " . $vbulletin->userinfo['userid'] . ")
    
            AND confirmstatus =1
            ");
    

    Update:
    It’s hard to determine the problem without knowing the data you’re working with. I’ve created a test that outputs the data your code is working with, you’ll be able to see what the individual parts of your query are returning and then can determine where the problem lies.

    Modify your file temporarily by placing this code just before the code in your example (you’ll need to use the correct table name). Then edit your question and paste the output at the bottom.

    echo "vBulletin User ID = " . $vbulletin->userinfo['userid'];
    
    $test_query1 = $db->query_read("
      SELECT * FROM " . TABLE_PREFIX . "anexampletable
      WHERE (fromuserid = " . $vbulletin->userinfo['userid'] . ")
    ");  
    
    $t1_count = 0;
    echo "Test From User ID Results<br />";
    while ($test1_output = $db->fetch_array($test_query1)) {
      $t1_count++;
      echo "Test From User Result " . $t1_count . "<br />";
      echo "From User ID = " . $test1_output['fromuserid'] . "<br />";
      echo "To User ID = " . $test1_output['touserid'] . "<br />";
      echo "Confirm Status = " . $test1_output['confirmstatus'] . "<br />";
      echo "Relationship Status = " . $test1_output['reltype'] . "<br />";
    }
    
    
    $test_query2 = $db->query_read("
      SELECT * FROM " . TABLE_PREFIX . "anexampletable
      WHERE (touserid = " . $vbulletin->userinfo['userid'] . ")
    ");  
    
    $t2_count = 0;
    echo "<br /><br />Test To User ID Results<br />";
    while ($test2_output = $db->fetch_array($test_query2)) {
      $t2_count++;
      echo "Test To User Result " . $t2_count . "<br />";
      echo "From User ID = " . $test2_output['fromuserid'] . "<br />";
      echo "To User ID = " . $test2_output['touserid'] . "<br />";
      echo "Confirm Status = " . $test2_output['confirmstatus'] . "<br />";
      echo "Relationship Status = " . $test2_output['reltype'] . "<br />";
    }
    
    exit();
    

    Final Code?
    It appears that there were two problems:
    1) The query needed to be modified:
    Original:

    fromuserid OR touserid = " . $vbulletin->userinfo['userid'] . "
    

    Updated:

    (fromuserid = " . $vbulletin->userinfo['userid'] . " 
    OR 
    touserid = " . $vbulletin->userinfo['userid'] . ")
    

    Updated 07/05/2012
    2) You can’t loop through arrays in vb3 templates, so we’ll concatenate strings.
    The $showit variable being output for use in the template is a string. It’s being overwritten by each successive pass through the while loop so that only the last result is sent to the template. Instead of using $showit = xxx;, use $showit .= xxx; with .=.

    I’ve updated the last 15 lines or so of the code below.


    You can look at how the forum page is generated to learn more.
    Open the upload\forumdisplay.php file. The while loop that creates the list of threads starts here:
    upload\forumdisplay.php(962)
    while ($thread = $db->fetch_array($threads))

    The output for each thread is generated using the “threadbit” template and added to the $threadbit string here:
    upload\forumdisplay.php(1000)
    eval('$threadbit .= "' . fetch_template('threadbit') . '";');

    The “FORUMDISPLAY” template is output at the end:
    upload\forumdisplay.php(1056)
    eval('print_output("' . fetch_template('FORUMDISPLAY') . '");');

    If you look at the FORUMDISPLAY template, you’ll find that the $threadbit string is used about 1/5 from the beginning.


    Try the code below and see how it works, I replaced the series of else if statements with a switch() statement. It’s more efficient.

    if ($_REQUEST['do'] == 'showthis') {
    
      // Make standalone query, easy to output query string and run it directly for testing
      $rel_sql = "SELECT * FROM " . TABLE_PREFIX . "anexampletable
        WHERE (fromuserid = " . $vbulletin->userinfo['userid'] . "
        OR touserid = " . $vbulletin->userinfo['userid'] . ")
        AND confirmstatus =1";
    
      $queryrel = $db->query_read($rel_sql);
    
      if ($db->num_rows($queryrel))
      {
        while ($queryre = $db->fetch_array($queryrel))
        {
          switch ($queryre['reltype'])
          {
            case 1:
              $ty = " do something 1 ";
              break;
            case 2:
              $ty = " do something 2 ";
              break;
            case 3:
              $ty = " do something 3 ";
              break;
    
            // Add as many cases as needed
            .......
            case xxx:
              $ty = " do something xxx ";
              break;
            .......
    
            default:
              $ty = " is default ";
          }
    
          $sender = $queryre['fromusername'];
          $receiver = $queryre['tousername'];
    
          // UPDATED FROM HERE DOWN on 07/05/2012
          // Add to $showit with ".=" rather than overwriting it with "=".
    
          // Method One
          // If the output is simple, try this.
          // I added a line break after each entry.
          $showit .= $sender . $ty . $receiver . "<br />";
    
          OR
    
          // Method Two
          // If the output is complex.
          // Create a separate template and store the output in $showit
          // Remember to add the new template to the $actiontemplates array.
          eval('$showit .= "' . fetch_template('showit') . '";');
        }
    
        eval('print_output("' . fetch_template('relationships') . '");');
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a problem here that's probably something that I'm just overlooking, but I
new to programmation, im learning and here is probably a very simple problem for
edit: I should probably say how I am currently worked around the problem here.
Here's my application workflow. I have a ref cursor that is populated with all
just got a slight problem here with updating a MySql DataGridView from visual studio
I'm probably making a newbie mistake here, but I can't figure out how to
I've got a problem here with an MSI deployment that I'm working on (using
I got a serious problem here: I have a scrolling background that is 1320
This is probably something fundamental and stupid that I've missed, but the various workarounds
I know it's been here a lot of times but I didn't find the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.