By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,729 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,729 IT Pros & Developers. It's quick & easy.

search engine cant function

100+
P: 127
Below is my search engine for job portal which jobseeker can find the job through quick search. But it cant work... Is it mysql query got problem?? Thanx..

Interface
[HTML]<html>
<head>
<title>UMS e-Job Portal</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
background-color: #FFFFFF;
}
body,td,th {
color: #000000;
}
a:link {
color: #FFFFFF;
}
a:visited {
color: #FFFFFF;
}
a:hover {
color: #CCCCCC;
}
a:active {
color: #CCCCCC;
}
-->
</style></head>

<body bgcolor="#FFFFFF" text="#000000">
<form name="search job" method="post" action="jobsearch_act.php">
<p>&nbsp;</p>

<table width="600" border="0">
<tr>
<td colspan="3"><font color="#000000"><strong>QUICK SEARCH</strong></font></td>
</tr>
<tr>
<td width="217"><font color="#000000">Keyword(s)</font><font color="#000000">&nbsp;</font></td>
<td width="30"><div align="center"><strong>:</strong></div></td>
<td width="339"><input name="keyword" type="text" maxlength="30"></td>
</tr>
<tr>
<td><font color="#000000">Job Category</font> </td>
<td><div align="center"><strong>:</strong></div></td>
<td><select name="jobCategory">
<option selected></option>
<option>Accounting</option>
<option>Advertising</option>
<option>Agriculture</option>
<option>Banking</option>
<option>Biotechnology</option>
<option>Chemical Eng</option>
<option>Chemistry</option>
<option>Clerical/Admin</option>
<option>Customer Service</option>
<option>Education</option>
<option>Electronics Eng</option>
<option>Food Tech</option>
<option>General Workers</option>
<option>Graphics</option>
<option>Healthcare</option>
<option>Hotel/Food</option>
<option>Human Resources</option>
<option>IT/Computer</option>
<option>Journalist/Editor</option>
<option>Manufacturing</option>
<option>Marketing</option>
<option>Mechanical Eng</option>
<option>Media/Entertain</option>
<option>Personal Care</option>
<option>Publishing</option>
<option>Purchasing</option>
<option>Quantity Survey</option>
<option>Sales</option>
<option>Science/Tech</option>
<option>Secretarial</option>
<option>Social Services</option>
<option>Training</option>
<option>Others</option>
</select></td>
</tr>
<tr>
<td><font color="#000000">Job Location</font></td>
<td><div align="center"><strong>:</strong></div></td>
<td><select name="jobLocation">
<option selected></option>
<option>Perlis</option>
<option>Penang</option>
<option>Kedah</option>
<option>Perak</option>
<option>Kelantan</option>
<option>Terengganu</option>
<option>Pahang</option>
<option>Selangor</option>
<option>Kuala Lumpur</option>
<option>Negeri Sembilan</option>
<option>Melaka</option>
<option>Johor</option>
<option>Labuan</option>
<option>Sabah</option>
<option>Sarawak</option>
</select></td>
</tr>
<td colspan="3"><div align="center">
<input type=hidden name=act value=adduser>

<input name="Search" type="submit" id="Search" value="Search">
</div></td>
</table>
</form>
<p><img src="image/bottom%20banner.jpg" width="955" height="46"></p>
</body>
</html>[/HTML]


PHP CODE for search engine
[PHP]<?php
//required file for database connection
require("database.php");
if (isset($_POST['keyword'])) {
$keyword = mysql_real_escape_string($_POST["keyword"]);
$category=mysql_real_escape_string($_POST["jobCategory"]);
$location=mysql_real_escape_string($_POST["jobLocation"]);

echo"<p align=center><center><font face='Arial' size='3'>Search Results</p>";
//An error given when they did not enter a keyword.
if ($keyword== "") {
echo "<p align=center><font face='Arial' size='2'>Opps.. You forgot enter a keyword(s)";
echo"<br><br><br><a href='jobsearch.php? '><font face='Arial' size='2'>Back</a>";

exit;
}

$sql="SELECT * FROM job WHERE jobCategory like '$jobCategory' AND jobLocation like '$jobLocation' AND jobTitle LIKE '%$keyword%' OR jobType LIKE '%$keyword%'OR jobPosition LIKE'%$keyword%'";

$anymatches = @mysql_num_rows($data);
if ($anymatches == 0)
{
echo "<center><font face='Arial' size='2'> Sorry, no job found.</center><br><br>";
echo"<br><br><br><a href='jobsearch.php? '><font face='Arial' size='2'>Back</a>";

exit();

}

$bgcolor="#f1f1f1";
echo "<table border='1'align=center>";
echo"
<TABLE width=70% align=center cellpadding=0 cellspacing=0> <tr>

<td bgcolor='dfdfdf' >&nbsp;<font face='arial' color='#000000' size='3'>Job Title</font></td>
<td bgcolor='dfdfdf' >&nbsp;<font face='arial' color='#000000' size='3'>Company</font></td>
<td bgcolor='dfdfdf' >&nbsp;<font face='arial' color='#000000' size='3'>Location</font></td></tr>
<td bgcolor='dfdfdf' >&nbsp;<font face='arial' color='#000000' size='3'>Date Posted</font></td></tr>

</tr>";
$counter = 0;
while($result = @mysql_fetch_array( $data )){
if ($counter == 3) {


$counter = 0;
}

if($bgcolor=='#f1f1f1'){$bgcolor='#ffffff';}
else{$bgcolor='#f1f1f1';}

echo "<tr><td align=left bgcolor=$bgcolor id='title'><a href='jobsearch_result.php?id={$result['ID']}'><font face='Arial' size='2'>{$result['jobTitle']}</a></td>
<td align=left bgcolor=$bgcolor id='title'><font face='Arial' size='2'>{$result['companyName']}</td>
<td align=left bgcolor=$bgcolor id='title'><font face='Arial' size='2'>{$result['jobLocation']}</td>
<td align=left bgcolor=$bgcolor id='title'><font face='Arial' size='2'>{$result['datePosted']}</td>
</tr>";
$counter = $counter + 1;
}

echo "</table>"; echo"<font face='Arial' size='2'>Keyword: " .$keyword;
echo"<br><br><br><a href='jobsearch.php? '><font face='Arial' size='2'>Back</a>";
}



?> [/PHP]
Jan 31 '07 #1
Share this Question
Share on Google+
19 Replies


Motoma
Expert 2.5K+
P: 3,235
Below is my search engine for job portal which jobseeker can find the job through quick search. But it cant work... Is it mysql query got problem?? Thanx..

Interface
[HTML]<html>
<head>
<title>UMS e-Job Portal</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
background-color: #FFFFFF;
}
body,td,th {
color: #000000;
}
a:link {
color: #FFFFFF;
}
a:visited {
color: #FFFFFF;
}
a:hover {
color: #CCCCCC;
}
a:active {
color: #CCCCCC;
}
-->
</style></head>

<body bgcolor="#FFFFFF" text="#000000">
<form name="search job" method="post" action="jobsearch_act.php">
<p>&nbsp;</p>

