mysql comparing two integers from two tables
if($num>0) {
echo "<table border=2> Table Request".$_SESSION['s1'];
echo"<tr>
<td>Id</td><td>Drug</td><td>Quantity</td>
</tr>";
for($i=0;$i<$num;$i++) {
$row=mysql_fetch_row($result);
$r[$i]=$row[1];
echo "<tr>";
for($j=0;$j<$num1;$j++) {
echo"<td>$row[$j]</td>";
}
echo"<td><input type='Checkbox' name='p[$i]' value='on' unchecked /></td>";
echo"<td><input type='txt' name='q[$i]' /></td>";
echo"</tr>";
$r[$i]=$row[1];
}
if(isset($_POST['p'])) {
foreach($_POST['p'] as $key=>$value) {
if($value == "on") {
$query8 = "select $r[$i] from $_SESSION['t'] ";
echo $query8;
$result8 = mysq开发者_如何学Gol_query($query8);
$num8=Mysql_num_rows($result8);
if($num8!=0) {
$query7="select qun from $_SESSION['t']";
$result7 = mysql_query($query8);
//?????????????????
}
}
echo"</table>";
}
}//result
}//else
I have a table request and another table for example E.
I want to compare the field quantity of these tables
if(select qun from request)<((select qun from $_SESSION['t'])) // some work
How can I write this code in the part that I marked with many question marks?
is this correct?If you really want what the title says, why you don't do something like that
SELECT table1.quantity AS qu1, table2.quantity AS qu2 FROM table1, table2 WHERE your_conditions;
When you get the results, you can compare qu1 against qu2.
But if you are looking for something different, than please be more specific with your question.
Actual example:
$query8 = 'SELECT '.$_SESSION[ 't'].'.'.$r[$i].' AS qu1, request.qun AS qu2 FROM '.$_SESSION[ 't'].', request';
$result8 = mysql_query($query8);
while ($row8 = mysql_fetch_array($result8)) {
if ($row8[ 'qu1'] < $row8[ 'qu2']) {
echo 'the value from '.$r[$i]. ' is smaller';
} elseif ($row8[ 'qu1'] > $row8[ 'qu2']) {
echo 'the value from '.$r[$i]. ' is bigger';
} else {
echo 'both values are same';
}
}
精彩评论