请帮忙吗?我通过搜索表单和输出结果运行查询,但它没有显示它应该?还是php的新手,请原谅我的代码是....
需要的结果。如果te搜索返回我想要两件事之一。要么显示雇用者:xxx或当前未使用:
<?php
if ($_REQUEST['submit']) {
$term = $_POST['term'];
$row ['employerid'] == $user_data ['user_id'];
$XX = "<br><br><div class='messagebox'><h2> <center> Oops! </h2> <p>We were only to retrieve a partial record on <strong>$term</strong> you have entered. Please make use of our contact form if you would like us to get you your reference. Be sure to enter the three required fields. <a href='Mailforms/refrequest.php' class='lightbox'>Click Here!</a> or to validate the id <a href='idverification.php'> Click here</a></p>
<br />
</div>";
$sql = mysql_query("select * from ref_employees where `idnumber`= '$term'")
or die('Error in query : $sql. ' .mysql_error());
{
if (mysql_num_rows($sql) > 0 )
{
while ($row = mysql_fetch_array($sql)){
if ($row ['employed'] == '1') {
echo '<h4>Currently Employed By : '.$row['companyname'];
echo '</h4> ';}
if ($row ['employed'] == '0') {
echo '<h4>Not Currently employed : '.$row['companyname'];
echo '</h4> ';}
echo '<h4> ID : '.$row['idnumber'] ;
echo '<br> First Name : '.$row['firstname'];
echo '<br> Last Name : '.$row['lastname'];
echo '<br> Gender : '.$row['gender'];
echo ' </h4>';
echo '<br />';
echo '<h2>Some Additional Options</h2>';
echo '<br />';
}
}
else
{
print ("$XX");
}
mysql_free_result($sql);
mysql_close($connection);
}
答案 0 :(得分:1)
你在{
上面放了一个额外的大括号if (mysql_num_rows($sql) > 0 ) {
更正代码:
<?php
if ($_REQUEST['submit']) {
$term = $_POST['term'];
$row ['employerid'] == $user_data ['user_id'];
$XX = "<br><br><div class='messagebox'><h2> <center> Oops! </h2> <p>We were only to retrieve a partial record on <strong>$term</strong> you have entered. Please make use of our contact form if you would like us to get you your reference. Be sure to enter the three required fields. <a href='Mailforms/refrequest.php' class='lightbox'>Click Here!</a> or to validate the id <a href='idverification.php'> Click here</a></p>
<br />
</div>";
$sql = mysql_query("select * from ref_employees where `idnumber`= '$term'")
or die('Error in query : $sql. ' .mysql_error());
if (mysql_num_rows($sql) > 0 ) {
while ($row = mysql_fetch_array($sql)){
if ($row ['employed'] == '1') {
echo '<h4>Currently Employed By : '.$row['companyname'];
echo '</h4> ';}
if ($row ['employed'] == '0') {
echo '<h4>Not Currently employed : '.$row['companyname'];
echo '</h4> ';}
echo '<h4> ID : '.$row['idnumber'] ;
echo '<br> First Name : '.$row['firstname'];
echo '<br> Last Name : '.$row['lastname'];
echo '<br> Gender : '.$row['gender'];
echo ' </h4>';
echo '<br />';
echo '<h2>Some Additional Options</h2>';
echo '<br />';
}
}
else
{
print ("$XX");
}
mysql_free_result($sql);
mysql_close($connection);
}