<table width="600" border="0">
<tr>
<td colspan="3"><font color="#000000"><strong>QUICK SEARCH</strong></font></td>
</tr>
<tr>
<td width="217"><font color="#000000">Keyword(s)</font><font color="#000000">&nbsp;</font></td>
<td width="30"><div align="center"><strong>:</strong></div></td>
<td width="339"><input name="keyword" type="text" maxlength="30"></td>
</tr>
<tr>
<td><font color="#000000">Job Category</font> </td>
<td><div align="center"><strong>:</strong></div></td>
<td><select name="jobCategory">
<option selected></option>
<option>Accounting</option>
<option>Advertising</option>
<option>Agriculture</option>
<option>Banking</option>
<option>Biotechnology</option>
<option>Chemical Eng</option>
<option>Chemistry</option>
<option>Clerical/Admin</option>
<option>Customer Service</option>
<option>Education</option>
<option>Electronics Eng</option>
<option>Food Tech</option>
<option>General Workers</option>
<option>Graphics</option>
<option>Healthcare</option>
<option>Hotel/Food</option>
<option>Human Resources</option>
<option>IT/Computer</option>
<option>Journalist/Editor</option>
<option>Manufacturing</option>
<option>Marketing</option>
<option>Mechanical Eng</option>
<option>Media/Entertain</option>
<option>Personal Care</option>
<option>Publishing</option>
<option>Purchasing</option>
<option>Quantity Survey</option>
<option>Sales</option>
<option>Science/Tech</option>
<option>Secretarial</option>
<option>Social Services</option>
<option>Training</option>
<option>Others</option>
</select></td>
</tr>
<tr>
<td><font color="#000000">Job Location</font></td>
<td><div align="center"><strong>:</strong></div></td>
<td><select name="jobLocation">
<option selected></option>
<option>Perlis</option>
<option>Penang</option>
<option>Kedah</option>
<option>Perak</option>
<option>Kelantan</option>
<option>Terengganu</option>
<option>Pahang</option>
<option>Selangor</option>
<option>Kuala Lumpur</option>
<option>Negeri Sembilan</option>
<option>Melaka</option>
<option>Johor</option>
<option>Labuan</option>
<option>Sabah</option>
<option>Sarawak</option>
</select></td>
</tr>
<td colspan="3"><div align="center">
<input type=hidden name=act value=adduser>

<input name="Search" type="submit" id="Search" value="Search">
</div></td>
</table>
</form>
<p><img src="image/bottom%20banner.jpg" width="955" height="46"></p>
</body>
</html>[/HTML]


PHP CODE for search engine
[PHP]<?php
//required file for database connection
require("database.php");
if (isset($_POST['keyword'])) {
$keyword = mysql_real_escape_string($_POST["keyword"]);
$category=mysql_real_escape_string($_POST["jobCategory"]);
$location=mysql_real_escape_string($_POST["jobLocation"]);

echo"<p align=center><center><font face='Arial' size='3'>Search Results</p>";
//An error given when they did not enter a keyword.
if ($keyword== "") {
echo "<p align=center><font face='Arial' size='2'>Opps.. You forgot enter a keyword(s)";
echo"<br><br><br><a href='jobsearch.php? '><font face='Arial' size='2'>Back</a>";

exit;
}

$sql="SELECT * FROM job WHERE jobCategory like '$jobCategory' AND jobLocation like '$jobLocation' AND jobTitle LIKE '%$keyword%' OR jobType LIKE '%$keyword%'OR jobPosition LIKE'%$keyword%'";

$anymatches = @mysql_num_rows($data);
if ($anymatches == 0)
{
echo "<center><font face='Arial' size='2'> Sorry, no job found.</center><br><br>";
echo"<br><br><br><a href='jobsearch.php? '><font face='Arial' size='2'>Back</a>";

exit();

}

$bgcolor="#f1f1f1";
echo "<table border='1'align=center>";
echo"
<TABLE width=70% align=center cellpadding=0 cellspacing=0> <tr>

<td bgcolor='dfdfdf' >&nbsp;<font face='arial' color='#000000' size='3'>Job Title</font></td>
<td bgcolor='dfdfdf' >&nbsp;<font face='arial' color='#000000' size='3'>Company</font></td>
<td bgcolor='dfdfdf' >&nbsp;<font face='arial' color='#000000' size='3'>Location</font></td></tr>
<td bgcolor='dfdfdf' >&nbsp;<font face='arial' color='#000000' size='3'>Date Posted</font></td></tr>

</tr>";
$counter = 0;
while($result = @mysql_fetch_array( $data )){
if ($counter == 3) {


$counter = 0;
}

if($bgcolor=='#f1f1f1'){$bgcolor='#ffffff';}
else{$bgcolor='#f1f1f1';}

echo "<tr><td align=left bgcolor=$bgcolor id='title'><a href='jobsearch_result.php?id={$result['ID']}'><font face='Arial' size='2'>{$result['jobTitle']}</a></td>
<td align=left bgcolor=$bgcolor id='title'><font face='Arial' size='2'>{$result['companyName']}</td>
<td align=left bgcolor=$bgcolor id='title'><font face='Arial' size='2'>{$result['jobLocation']}</td>
<td align=left bgcolor=$bgcolor id='title'><font face='Arial' size='2'>{$result['datePosted']}</td>
</tr>";
$counter = $counter + 1;
}

echo "</table>"; echo"<font face='Arial' size='2'>Keyword: " .$keyword;
echo"<br><br><br><a href='jobsearch.php? '><font face='Arial' size='2'>Back</a>";
}



