Jump to content

Data not completely populating table


doctortim

Recommended Posts

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.

Link to comment
Share on other sites

<?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
}
?>

Link to comment
Share on other sites

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}

Link to comment
Share on other sites

<?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>';
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.