doctortim Posted December 11, 2007 Share Posted December 11, 2007 Hi All, Basically I have records with 5 data fields. I want to display this data in a nice table with the first row of the table holding four cells - which is where the first four fields are outputted to. There are a few blank rows for spacing following that first row. Then a nested table of just a single cell sits in the fourth row, that holds the output of the much larger "article" field. Basically I'm using the following code to set things up: <?php include_once("include/connect_sql.inc.php"); ?> <?php $sql = 'SELECT * FROM blogprofessional ORDER BY created DESC'; $result = mysql_query($sql) or die(mysql_error()); $i=0; $article_id = mysql_result($result,$i,"article_id"); $issue_no = mysql_result($result,$i,"issue_no"); $issue_date = mysql_result($result,$i,"issue_date"); $focus = mysql_result($result,$i,"focus"); $toc = mysql_result($result,$i,"toc"); $article = mysql_result($result,$i,"article"); ?> In order to loop another table for each article I use: <?php while($row = mysql_fetch_assoc($result)) { ?> ...placing this part of the while loop right before the opening table tag, and placing... <?php } ?> ...after the closing table tag. In each cell that I want my field's data to appear I use: <?php echo $row['issue_no']; ?> What I see in the browser is the first four data fields outputting into their respective cells of the first row. However my single cell nested table in row 4 is not producing the result of it's echo statement. The cell just appears blank. Why is this happening?? I hope it isn't because of the nested table, i need it for layout purposes. Quote Link to comment Share on other sites More sharing options...
DyslexicDog Posted December 11, 2007 Share Posted December 11, 2007 <?php include_once("include/connect_sql.inc.php"); ?> <?php $sql = 'SELECT * FROM blogprofessional ORDER BY created DESC'; $result = mysql_query($sql) or die(mysql_error()); for($i = 0; $i > mysql_num_rows($result); $i++){ $article_id = mysql_result($result,$i,"article_id"); $issue_no = mysql_result($result,$i,"issue_no"); $issue_date = mysql_result($result,$i,"issue_date"); $focus = mysql_result($result,$i,"focus"); $toc = mysql_result($result,$i,"toc"); $article = mysql_result($result,$i,"article"); //table code to echo your results for each item } ?> Quote Link to comment Share on other sites More sharing options...
doctortim Posted December 12, 2007 Author Share Posted December 12, 2007 I changed the way my code was counting through the entries as you suggested. Though the way I had it was already working before, so no change in things there, still the article cell is not showing it's echo. I assume you are meaning i should close my loop with <?php } ?> after the closing </table> tag? this is what I have done. More help please...how could the first four variables be echoing fine, but the last one is not. I have tried echo $variable and echo $row['field'] to display the result and nothing. Do I still need <?php while($row = mysql_fetch_assoc($result)) { ?> Could this function be the source of my problem? Please help {Also when you tell me the code next, would it be cool to let me now where your suggested code should be placed rel. to both the doctype decleration and my table - thanks} Quote Link to comment Share on other sites More sharing options...
doctortim Posted December 12, 2007 Author Share Posted December 12, 2007 bump Quote Link to comment Share on other sites More sharing options...
mr_mind Posted December 12, 2007 Share Posted December 12, 2007 <?php include_once("include/connect_sql.inc.php"); $blog_query = mysql_query("SELECT * FROM blogprofessional ORDER BY created DESC") or die(mysql_error()); print '<table>'; while($blog_array = mysql_fetch_array($blog_query)) { $article_id = $article_array['article_id']; $article_issue_num = $article_array['issue_no']; $article_issue_date = $article_array['issue_date']; $article_focus = $article_array['focus']; $article_toc = $article_array['toc']; $article = $article_array['article']; print '<tr>'; print '<td> ' . $article_id . ' </td>'; print '<td> ' . $article_issue_num . ' </td>'; print '<td> ' . $article_issue_date . ' </td>'; print '<td> ' . $article_focus . ' </td>'; print '<td> ' . $article_toc . ' </td>'; print '<td> ' . $article . ' </td>'; print '</tr>'; } print '</table>'; ?> Quote Link to comment Share on other sites More sharing options...
doctortim Posted December 12, 2007 Author Share Posted December 12, 2007 Ok I can see that may be helpful, but can you explain what you are doing here with a little detail. Thank you kindly. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.