?> [/PHP]
What doesn't work about this? Please elaborate. Do you get any errors appearing?
Jan 31 '07 #2

100+
P: 127
When i insert the keyword, job category and job location, it will show:

Sorry, no job found.


The job is already in database, but the result is can't find the job, what is the problem??

Thanks..:)
Feb 1 '07 #3

100+
P: 127
Could someone tell me what is the problem of my search engine.. I really can't find the problem.. Thanks..
Feb 1 '07 #4

ak1dnar
Expert 100+
P: 1,584
To get a search result belongs to your search criteria you should have
at least one value in the JOB table for each an every input that
you passing from the form. why i am saying like that actually, your
sql query it contains with AND operators.

for a example see this: [This is your Query]

SELECT * FROM job WHERE jobCategory like 'IT/Computer'
AND jobLocation like 'Melaka' AND jobTitle LIKE '%programmer%'
OR jobType LIKE '%programmer%'OR jobPosition LIKE'%programmer%'


And also Note that %% are Missing.Try like this try to Print the $sql
value as i did here.
Then Manually try to Execute the values from the Table by using the SQL query window.
If you getting a out put you are ready to fly.
[PHP]
//Your Result Area
echo $sql;
//Your Result Area
[/PHP]
Feb 1 '07 #5

100+
P: 127
my search engine is list menu, is it got simple ways to code the sql query?? Because is quick a lot sql query need to code..
Is it really need to code like this??

[PHP]
SELECT * FROM job WHERE jobCategory like 'IT/Computer'
AND jobLocation like 'Melaka' AND jobTitle LIKE '%programmer%'
OR jobType LIKE '%programmer%'OR jobPosition LIKE'%programmer%'
[/PHP]
Feb 1 '07 #6

ak1dnar
Expert 100+
P: 1,584
I got this Nice Script from Ronald.
I have done modification for the script that suited for you.

before you start In HTML List menus do the modifaication like this for better performance of the script.
[HTML]
<!-- Do it for Rest of the Option values-->
<option value="Others" >Others</option>
[/HTML]

No use of putting this "mysql_real_escape_string" for list menus.But put it to the text input box.

Here is the PHP:
Do the Modification as u wish.If u need you can pass AND instead of OR keyword here.If You passing or all the related data will list.

[PHP]
$keyword = mysql_real_escape_string($_POST["keyword"]);
$category=$_POST['jobCategory'];
$location=$_POST["jobLocation"];

$string = array();
$where = "";
if (isset($_POST["keyword"]) AND !empty($_POST["keyword"]))
$string[] = " jobTitle LIKE '%".$_POST["keyword"]."%' ";
if (isset($_POST["keyword"]) AND !empty($_POST["keyword"]))
$string[] = " jobType LIKE '%".$_POST["keyword"]."%' ";
if (isset($_POST["keyword"]) AND !empty($_POST["keyword"]))
$string[] = " jobPosition LIKE '%".$_POST["keyword"]."%' ";
if (isset($_POST["jobCategory"]) AND !empty($_POST["jobCategory"]) AND ($category != Others))
$string[] = " jobCategory LIKE '%".$_POST["jobCategory"]."%' ";
if (isset($_POST["jobLocation"]) AND !empty($_POST["jobLocation"]))
$string[] = " jobLocation LIKE '%".$_POST["jobLocation"]."%' ";
if (!empty($string))
$where = " WHERE ".implode("OR", $string);// OR/AND


