查询在 mysql 中运行良好,但在 PHP 中运行不佳
Query is working well in mysql but not in PHP
查询在 mysql 中运行良好,但在 php 中运行不佳。
在 php 中实施内部联接后,我只获得星期二的价值。周一和周二有两张桌子。选择星期一的 lab1 和星期二的 lab1 时,只显示星期二的 lab1。
P.S。查询正在 mysql.
<form action="lab.php" method="POST">
Check routine for : <select name="new">
<option name="lab1">LAB1</option>
<option name="lab2">LAB2</option>
<option name="lab3">LAB3</option>
<option name="lab4">LAB4</option>
</select>  
<input type="submit" value="Submit">
</form>
<?php
require 'conn.php';
if(isset($_POST['new'])&& !empty($_POST['new']))
{
$lab=$_POST['new'];
$lab=strtolower($lab);
$result = mysql_query("select monday.time,
monday.$lab,tuesday.$lab from monday inner join
tuesday where monday.time=tuesday.time");
echo "<table BORDER='1' width='50%' cellpadding='3'>
<tr>
<th colspan='7'><h2>$lab</h2></th>
</tr>
<tr>
<th>TIME</th>
<th>MONDAY</th>
<th>TUESDAY</th>
</tr>";
while($row = mysql_fetch_array($result))
{ echo "<tr>";
echo "<td>" .$row['time']. "</td>";
echo "<td>" .$row[$lab]. "</td>";
echo "<td>" .$row[$lab]. "</td>";
echo "</tr>";
}
echo "</table>";
}
?>
试一试它有效。
<?php
require 'conn.php';
if(isset($_POST['new'])&& !empty($_POST['new']))
{
$lab=$_POST['new'];
$lab=strtolower($lab);
$result = mysql_query("select monday.time,
monday.$lab,tuesday.$lab as labval from monday inner join
tuesday where monday.time=tuesday.time") or die(mysql_error());
echo "<table BORDER='1' width='50%' cellpadding='3'>
<tr>
<th colspan='7'><h2>$lab</h2></th>
</tr>
<tr>
<th>TIME</th>
<th>MONDAY</th>
<th>TUESDAY</th>
</tr>";
while($row = mysql_fetch_array($result))
{ echo "<tr>";
echo "<td>" .$row['time']. "</td>";
echo "<td>" .$row[$lab]. "</td>";
echo "<td>" .$row['labval']. "</td>";
echo "</tr>";
}
echo "</table>";
}
?>
查询在 mysql 中运行良好,但在 php 中运行不佳。 在 php 中实施内部联接后,我只获得星期二的价值。周一和周二有两张桌子。选择星期一的 lab1 和星期二的 lab1 时,只显示星期二的 lab1。
P.S。查询正在 mysql.
<form action="lab.php" method="POST">
Check routine for : <select name="new">
<option name="lab1">LAB1</option>
<option name="lab2">LAB2</option>
<option name="lab3">LAB3</option>
<option name="lab4">LAB4</option>
</select>  
<input type="submit" value="Submit">
</form>
<?php
require 'conn.php';
if(isset($_POST['new'])&& !empty($_POST['new']))
{
$lab=$_POST['new'];
$lab=strtolower($lab);
$result = mysql_query("select monday.time,
monday.$lab,tuesday.$lab from monday inner join
tuesday where monday.time=tuesday.time");
echo "<table BORDER='1' width='50%' cellpadding='3'>
<tr>
<th colspan='7'><h2>$lab</h2></th>
</tr>
<tr>
<th>TIME</th>
<th>MONDAY</th>
<th>TUESDAY</th>
</tr>";
while($row = mysql_fetch_array($result))
{ echo "<tr>";
echo "<td>" .$row['time']. "</td>";
echo "<td>" .$row[$lab]. "</td>";
echo "<td>" .$row[$lab]. "</td>";
echo "</tr>";
}
echo "</table>";
}
?>
试一试它有效。
<?php
require 'conn.php';
if(isset($_POST['new'])&& !empty($_POST['new']))
{
$lab=$_POST['new'];
$lab=strtolower($lab);
$result = mysql_query("select monday.time,
monday.$lab,tuesday.$lab as labval from monday inner join
tuesday where monday.time=tuesday.time") or die(mysql_error());
echo "<table BORDER='1' width='50%' cellpadding='3'>
<tr>
<th colspan='7'><h2>$lab</h2></th>
</tr>
<tr>
<th>TIME</th>
<th>MONDAY</th>
<th>TUESDAY</th>
</tr>";
while($row = mysql_fetch_array($result))
{ echo "<tr>";
echo "<td>" .$row['time']. "</td>";
echo "<td>" .$row[$lab]. "</td>";
echo "<td>" .$row['labval']. "</td>";
echo "</tr>";
}
echo "</table>";
}
?>