Results 1 to 3 of 3

Thread: Trying to get rid of an error message

  1. #1
    Join Date
    Oct 2012
    Posts
    180
    Thanks
    22
    Thanked 1 Time in 1 Post

    Default Trying to get rid of an error message

    I am trying to set up a job search engine using careerjet's API. Everything is working fine except when the careerjet's database doesn't have jobs available for a particular query the error_log writes and posts this message:

    Warning: Invalid argument supplied for foreach() in /home1/fastjobs/public_html/index.php on line 117

    In my case line 117 is this one in the index page:

    foreach( $jobs as $job ){

    My question is is there a way to make it say a specific error message instead of a generic one when no jobs are available. Something like: Sorry, no jobs were found.

    Any help will be appreciated.

    This is the entire snippet:

    Code:
          $jobs = $result->jobs ;
    
              foreach( $jobs as $job ){
               
                $counter++;
               
                echo "<div class='job'>";
                echo "<span class='title'><a target='_blank' href='". $job->url . "'>" . $job->title . "</a></span>";
                echo "<div class='location'>" . $job->locations . "</div>";
                echo "<div class='company'>" .$job->company . "</div>";
                echo "<div class='salary'>" . $job->salary . "</div>";
                echo "<div class='date'>" . $job->date . "</div>";
                echo "<div class='description'>" . $job->description . "</div>";
                echo "</div>";
              }

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Something like:

    PHP Code:
          $jobs $result->jobs ;
        if(!
    $jobs or == count($jobs)){
            echo 
    "My custom Error Message - There ain't no Jobs Dude!";
        } else
              foreach( 
    $jobs as $job ){
               
                
    $counter++;
               
                echo 
    "<div class='job'>";
                echo 
    "<span class='title'><a target='_blank' href='"$job->url "'>" $job->title "</a></span>";
                echo 
    "<div class='location'>" $job->locations "</div>";
                echo 
    "<div class=' . . . 
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Oct 2012
    Posts
    180
    Thanks
    22
    Thanked 1 Time in 1 Post

    Default

    Thanks John. Looks simple when someone else does it. Appreciate your help!

Similar Threads

  1. Can anyone help with an error message?
    By Gemini23 in forum JavaScript
    Replies: 0
    Last Post: 01-13-2010, 07:41 PM
  2. Error Message in 3d spinning message
    By drgsb in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 05-24-2009, 06:36 AM
  3. XML error message
    By jendelaniaga in forum Dynamic Drive scripts help
    Replies: 25
    Last Post: 07-26-2008, 05:01 AM
  4. Error message...
    By confusio in forum PHP
    Replies: 4
    Last Post: 07-08-2006, 03:19 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •