table1
id | author | number_of_view |
---+--------------+-----------------
1 | john | 10
2 | Jack | 20
3 | Anna | 80
4 | Neri | 100
Below I have a PHP script which checks MySQL database table and gives badges to users. The script works perfectly.
$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>$from1 && $viewnumber<=$to1)
{
echo "special user";
}
elseif ($viewnumber>$from2 && $viewnumber<=$to2)
{
echo "plain user";
}
}
}
But problem is that I want to get $from and $to variable values from database table:
table2
id | badge | from |to
---+-------------+------+---
1 | special user| 10 |15
2 | plain user | 20 |30
Here it is second query and PHP script for the second table:
$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 }
How can I do that?
SELECT id, first_name FROM student_details WHERE first_name IN (SELECT first_name FROM student_details WHERE subject='Science'). You'd have to provide more details to get a query that works for your particular situation but this is probably the general idea you want to use.