$sql="SELECT * FROM job $where";
// Call for this $sql
[/PHP]

I couldn't test it against database, becoz i dont like to create tables for u and give the solution. Better to POST SQL table structures [Coding] also next time.
Feb 1 '07 #7

100+
P: 127
Thanks for your help but i have copy the php code as you showed me, but it still can not work... The result show that no job found.. I really no idea for it.. My php code as below:
[PHP]
<?php
//required file for database connection
require("database.php");
if (isset($_POST['keyword'])) {
$keyword = mysql_real_escape_string($_POST["keyword"]);
$jobCategory=$_POST["jobCategory"];
$jobLocation=$_POST["jobLocation"];

$string = array();
$where = "";
if (isset($_POST["keyword"]) AND !empty($_POST["keyword"]))
$string[] = " jobTitle LIKE '%".$_POST["keyword"]."%' ";
if (isset($_POST["keyword"]) AND !empty($_POST["keyword"]))
$string[] = " jobType LIKE '%".$_POST["keyword"]."%' ";
if (isset($_POST["keyword"]) AND !empty($_POST["keyword"]))
$string[] = " jobPosition LIKE '%".$_POST["keyword"]."%' ";
if (isset($_POST["jobCategory"]) AND !empty($_POST["jobCategory"]) AND ($category != Others))
$string[] = " jobCategory LIKE '%".$_POST["jobCategory"]."%' ";
if (isset($_POST["jobLocation"]) AND !empty($_POST["jobLocation"]))
$string[] = " jobLocation LIKE '%".$_POST["jobLocation"]."%' ";
if (!empty($string))
$where = " WHERE ".implode("OR", $string);// OR/AND


$sql="SELECT * FROM job $where";
// Call for this $sql


echo"<p align=center><center><font face='Arial' size='3'>Search Results</p>";
//An error given when they did not enter a keyword.
if ($keyword== ""||$jobCategory==""||$jobLocation=="") {
echo "<p align=center><font face='Arial' size='2'>You are missing some required fields";
echo"<br><br><br><a href='jobsearch.php? '><font face='Arial' size='2'>Back</a>";

exit;
}

$anymatches = @mysql_num_rows($data);
if ($anymatches == 0)
{
echo "<center><font face='Arial' size='2'> Sorry, no job found.</center><br><br>";
echo"<br><br><br><a href='jobsearch.php? '><font face='Arial' size='2'>Back</a>";

exit();

}

$bgcolor="#f1f1f1";
echo "<table border='1'align=center>";
echo"
<TABLE width=70% align=center cellpadding=0 cellspacing=0> <tr>

<td bgcolor='dfdfdf' >&nbsp;<font face='arial' color='#000000' size='3'>Job Title</font></td>
<td bgcolor='dfdfdf' >&nbsp;<font face='arial' color='#000000' size='3'>Company</font></td>
<td bgcolor='dfdfdf' >&nbsp;<font face='arial' color='#000000' size='3'>Location</font></td></tr>
<td bgcolor='dfdfdf' >&nbsp;<font face='arial' color='#000000' size='3'>Date Posted</font></td></tr>

</tr>";
$counter = 0;
while($result = @mysql_fetch_array( $data )){
if ($counter == 3) {


$counter = 0;
}

if($bgcolor=='#f1f1f1'){$bgcolor='#ffffff';}
else{$bgcolor='#f1f1f1';}

echo "<tr><td align=left bgcolor=$bgcolor id='title'><a href='jobsearch_result.php?id={$result['ID']}'><font face='Arial' size='2'>{$result['jobTitle']}</a></td>
<td align=left bgcolor=$bgcolor id='title'><font face='Arial' size='2'>{$result['companyName']}</td>
<td align=left bgcolor=$bgcolor id='title'><font face='Arial' size='2'>{$result['jobLocation']}</td>
<td align=left bgcolor=$bgcolor id='title'><font face='Arial' size='2'>{$result['datePosted']}</td>
</tr>";
$counter = $counter + 1;
}

echo "</table>"; echo"<font face='Arial' size='2'>Keyword: " .$keyword;
echo"<br><br><br><a href='jobsearch.php? '><font face='Arial' size='2'>Back</a>";
}



?>
[/PHP]

This is my table and datatype
Tablename: job
job_ID int(10) PRI NULL auto_increment
company_ID int(10) 0
companyName varchar(30)
contactName varchar(30)
emailAdd varchar(50)
contactNum varchar(11)
contactAdd varchar(100)
jobTitle varchar(30)
jobType varchar(30)
jobCategory varchar(30)
jobPosition varchar(30)
jobLocation varchar(30)
mRequirement blob
jobDescription blob
datePosted date 0000-00-00
Feb 1 '07 #8

100+
P: 127
What is the problem with my search engine, someone know what is the problem with my code??? Please help me to solve it....
Really thanks..
Feb 1 '07 #9

Atli
Expert 5K+
P: 5,058
Hi.

Do you ever query the database with the $sql you created?

If so I'm not seing it :P
Feb 1 '07 #10

100+
P: 127
Sorry, i'm a newbie, i don't really understand what you mean...
Can u explain in more details...:)
Feb 1 '07 #11

Atli
Expert 5K+
P: 5,058
I see you create a query and use the mysql_num_row function.

What I dont see is where you acctually send the query to the database and get the results.

This might explain better

[PHP]// 1. Create query
$SQL = "SELECT * FROM MyTable";

// 2. Query database and get results
$RESULT = mysql_query($SQL);

// 3. Count rows
echo "I have ". mysql_num_rows($RESULT) ." rows in my table :D";[/PHP]

You have stepps 1 and 3 but I dont see stepp 2 anywhere
Feb 1 '07 #12

Motoma
Expert 2.5K+
P: 3,235
Sorry, i'm a newbie, i don't really understand what you mean...
Can u explain in more details...:)
In your code, you create an SQL query, and store it to the $sql variable, however, you never actually execute the SQL query in this code.
Feb 1 '07 #13

100+
P: 127
I have add the php code regarding your suggestion, but it still display the message: No job found... And with the echo $sql; it will print the sql query in the page, but not call the database out... So, what should i do or what php code should i add again to make it work...

PHP Code
[PHP]
$sql="SELECT * FROM job $where";
// Call for this $sql

if(!empty($keyword)&&!empty($jobCategory)&&!empty( $jobLocation)){
$result = mysql_query($sql);

echo $sql;
}
[/PHP]
Feb 1 '07 #14

100+
P: 127
Is it anyone know what is my search engine problem??? Thanks...
Feb 2 '07 #15

Motoma
Expert 2.5K+
P: 3,235
Paste in the latest code, with your updates please.
Feb 2 '07 #16

100+
P: 127
Ok... Thank...This is my latest and update coding for search engine, but it still can not work...

[PHP]<?php

