Jump to content

While loop and mysql_fetch_assoc problem


Darkmatter5

Recommended Posts

Here's the problematic code.

<?php
  if(isset($_POST['LOADclient_job'])) {
    include 'library/dbconfig.php';
    include 'library/opendb.php';
                
    $query="SELECT clients.last_name, clients.first_name, clients.company_name, jobs.job_id, jobs.job_number, jobs.job_desc
      FROM byrnjobdb.clients
      INNER JOIN byrnjobdb.jobs
      ON byrnjobdb.clients.client_id = byrnjobdb.jobs.client_id
      WHERE byrnjobdb.clients.client_id = $client
      ORDER BY jobs.job_number ASC";
    $result=mysql_query($query);
    $row=mysql_fetch_assoc($result);
    if(empty($row['company_name'])) {
      $fullname=$row['last_name']. ", " .$row['first_name'];
    } else {
      $fullname=$row['last_name']. ", " .$row['first_name']. " of " .$row['company_name'];
    }
    echo "<table width='650' border='0'>";
    echo "<tr>";
    echo "<td colspan='2' class='row_title' align='left'>Jobs associated with '" .$fullname. "' as the client.";
    echo "</tr>";
    echo "<tr>";
    echo "<td colspan='2' class='row_description' align='left'>";
    echo "<ol>";
    while($row = mysql_fetch_assoc($result)) {
      echo "<li><a href='editjobs.php?=" .$row['job_id']. "' >" .$row['job_number']. "</a>, " .$row['job_desc']. "</li>";
    }
    echo "</ol></td></tr></table>";
                
    include 'library/closedb.php';
  }
?>

 

When it's run and a client with multiple jobs associated with them is selected only the first result is echoed. Now if I run the following code I get all job results, but obviously the list title isn't generated.

<?php
  if(isset($_POST['LOADclient_job'])) {
    include 'library/dbconfig.php';
    include 'library/opendb.php';
                
    $query="SELECT clients.last_name, clients.first_name, clients.company_name, jobs.job_id, jobs.job_number, jobs.job_desc
      FROM byrnjobdb.clients
      INNER JOIN byrnjobdb.jobs
      ON byrnjobdb.clients.client_id = byrnjobdb.jobs.client_id
      WHERE byrnjobdb.clients.client_id = $client
      ORDER BY jobs.job_number ASC";
    $result=mysql_query($query);
/*    $row=mysql_fetch_assoc($result);
    if(empty($row['company_name'])) {
      $fullname=$row['last_name']. ", " .$row['first_name'];
    } else {
      $fullname=$row['last_name']. ", " .$row['first_name']. " of " .$row['company_name'];
    }*/
    echo "<table width='650' border='0'>";
    echo "<tr>";
    echo "<td colspan='2' class='row_title' align='left'>Jobs associated with '" .$fullname. "' as the client.";
    echo "</tr>";
    echo "<tr>";
    echo "<td colspan='2' class='row_description' align='left'>";
    echo "<ol>";
    while($row = mysql_fetch_assoc($result)) {
      echo "<li><a href='editjobs.php?=" .$row['job_id']. "' >" .$row['job_number']. "</a>, " .$row['job_desc']. "</li>";
    }
    echo "</ol></td></tr></table>";
                
    include 'library/closedb.php';
  }
?>

 

What's going on??

I tried that, but the output is just the first character from each cell of the array. I'm totally confused as to how it's coming up with this output.

 

Here's an example of what it's doing:

last_name: smith

first_name: john

company_name: nothing

job_id: 5

job_number: 12345

job_desc: survey

 

The output is: sjn51s

As you can see it's the first character of each cell of the array. What's going on?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.