Darkmatter5 Posted July 28, 2008 Share Posted July 28, 2008 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?? Link to comment https://forums.phpfreaks.com/topic/117038-while-loop-and-mysql_fetch_assoc-problem/ Share on other sites More sharing options...
jake2891 Posted July 28, 2008 Share Posted July 28, 2008 since you already have the $row in the above section of the code try this instead foreach($row as $r) { echo "<li><a href='editjobs.php?=" .$row['job_id']. "' >" .$row['job_number']. "</a>, " .$row['job_desc']. "</li>"; } Link to comment https://forums.phpfreaks.com/topic/117038-while-loop-and-mysql_fetch_assoc-problem/#findComment-602048 Share on other sites More sharing options...
jake2891 Posted July 28, 2008 Share Posted July 28, 2008 changing the $row['field_name'] to $r['field_name'] etc.. Link to comment https://forums.phpfreaks.com/topic/117038-while-loop-and-mysql_fetch_assoc-problem/#findComment-602049 Share on other sites More sharing options...
Darkmatter5 Posted July 29, 2008 Author Share Posted July 29, 2008 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? Link to comment https://forums.phpfreaks.com/topic/117038-while-loop-and-mysql_fetch_assoc-problem/#findComment-602613 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.