1

ここでの私の問題 (おそらく) は、$db->fetch_array が db からのすべての結果を表示しないことです。何が起こるかわかりませんが、3 つの結果のうちの 1 つしか得られません。クエリを少し変更しても、多くのことを試しました。ここですべての結果を取得できない理由はありますか?

それはvBulletin 3.8 btw用です。

ありがとう。

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') . '");');

}

}   
4

1 に答える 1

0

あなたのクエリは言っています:

WHERE `fromuserid` has any value 

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

fromuseridユーザー ID に一致する行またはユーザー IDに一致する行が必要な場合は、次のようにしますtouserid

$queryrel = $db->query_read("
        SELECT * FROM " . TABLE_PREFIX . "anexampletable

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

        AND confirmstatus =1
        ");

更新:
作業しているデータを知らずに問題を特定することは困難です。コードが処理しているデータを出力するテストを作成しました。クエリの個々の部分が何を返しているかを確認し、問題がどこにあるかを判断できます。

例のコードの直前にこのコードを配置して、ファイルを一時的に変更します (正しいテーブル名を使用する必要があります)。次に、質問を編集し、出力を下部に貼り付けます。

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();

ファイナルコード?
2 つの問題があったようです:
1)クエリを変更する必要がありました:
オリジナル:

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

更新しました:

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

2012 年 7 月 5 日更新
2) vb3 テンプレートでは配列をループ処理できないため、文字列を連結します。
テンプレートで使用するために出力される $showit 変数は文字列です。最後の結果のみがテンプレートに送信されるように、while ループを通過するたびに上書きされます。を使用する代わりに、 with を$showit = xxx;使用$showit .= xxx;.=ます。

以下のコードの最後の 15 行ほどを更新しました。


詳細については、フォーラム ページがどのように生成されるかをご覧ください。
upload\forumdisplay.php ファイルを開きます。スレッドのリストを作成するループは、 upload\forumdisplay.php(962)whileから始まります。

while ($thread = $db->fetch_array($threads))

各スレッドの出力は「threadbit」テンプレートを使用して生成され、次の$threadbit文字列に追加されます:
upload\forumdisplay.php(1000)
eval('$threadbit .= "' . fetch_template('threadbit') . '";');

最後に「FORUMDISPLAY」テンプレートが出力されます:
upload\forumdisplay.php(1056)
eval('print_output("' . fetch_template('FORUMDISPLAY') . '");');

FORUMDISPLAY テンプレートを見ると、$threadbit文字列が最初から 1/5 ほど使用されていることがわかります。


以下のコードを試して、それがどのように機能するかを確認してください。一連のelse ifステートメントをステートメントに置き換えましたswitch()。より効率的です。

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') . '");');
  }
}
于 2012-06-15T00:42:15.447 に答える