SQL获取与请求匹配的所有查询

SQL获取与请求匹配的所有查询

问题描述:

Hey all I am wondering how I could get ALL queries from a table, it only gets the first one and stops

My code:

              $result1 = mysql_query("SELECT `to` FROM transactions WHERE `from` = '$user'");

              $row = mysql_fetch_row($result1);

              $result2 = mysql_query("SELECT `amount` FROM transactions WHERE `from` = '$user'");

               $row2 = mysql_fetch_row($result2);


              echo "<li>TO</li>";
              echo "<li>AMOUNT</li>";
              echo "<li>$row[0]</li>";
              echo "<li>$row2[0]</li>";
              echo "<li>$row[1]</li>";
              echo "<li>$row2[1]</li>";
              echo "<li>$row[2]</li>";
              echo "<li>$row2[2]</li>";
              echo "<li>$row[3]</li>";
              echo "<li>$row2[4]</li>";
              echo "<li>$row[4]</li>";
              echo "<li>$row2[5]</li>";

My Database:

I want all of the rows that say "fusion" or the to return, but it only returns first.

嘿所有我想知道如何从表中获取所有查询,它只获取第一个并停止

我的代码: p>

  $ result1 = mysql_query(“SELECT`to` FROM transactions WHERE`from` ='$ user'”)  ; 
 
 $ row = mysql_fetch_row($ result1); 
 
 $ result2 = mysql_query(“SELECT`num` FROM transactions WHERE` from` ='$ user'”); 
 
 $ row2 = mysql_fetch_row  ($ result2); 
 
 
 echo“&lt; li&gt; TO&lt; / li&gt;”; 
 echo“&lt; li&gt; AMOUNT&lt; / li&gt;”; 
 echo“&lt; li&gt; $ row [  0]&lt; / li&gt;“; 
 echo”&lt; li&gt; $ row2 [0]&lt; / li&gt;“; 
 echo”&lt; li&gt; $ row [1]&lt; / li&gt;“; \  n echo“&lt; li&gt; $ row2 [1]&lt; / li&gt;”; 
 echo“&lt; li&gt; $ row [2]&lt; / li&gt;”; 
 echo“&lt; li&gt; $ row2 [  2]&lt; / li&gt;“; 
 echo”&lt; li&gt; $ row [3]&lt; / li&gt;“; 
 echo”&lt; li&gt; $ row2 [4]&lt;  / li&gt;“; 
 echo”&lt; li&gt; $ row [4]&lt; / li&gt;“; 
 echo”&lt; li&gt; $ row2 [5]&lt; / li&gt;“; 
  code  >  pre> 
 
 

我的数据库: p>

p> div>

$row = mysql_fetch_row($result1); will only fetch one row

You need to use while

$query = mysql_query("SELECT `to`, `amount` FROM transactions WHERE `from` = '$user'");
echo "<li>TO</li>";
echo "<li>AMOUNT</li>";
while ($row = mysql_fetch_assoc($query)) {

     echo "<li>{$row['to']}</li>";
     echo "<li>{$row['amount']}</li>";
}