Jump to content

For Each Loop Problem When Echoing Database Table


jjacquay712

Recommended Posts

im using this code to echo a database table into an html table. it works, but it echos out 7x as many columns as i need, its hard to explain, so heres a demo: http://johnj.gknu.com/post.php

Here is my Code:

<table width="200" border="1">
<?php
mysql_connect(hidden);
mysql_select_db(hidden);
$query = mysql_query("SELECT * FROM comments");
$query1 = mysql_query("SELECT * FROM comments");

echo '<tr>';
while ($array1 = mysql_fetch_array($query1)) {
foreach ($array1 as $value1 => $lol1) {
	if ( !is_int($value1) ) {
		echo '<td>' . $value1 . '</td>';
	}
}
}
echo '</tr>';

while ($array = mysql_fetch_array($query)){
echo '<tr>';
foreach ($array as $value => $lol) {
	if ( !is_int($value) ) {
		echo  '<td>' . $lol . '</td>';
	}
}
echo '</tr>';
}

?>
</table>

 

any reasons it might be doing this?

Thanks, John

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.