0

助けてください?検索フォームからクエリを実行して結果を出力したのですが、正しく表示されませんか? まだPHPは初めてなので、私のコードが....

必要な結果。te search が返された場合、2 つのうちの 1 つが必要です。雇用者を表示するには: 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);
}
4

1 に答える 1

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);
}
于 2013-09-25T11:03:41.320 に答える