1
<?php
$regs=$_GET["regs"];
$schm=$_GET["schm"];

//echo $regs;

$con = mysql_connect('localhost', 'root', '');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("adjpoly", $con);

$sql="SELECT * FROM student WHERE Register = '".$regs."'";

//echo $sql;

$result = mysql_query($sql);


$sql1="SELECT `Semester`,`Subject`,`Internal`,`External`,`Total`,`Result`,`Arrear` FROM semester".$schm." where Register ='".$regs."'";

//echo $sql1;
$result1 = mysql_query($sql1);

while($row = mysql_fetch_array($result))
{
    if($row==NULL)
    {
        echo '<b style="background-color:#000000">Invalid Number.</b>';
    }
    else
    {
echo "<table style='border:1px solid black;border-collapse:collapse;' width='70%'>
<tr><td style='border:1px solid black;font-weight:bold;background-color:#E2E2E2;font:Tahoma; font-size:13pt' align='right' width='20%'>Name</td>
<td style='border:1px solid black;font-weight:bold;color:#0000CC;background-color:#E2E2E2;font:Tahoma; font-size:13pt'>" . $row['Name']."(". $row['Register']. ")"."</td>
</tr>
<tr><td style='border:1px solid black;font-weight:bold;background-color:#E2E2E2;font:Tahoma; font-size:13pt' align='right' width='20%'>Institution Code</td>
 <td style='border:1px solid black;font-weight:bold;color:#0000CC;background-color:#E2E2E2;font:Tahoma; font-size:13pt'>" . $row['Icode'] . "</td>
</tr>
<tr><td style='border:1px solid black;font-weight:bold;background-color:#E2E2E2;font:Tahoma; font-size:13pt' align='right' width='20%'>Course</td>
<td style='border:1px solid black;font-weight:bold;color:#0000CC;background-color:#E2E2E2;font:Tahoma; font-size:13pt'>" . $row['Course'] ."(FULLTIME)"."(". $row['CCode']. ")". "</td>
</tr>
<tr><td style='border:1px solid black;font-weight:bold;background-color:#E2E2E2;font:Tahoma; font-size:13pt' align='right' width='20%'>Scheme</td>
 <td style='border:1px solid black;font-weight:bold;color:#0000CC;background-color:#E2E2E2;font:Tahoma; font-size:13pt'>" . $row['Scheme'] . "</td>
</tr>";
echo "</table>";

echo "<B> Result : P - Pass   F - Fail   A - Absent </B>";
echo "<table style='border:1px solid black;border-collapse:collapse;' width='70%'>
<tr>
<th style='background-color:#0099CC;color:white;font-size:14pt'>Semester</th>
<th style='background-color:#0099CC;color:white;font-size:14pt'>Subject</th>
<th style='background-color:#0099CC;color:white;font-size:14pt'>Internal Mark</th>
<th style='background-color:#0099CC;color:white;font-size:14pt'>External Mark</th>
<th style='background-color:#0099CC;color:white;font-size:14pt'>Total Mark</th>
<th style='background-color:#0099CC;color:white;font-size:14pt'>Result</th>
</tr>";

while($row = mysql_fetch_array($result1))
  {
  echo "<tr align='center'>";
  echo "<td bgcolor='#E2E2E2' style='border: 1px solid black;font:Tahoma; font-size:14pt'>" . $row['Semester'] . "</td>";
  echo "<td bgcolor='#E2E2E2' style='border: 1px solid black;font:Tahoma; font-size:14pt'>" . $row['Subject'] . "</td>";
  echo "<td bgcolor='#E2E2E2' style='border: 1px solid black;font:Tahoma; font-size:14pt'>" . $row['Internal'] . "</td>";
  echo "<td bgcolor='#E2E2E2' style='border: 1px solid black;font:Tahoma; font-size:14pt'>" . $row['External'] . "</td>";
  echo "<td bgcolor='#E2E2E2' style='border: 1px solid black;font:Tahoma; font-size:14pt'>" . $row['Total'] . "</td>";
  echo "<td bgcolor='#E2E2E2' style='border: 1px solid black;font:Tahoma; font-size:14pt'>" . $row['Result'] . "</td>";
  echo "</tr>";
    $arr = $row['Arrear'];
  }
  echo "<tr align='center' bgcolor='#E2E2E2'><td width='100%' colspan='6' style='border: 1px solid black;'>&nbsp;</td></tr>";
  echo "<tr align='center' bgcolor='#D7DFE3'><td width='100%' align='center' colspan='6' style='border: 1px solid black;'>Arrear:" .$arr . "</td></tr>";
  echo "</table>"; 
    }
}
mysql_close($con);
?>

上面的 php 代码用于根据用户输入显示从 mysql 数据库中检索的内容。

通过使用 if 语句,验证给定的输入是否存在于表中。基于以下示例的语法。

if($row==NULL)
{
  echo "Invalid Input.";  // while run, the echo statement not displaying.
}
else
{
o/p part..   //while run, response proper o/p
}

谁能帮我。请

4

1 回答 1

0

我得到了正确的输出。非常感谢你...

$row=mysql_fetch_array($result);  // here the query executed

if($row!=NULL)    // here checking row not equal to null value.
{

Displaying part...

}
else      // here if the row is NULL; it will print the following echo statement.
{
echo "Invalid input.";
}
于 2013-03-17T15:59:32.757 回答