Note that there are some explanatory texts on larger screens.

plurals
  1. POHow get multiple values from first mysql table and use it in second query?
    primarykey
    data
    text
    <p><strong>table1</strong></p> <pre><code>id | author | number_of_view | ---+--------------+----------------- 1 | john | 10 2 | Jack | 20 3 | Anna | 80 4 | Neri | 100 </code></pre> <p>Below I have a PHP script which checks MySQL database table and gives badges to users. The script works perfectly. </p> <pre><code>$from1=10; $to1=15; $from2=20; $to2=30; $query=mysql_query("SELECT SUM( number_of_view ) AS view_number, author FROM `table1` GROUP BY author"); while ($row= mysql_fetch_array($query)) { $view_number=$row['view_number']; $author=$row['author']; if ($viewnumber&gt;$from1 &amp;&amp; $viewnumber&lt;=$to1) { echo "special user"; } elseif ($viewnumber&gt;$from2 &amp;&amp; $viewnumber&lt;=$to2) { echo "plain user"; } } } </code></pre> <p>But problem is that I want to get <code>$from</code> and <code>$to</code> variable values from database table:</p> <p><strong>table2</strong></p> <pre><code>id | badge | from |to ---+-------------+------+--- 1 | special user| 10 |15 2 | plain user | 20 |30 </code></pre> <p>Here it is second query and PHP script for the second table:</p> <pre><code>$query2=mysql_query("SELECT * FROM table2"); while ($row= mysql_fetch_array($query2)) { $badgeName=$row['view_number']; //I would like to use this variable above. So instead of "echo 'special user';" I would like use "echo $badgeName" $from=$row['author']; // I would like to use this variable above instead of $from1 and $from2 $to=$row['to']; // I would like to use this variable above instead of $to1 and $to2 } </code></pre> <p>How can I do that? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload