To display some data from a mysql table the usual method that I’m used to is:
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo $row['FIELD'];
}
Now to make things more dynamic I’ve tried this:
/* $array carries list of column names like 'FIELD'. In this case its the only one
* $result stores whatever the query like "SELECT * FROM TABLE1" returned
*/
function dosomething($array, $result)
{
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
for($i = 0; $i < sizeof($array); $i++) //gets size of $array and loops
{
echo $row["'".$array[$i]."'"]; //should read $row['FIELD'] yes?
}
}
}
The code above shows nothing. Data exists. echo $row[‘FIELD’]; returns something. but the line
echo $row["'".$array[$i]."'"];
gives nothing in return. I’ve tried an alternate like-
echo $row[$array[$i]];
still nothing.
I hope I was able to make the reader understand the problem. How can I put an array in he mysql_fetch_array type array?
Any suggestions are welcome.
the fields to display you have to define in the query
and there is no point in having such a function like your dosomething()