SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: job list error

  1. #1
    SitePoint Member monkeynme's Avatar
    Join Date
    Oct 2003
    Location
    Colorado Springs
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    job list error

    This is my first PHP page. I wanted to list all of the jobs in our database. I borrowed code and changed the field names to those in the MYSQL database.

    When the list outputs, there are no errors. But instead of the table listing the data, it prints the variable names. I tried using ECHO and PRINT. But neither made a difference.

    I'm sure it's probably just a punctuation thing. But I can't see it. Can someone find it in the code?

    PHP Code:
    $joblist = @mysql_query'SELECT jobID, jobTitle, jobPostdate, jobStatus
                                FROM jobs'
    );
      if (!
    $joblist) {
        die(
    '<p>Error performing query: ' mysql_error() . '</p>');
      }

      while (
    $job mysql_fetch_array($joblist)) {
        
    $jobID $job['jobID'];
        
    $title $job['jobTitle'];
        
    $date $job['jobPostdate'];
        
    $status $job['jobStatus'];
        }
        
        
    // Display the jobs
        
    print ('
        <table width="100%" (blah, blah, blah) 
    And the table setup where the data should be displayed is:

    <td>$jobID</td>
    <td>$title</td>
    <td>$date</td>
    <td>$status</td>

  2. #2
    SitePoint Addict marylin77's Avatar
    Join Date
    Aug 2003
    Location
    Spain
    Posts
    362
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try to leave out the single quotes in your associative array.
    Example:
    PHP Code:
    $jobID $job[jobID]; 
    and so on :]
    ///
    or try this:
    echo "<td>".$jobID."</td>";
    echo "<td>".$title."</td>";
    echo "<td>".$date."</td>";
    echo "<td>".$status."</td>";

  3. #3
    SitePoint Zealot nsr81's Avatar
    Join Date
    Nov 2002
    Location
    B'klyn, NY
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You will need to print the table information inside the while loop. See if this accomplishes what you are after:
    PHP Code:
    <?
    $joblist 
    = @mysql_query'SELECT jobID, jobTitle, jobPostdate, jobStatus 
                                FROM jobs'
    ); 
      if (!
    $joblist) { 
        die(
    '<p>Error performing query: ' mysql_error() . '</p>'); 
      } 
      
    // table begins here.
      
    print('<table width="100%" border="1" cellpadding="3">');
      
    // header line.
      
    print('<tr><th>ID</th><th>Title</th><th>Date</th><th>Status</th></tr>\n'); 
      
    // fetch and print jobs, one job per table row.
      
    while ($job mysql_fetch_array($joblist)) 
      { 
        
    $jobID $job['jobID']; 
        
    $title $job['jobTitle']; 
        
    $date $job['jobPostdate']; 
        
    $status $job['jobStatus']; 
        print(
    "<tr>\n");
        print(
    "<td>$jobID</td>\n");
        print(
    "<td>$title</td>\n");
        print(
    "<td>$date</td>\n");
        print(
    "<td>$status</td>\n"); 
        print(
    "</tr>\n");
      } 
         
        print (
    '</table>');
    ?>
    Nasir
    nasir.us

  4. #4
    SitePoint Zealot nsr81's Avatar
    Join Date
    Nov 2002
    Location
    B'klyn, NY
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by marylin77
    Try to leave out the single quotes in your associative array.
    Example:
    PHP Code:
    $jobID $job[jobID]; 
    and so on :]
    Although that works, but it is recommended that you should always use single/double quotes with associative arrays where the key is not an integer.

    Take a look at "Why is $foo[bar] wrong?" under "Array do's and don'ts" in PHP manual:

    http://us4.php.net/manual/en/languag...es.array.donts
    Nasir
    nasir.us


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
  •