how do i limit my search result to be echod

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
adsegzy
Forum Contributor
Posts: 184
Joined: Tue Jul 28, 2009 9:26 am

how do i limit my search result to be echod

Post by adsegzy »

Hello Friends,

I am developing a website where vacancies can be posted. Enployers will have to fill a form which include number of I weeks the vacancies would be available. I have a table in my database where the entries will be kept. I have converted the number of weeks the vacancies will be available to days and have added it to the date which the vacancy is posted to get the date the vacancy will expire. On my home page where the visitors can view the avalable vacancies, I tried subtract today's (everyday) date from the expiry date and echo the result of vacancies which are still available. i used the code below but it didn't work

Code: Select all

<?
$table_name=vacancies;
$column_name=end_date;
$date=date("d M y", time());
$getvac=mysql_query("SELECT * FROM $table_name WHERE $column_name - $date > 0 ORDER BY id DESC");
if(mysql_num_row($getvac)==0)
echo "NO VACANCY IS AVAILABLE.";
else
{$result=mysql_fetch_array($getvac);
...}
?>
The end date is also in this format date("d M y"). But am receiving this error
Warning: mysql_num_rows(): supplied argument is not a valid Mysql result resource
Pls what can i do or what are the other ways out because i want to echo only those vacancies whose end_date is greater than zero.

regards
adsegzy
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: how do i limit my search result to be echod

Post by Jade »

Try this:

Code: Select all

<?
$table_name="vacancies";
$column_name="end_date";
$date=date("d M y", time());
$getvac = mysql_query("SELECT * FROM $table_name WHERE $column_name - $date > 0 ORDER BY id DESC") or die (mysql_error());
if(mysql_num_row($getvac)==0)
  echo "NO VACANCY IS AVAILABLE.";
else
{
  $result=mysql_fetch_array($getvac);
}
?>
Post Reply