开发者

simplest code to spill a mysql table

I have a table called table1 in mysql. I want to output it all, each row on a separate line. It has 4 columns, id,a,b,c.

Whats the shortest php code to just get it all out? I'm up开发者_StackOverflow中文版 to here:

$a=mysql_query("SELECT * FROM table1");
$b=mysql_fetch_assoc($a);

...what next?

What if their are an unknown number of columns?


echo `mysql --html -e "SELECT * FROM database.table1"`;


$a=mysql_query("SELECT * FROM table1");
while($row = mysql_fetch_assoc($a)){
  echo $row['id'].$row['a'].$row['b'].$row['c'].'<br />';
}

Update in relation to this questions comment:

$a=mysql_query("SELECT * FROM table1");
while($row = mysql_fetch_assoc($a)){
  foreach($row as $value)
    echo $value;
  echo '<br />';
}


<table>
<?php
while($b = mysql_fetch_row($a)) {
    echo('<tr>');
    foreach($b as $str) {
        echo("<td>$str</td>");
    }
    echo('</tr>');
}
?>
</table>


Prints the array recursively:

$a = mysql_query("SELECT * FROM table1");
$b = mysql_fetch_array($a);
echo "<pre>";
print_r($b);
echo "</pre>";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