//required file for database connection
require("database.php");
if (isset($_POST['keyword'])) {
$keyword = mysql_real_escape_string($_POST["keyword"]);
$jobCategory=$_POST["jobCategory"];
$jobLocation=$_POST["jobLocation"];

echo"<p align=center><center><font face='Arial' size='3'>Search Results</p>";
//An error given when they did not enter a keyword.
if ($keyword== ""||$jobCategory==""||$jobLocation=="") {
echo "<p align=center><font face='Arial' size='2'>You are missing some required fields";
echo"<br><br><br><a href='jobsearch.php? '><font face='Arial' size='2'>Back</a>";

exit;
}


$string = array();
$where = "";
if (isset($_POST["keyword"]) AND !empty($_POST["keyword"]))
$string[] = " jobTitle LIKE '%".$_POST["keyword"]."%' ";
if (isset($_POST["keyword"]) AND !empty($_POST["keyword"]))
$string[] = " jobType LIKE '%".$_POST["keyword"]."%' ";
if (isset($_POST["keyword"]) AND !empty($_POST["keyword"]))
$string[] = " jobPosition LIKE '%".$_POST["keyword"]."%' ";
if (isset($_POST["jobCategory"]) AND !empty($_POST["jobCategory"]) AND ($category != Others))
$string[] = " jobCategory LIKE '%".$_POST["jobCategory"]."%' ";
if (isset($_POST["jobLocation"]) AND !empty($_POST["jobLocation"]))
$string[] = " jobLocation LIKE '%".$_POST["jobLocation"]."%' ";
if (!empty($string))
$where = " WHERE ".implode("OR", $string);// OR/AND


$sql="SELECT * FROM job $where";
// Call for this $sql

if(!empty($keyword)&&!empty($jobCategory)&&!empty( $jobLocation)){
$result = mysql_query($sql)
or die("Cannot execute query");;

echo $sql;
}


$anymatches = @mysql_num_rows($data);
if ($anymatches == 0)
{
echo "<center><font face='Arial' size='2'> Sorry, no job found.</center><br><br>";
echo"<br><br><br><a href='jobsearch.php? '><font face='Arial' size='2'>Back</a>";

exit();

}

$bgcolor="#f1f1f1";
echo "<table border='1'align=center>";
echo"
<TABLE width=70% align=center cellpadding=0 cellspacing=0> <tr>

<td bgcolor='dfdfdf' >&nbsp;<font face='arial' color='#000000' size='3'>Job Title</font></td>
<td bgcolor='dfdfdf' >&nbsp;<font face='arial' color='#000000' size='3'>Company</font></td>
<td bgcolor='dfdfdf' >&nbsp;<font face='arial' color='#000000' size='3'>Location</font></td></tr>
<td bgcolor='dfdfdf' >&nbsp;<font face='arial' color='#000000' size='3'>Date Posted</font></td></tr>

</tr>";
$counter = 0;
while($result = @mysql_fetch_array( $data )){
if ($counter == 3) {


$counter = 0;
}

if($bgcolor=='#f1f1f1'){$bgcolor='#ffffff';}
else{$bgcolor='#f1f1f1';}

echo "<tr><td align=left bgcolor=$bgcolor id='title'><a href='jobsearch_result.php?id={$result['ID']}'><font face='Arial' size='2'>{$result['jobTitle']}</a></td>
<td align=left bgcolor=$bgcolor id='title'><font face='Arial' size='2'>{$result['companyName']}</td>
<td align=left bgcolor=$bgcolor id='title'><font face='Arial' size='2'>{$result['jobLocation']}</td>
<td align=left bgcolor=$bgcolor id='title'><font face='Arial' size='2'>{$result['datePosted']}</td>
</tr>";
$counter = $counter + 1;
}

echo "</table>"; echo"<font face='Arial' size='2'>Keyword: " .$keyword;
echo"<br><br><br><a href='jobsearch.php? '><font face='Arial' size='2'>Back</a>";
}

?> [/PHP]
Feb 2 '07 #17

Motoma
Expert 2.5K+
P: 3,235
Here is where I think you are having problems:
[PHP]
..
$sql="SELECT * FROM job $where";
// Call for this $sql

if(!empty($keyword)&&!empty($jobCategory)&&!empty( $jobLocation)){
$result = mysql_query($sql)
or die("Cannot execute query");;

echo $sql;
}


$anymatches = @mysql_num_rows($data);
if ($anymatches == 0)
{
...
[/PHP]
You see, you are setting the result to the $result variable, but you are checking the number of rows in the $data variable. Since you haven't performed a query to fill $data, it is naturally empty, and your check fails.
You will need to use the same variable for both the mysql_query() call and the mysql_num_rows() call.
Feb 2 '07 #18

100+
P: 127
Thanks a lot, i know what is my porblem... I change the coding, now it function well... Thanks...:)
Feb 2 '07 #19

Motoma
Expert 2.5K+
P: 3,235
Thanks a lot, i know what is my porblem... I change the coding, now it function well... Thanks...:)
Glad to help.
Feb 2 '07 #20

Post your reply

Sign in to post your reply or Sign up for a free account.