Forum Moderators: coopster
any way if you need display a (very) lot of columns then i understand you.
what do you think about:
if (is_array($array))
{
foreach ($array as $i -> $row)
{
$totalCols = count($row);
for ($j = 0; $j < $totalCols; $j++)
{
echo $row[$i][$j];
}
}
}
(using numerics arrays)
is only the idea, can be buggy.
<?
$username="<username>";
$password="<password>";
$database="<database>";mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM <table_name>";
$result=mysql_query($query);$num=mysql_numrows($result);
mysql_close();
echo "<b><center>Database Output</center></b><br><br>";
$i=0;
while ($i < $num) {
//use as many as necessary
$f01 = mysql_result($result,$i,"<feild1_name>");
$f02 = mysql_result($result,$i,"<feild2_name>");
$f03 = mysql_result($result,$i,"<feild3_name>");
$f04 = mysql_result($result,$i,"<feild4_name>");
$f05 = mysql_result($result,$i,"<feild5_name>");// output data
echo "$f01<br>$f02<br>$f03<br>$f04<br>$f05";
$i++;
}?>
EDIT: Wierd, it works now, but i cant figure out how...
$res = mysql_query("SELECT * FROM table WHERE id=$id",$db);
$row = mysql_fetch_array($res);
$array = Array($res);
if (is_array($array))
{
foreach ($array as $i -> $row)
{
$totalCols = count($row);
for ($j = 0; $j < $totalCols; $j++)
{
echo "".$row[$j]."<br>";
}
}
}
That gives me the correct output but what about $i and the whole array thing? yeye, as long as it works its good enough for me :) thanks everybody!
$row = mysql_fetch_array($res);
$array = Array($res);
you did a matrix (array of array), thats's why:
echo "".$row[$j]."<br>";
is better than
echo $row[$i][$j];
Only a suggest: always try to understand exactly you code is working. line by line a program gain his own life. you don't want a program untamable!