Re: mysql_fetch_assoc help
try adding $array = array(); before the while loop. this might fix the undefined variable
PHP Code:
<?php
$array = array();
while($row = mysql_fetch_assoc( $result)){
$array[] = $row; }
array2table($array,600); // Will output a table of 600px width
?>
also, since this is all PHP code, you can get rid of those unnecessary <?PHP ?> TAG.
PHP Code:
<?PHP
include("dbandy.php");
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
$dbname = 'db_andrewb';
mysql_select_db($dbname)or die('error finding DB');
$qstring = $_SERVER['QUERY_STRING'];
$qstring = str_replace('queries=', '',$qstring);
echo urldecode($qstring);
$query = $qstring; //if i use this it dosen't work
//$query = "Select * from students"; if i use this it works
$result = mysql_query($query);
function array2table($arr,$width)
{
$count = count($arr);
if($count > 0){
reset($arr);
$num = count(current($arr));
echo "<table align=\"center\" border=\"1\"cellpadding=\"5\" cellspacing=\"0\" width=\"$width\">\n";
echo "<tr>\n";
foreach(current($arr) as $key => $value){
echo "<th>";
echo $key." ";
echo "</th>\n";
}
echo "</tr>\n";
while ($curr_row = current($arr)) {
echo "<tr>\n";
$col = 1;
while ($curr_field = current($curr_row)) {
echo "<td>";
echo $curr_field." ";
echo "</td>\n";
next($curr_row);
$col++;
}
while($col <= $num){
echo "<td> </td>\n";
$col++;
}
echo "</tr>\n";
next($arr);
}
echo "</table>\n";
}
}
$array = array();
while($row = mysql_fetch_assoc($result)){
$array[] = $row;
}
array2table($array,600); // Will output a table of 600px width
?>
it won't fix anything, but just clean the code, hope that helped