如果关键字不匹配,如何显示消息

时间:2015-03-05 12:07:23

标签: php mysql search

我正在尝试按类别显示上传的简历,这是在下拉列表中,当我选择网页设计师时,它会显示所有上传的网页设计师简历,但如果关键字与任何类别不匹配,那么它应该显示消息"此类别中没有找到简历",如果可以的话,我希望我是php新手,请帮助我。感谢

<?php

$cat=$_GET['cat']; // Security will be added here.

$results = mysql_query("SELECT * FROM resumes where profile like '%$cat%' ORDER BY id desc LIMIT 0, 50000");

while($row = mysql_fetch_array($results)) {

$anymatches = mysql_num_rows($results);

?>

在这里,我想展示信息。

<?php if ($anymatches == 0) { ?><font color="#990000"></p>No resumes found in this category.</font><?php } ?>

完整页面在这里---

<?php include "inc.php";

$cat=$_REQUEST['cat'];
$cat=str_replace(' ','%',$_REQUEST['cat']);

if(!isset($_SESSION['ocer'])){
header("Location: index.php?l=1");
}

if(isset($_REQUEST['action']) && $_REQUEST['action']=="del"){
$sql_del="delete from resumes  where id='".$_REQUEST['idm']."'";
mysql_query($sql_del) or die(mysql_error());

header("Location: resumes_by_cat.php?del=1");
}
$mydtl="select * from register where email='".$_SESSION['ocer']."'";
$mydtl1=mysql_query($mydtl) or die(mysql_error());
$mydetail=mysql_fetch_array($mydtl1);

?>

<?php
$active=2;
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Admin Panel</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/js.js"></script>

<script type="text/JavaScript">

function cmd_del(){

var x= confirm("Do you want to delete this resume ?");

if(x)

return true;

else 

return false;



}
</script>
</head>

<body>

<div id="container">
<div id="header">
<table width="100%" border="0" style="position:fixed;">
  <tr>
    <td style="padding-left:10px; padding-top:8px;"><h1>Rozgaar4all Admin Panel</h1></td>
    <td>&nbsp;</td>
    <td align="right" style="padding-right:10px; padding-top:8px;"><a href="logout.php"><strong>Logout</strong></a></td>
  </tr>
</table>
</div>

<?php include "left-panel.php"; ?>



<table width="80%" border="0" style="float:right; margin-top:70px; margin-right:10px; font-size:12px; color:#555555;">

  <tr>
    <td height="21" colspan="2" align="left" valign="middle">
    <?php if($_REQUEST['del']==1){ ?>
                <div class="green-msg" style="margin-bottom:0px;">Resume has been successfully deleted.</div>
                <?php } ?>    </td>
    </tr>
  <tr>
    <td width="807" align="left" valign="middle"><h1>Manage Resumes </h2><select name="Profile" id="Profile" class="input" style="width:212px;" required onchange="location = this.options[this.selectedIndex].value;"><option value="" selected="selected">Find by Category</option><optgroup label="Top Categories">Top Categories</optgroup><option value="resumes_by_cat.php?cat=Accounts, Finance, Tax, Company Secretary, Audit">Accounts, Finance, Tax, Company Secretary, Audit</option><option value="resumes_by_cat.php?cat=Analytics &amp; Business Intelligence">Analytics &amp; Business Intelligence</option><option value="resumes_by_cat.php?cat=Financial Services, Banking, Investments, Insurance">Financial Services, Banking, Investments, Insurance</option><option value="resumes_by_cat.php?cat=ITES, BPO, KPO, LPO, Customer Service, Operations">ITES, BPO, KPO, LPO, Customer Service, Operations</option><option value="resumes_by_cat.php?cat=HR, Recruitment, Administration, IR">HR, Recruitment, Administration, IR</option><option value="resumes_by_cat.php?cat=Marketing, Advertising, MR, PR, Media Planning">Marketing, Advertising, MR, PR, Media Planning</option><option value="resumes_by_cat.php?cat=Production, Manufacturing, Maintenance">Production, Manufacturing, Maintenance</option><option value="resumes_by_cat.php?cat=Site Engineering, Project Management">Site Engineering, Project Management</option><option value="resumes_by_cat.php?cat=Engineering Design, R&amp;D">Engineering Design, R&amp;D</option><option value="resumes_by_cat.php?cat=Sales, Retail, Business Development">Sales, Retail, Business Development</option><option value="resumes_by_cat.php?cat=Shipping">Shipping</option><option value="resumes_by_cat.php?cat=IT Software - All Jobs">IT Software - All Jobs</option><optgroup label="IT Software Categories">IT Software Categories</optgroup><option value="resumes_by_cat.php?cat=IT Software - Application Programming, Maintenance">IT Software - Application Programming, Maintenance</option><option value="resumes_by_cat.php?cat=IT Software - Client/Server Programming">IT Software - Client/Server Programming</option><option value="resumes_by_cat.php?cat=IT Software - DBA, Datawarehousing">IT Software - DBA, Datawarehousing</option><option value="resumes_by_cat.php?cat=IT Software - ERP, CRM">IT Software - ERP, CRM</option><option value="resumes_by_cat.php?cat=IT Software - Embedded, EDA, VLSI, ASIC, Chip Design">IT Software - Embedded, EDA, VLSI, ASIC, Chip Design</option><option value="IT Software - Network Administration, Security">IT Software - Network Administration, Security</option><option value="resumes_by_cat.php?cat=IT Software - QA &amp; Testing">IT Software - QA &amp; Testing</option><option value="resumes_by_cat.php?cat=IT Software - System Programming">IT Software - System Programming</option><option value="resumes_by_cat.php?cat=IT Software - Telecom Software">IT Software - Telecom Software</option><option value="resumes_by_cat.php?cat=IT Software - Systems, EDP, MIS">IT Software - Systems, EDP, MIS</option><option value="resumes_by_cat.php?cat=IT Software - eCommerce, Internet Technologies">IT Software - eCommerce, Internet Technologies</option><option value="resumes_by_cat.php?cat=IT Software - Mainframe">IT Software - Mainframe</option><option value="resumes_by_cat.php?cat=IT Software - Mobile">IT Software - Mobile</option><option value="resumes_by_cat.php?cat=IT Software - Middleware">IT Software - Middleware</option><option value="resumes_by_cat.php?cat=IT Software - Other">IT Software - Other</option><optgroup label="More Categories">More Categories</optgroup><option value="resumes_by_cat.php?cat=Top Management - IT Jobs">Top Management - IT Jobs</option><option value="Top Management - Non IT">Top Management - Non IT</option><option value="Architecture, Interior Design">Architecture, Interior Design</option><option value="resumes_by_cat.php?cat=Design, Creative, User Experience">Design, Creative, User Experience</option><option value="resumes_by_cat.php?cat=Hotels, Restaurants">Hotels, Restaurants</option><option value="resumes_by_cat.php?cat=Journalism, Editing, Content">Journalism, Editing, Content</option><option value="resumes_by_cat.php?cat=Strategy, Management Consulting, Corporate Planning">Strategy, Management Consulting, Corporate Planning</option><option value="resumes_by_cat.php?cat=Self Employed, Entrepreneur, Independent Consultant">Self Employed, Entrepreneur, Independent Consultant</option><option value="resumes_by_cat.php?cat=Export, Import, Merchandising">Export, Import, Merchandising</option><option value="resumes_by_cat.php?cat=Executive Assistant, Front Office, Data Entry">Executive Assistant, Front Office, Data Entry</option><option value="resumes_by_cat.php?cat=Legal, Regulatory, Intellectual Property">Legal, Regulatory, Intellectual Property</option><option value="resumes_by_cat.php?cat=Supply Chain, Logistics, Purchase, Materials">Supply Chain, Logistics, Purchase, Materials</option><option value="Medical, Healthcare, R&amp;D, Pharmaceuticals, Biotechnology">Medical, Healthcare, R&amp;D, Pharmaceuticals, Biotechnology</option><option value="Packaging">Packaging</option><option value="resumes_by_cat.php?cat=Teaching, Education, Training, Counselling">Teaching, Education, Training, Counselling</option><option value="resumes_by_cat.php?cat=IT Hardware, Technical Support, Telecom Engineering">IT Hardware, Technical Support, Telecom Engineering</option><option value="Fashion Designing, Merchandising">Fashion Designing, Merchandising</option><option value="resumes_by_cat.php?cat=TV, Films, Production, Broadcasting">TV, Films, Production, Broadcasting</option><option value="resumes_by_cat.php?cat=Travel, Tours, Ticketing, Airlines">Travel, Tours, Ticketing, Airlines</option><option value="resumes_by_cat.php?cat=Defence Forces, Security Services">Defence Forces, Security Services</option><option value="resumes_by_cat.php?cat=Government, Defence">Government, Defence</option><option value="resumes_by_cat.php?cat=Overseas, International Jobs">Overseas, International Jobs</option><option value="resumes_by_cat.php?cat=Retail, Wholesale">Retail, Wholesale</option><option value="resumes_by_cat.php?cat=Pharma, Biotechnology, Clinical Research">Pharma, Biotechnology, Clinical Research</option><option value="resumes_by_cat.php?cat=Freshers">Freshers</option><option value="resumes_by_cat.php?cat=Other">Other</option></select>



</td>
    <td width="253" height="21" align="right" valign="top"><strong>Total Resumes :</strong> ( <?php $sql5="select * from resumes";
            $res5 = mysql_query($sql5);
            echo $num5=mysql_num_rows($res5);?> )</td>
    </tr>
  <tr>
    <td colspan="2"><div class="clear"></div></td>
    </tr>

<?php

$cat=$_GET['cat']; // Security will be added here.

$results = mysql_query("SELECT * FROM resumes where profile like '%$cat%' ORDER BY id desc LIMIT 0, 50000");

$anymatches = mysql_num_rows($results);

while($row = mysql_fetch_array($results)) {

?>

    <tr>


    <td height="35" align="left" valign="middle" style="font-size:13px;">

    <div class="admin-n-title"><?php echo $row['fullname']; ?></div>

    <div class="admin-n-title"><a href="applied-candidates.php?id=<?php echo $row['id']; ?>"></a></div>

            <div style="float:right; width:auto; margin-right:50px;"><a href="uploadedcv/<?php echo $row['resume']; ?>" style="color:#0d6eb5;">Download</a></div>   </td>
    <td height="35" align="left" valign="middle" style="color:#666666;">
    <div style="width:auto; float:left; margin-top:2px;"><?php echo stripslashes($row['date']); ?></div><a href="resumes.php?action=del&amp;idm=<?php echo $row['id']; ?>" onclick="return cmd_del()"><div class="admin-btn">Delete</div></a>   </td>
    </tr>
    <tr>
    <td colspan="2"></td>
    </tr>
    <tr>
      <td colspan="2"><table width="100%" border="1" cellpadding="5" cellspacing="0" bordercolor="#F0F0F0">
        <tr>
          <td width="10%" height="35" align="left" valign="middle"><strong>Job Type :</strong> </td>
          <td width="43%" height="35" align="left" valign="middle"><?php echo $row['profile'];?></td>
          <td width="12%" height="35"><strong>Desired Job Title :</strong></td>
          <td width="15%" height="35"><?php echo $row['jobtitle'];?></td>
          <td width="8%"><strong>Experience :</strong> </td>
          <td width="12%"><?php echo $row['experience'];?> years</td>
        </tr>
        <tr>
          <td width="10%" height="35" align="left" valign="middle"><strong>Qualification :</strong> </td>
          <td width="43%" height="35" align="left" valign="middle"><?php echo $row['qualification'];?></td>
          <td width="12%" height="35"><strong>Phone  :</strong></td>
          <td width="15%" height="35"><?php echo $row['phone'];?></td>
          <td width="8%"><strong>City  :</strong> </td>
          <td width="12%"><?php echo $row['city'];?></td>
        </tr>
        <tr>
          <td width="10%" height="35" align="left" valign="middle"><strong>Email  :</strong> </td>
          <td width="43%" height="35" align="left" valign="middle"><?php echo $row['email'];?></td>
          <td width="12%" height="35"><strong>State   :</strong></td>
          <td width="15%" height="35"><?php echo $row['state'];?></td>
          <td width="8%">&nbsp;</td>
          <td width="12%">&nbsp;</td>
        </tr>
        <tr>
          <td height="35" align="left" valign="middle"><strong>Message :</strong> </td>
          <td height="35" colspan="5" align="left" valign="middle"><?php echo $row['msg'];?></td>
          </tr>

      </table></td>
    </tr>
    <tr>
      <td height="15" colspan="2" valign="bottom"><div class="clear"></div></td>
    </tr>
<?php } ?>
</table>


</div>

</div>
</div>

</div>

</body>
</html>

3 个答案:

答案 0 :(得分:0)

mysql_num_rows不应该在你的while循环中。如果你将它移到循环之后,只要你的sql查找正确,你的代码应该可以正常工作。

像这样:

while($row = mysql_fetch_array($results)) {
    //output your resumes here
}
if( mysql_num_rows($results)==0 ) echo "<p>No resumes found in this category.</p>";

答案 1 :(得分:0)

希望此代码能为您提供帮助。

<?php

    $cat=$_GET['cat']; // Security will be added here.

    $results = mysql_query("SELECT * FROM resumes where profile like '%$cat%' ORDER BY id desc LIMIT 0, 50000");

    // Dont place mysql_num_rows inside loop
    // It returns same value only if its inside in loop
    $anymatches = mysql_num_rows($results); 

    //If mysql_num_rows has more than 0 let run in loop
    if($anymatches > 0){

        while($row = mysql_fetch_array($results)) {

            //loop so on

        }       

    }else{ // else number of rows is 0 print your message

        echo '<p>No resumes found in this category.</p>';       

    }    

?>

答案 2 :(得分:0)

解决问题!!

我在代码的顶部添加了这两行。

$results = mysql_query("SELECT * FROM resumes where profile like '%$cat%' ORDER BY id desc LIMIT 0, 50000");
$anymatches = mysql_num_rows($results);