Darkmatter5 Posted July 25, 2008 Share Posted July 25, 2008 Here's my 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_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_array($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) { echo "<li>" .$row['job_number']. ", " .$row['job_desc']. "</li>"; } echo "</ol></td></tr></table>"; include 'library/closedb.php'; } ?> The record that I'm using to search should have 2 results, so the output should be something like. 1. 22222, something 2. 33333, nothing But the while statement keeps running and doesn't stop. Any ideas why? Link to comment https://forums.phpfreaks.com/topic/116639-help-with-looping-problem-while-statement/ Share on other sites More sharing options...
jonsjava Posted July 25, 2008 Share Posted July 25, 2008 try this: <?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_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_array($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>" .$row['job_number']. ", " .$row['job_desc']. "</li>"; } echo "</ol></td></tr></table>"; include 'library/closedb.php'; } ?> Link to comment https://forums.phpfreaks.com/topic/116639-help-with-looping-problem-while-statement/#findComment-599711 Share on other sites More sharing options...
Darkmatter5 Posted July 25, 2008 Author Share Posted July 25, 2008 It partially works. Only one of the results show up. I've noticed that if I run a mysql_fetch_array or _assoc function on $result more then once, I only get one result. If say I get ride of this section of the code. $row=mysql_fetch_array($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']; } More importantly getting rid of $row=mysql_fetch_array($result). The lower "fetch" code runs correctly. Link to comment https://forums.phpfreaks.com/topic/116639-help-with-looping-problem-while-statement/#findComment-599722 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.