从MySQL表中拉出4个表行并在页面上用PHP显示?

时间:2013-05-29 00:41:48

标签: php mysql

我需要简单地从MySQL表中拉出4个表行并在页面上用PHP显示?有人可以帮我解决这个问题...我只有:

include_once ('db.php');

$link = mysql_connect($db,$user,$pass) or die("Can't connect to Database");
mysql_select_db($table,$link);

/* Main */
$query="SELECT * FROM $subtable ORDER BY id DESC LIMIT 1";
$result=mysql_query($query);

HTML

<?php echo mysql_result('tablerow'); ?>

1 个答案:

答案 0 :(得分:1)

以下是一些可以帮助您入门的代码!

$link = mysql_connect($host,$user,$pass,$table);

$loop = mysql_query($link,"SELECT * FROM $subtable ORDER BY id DESC LIMIT 4");

while ($row = mysql_fetch_array($loop))
{
 echo $row['yourrow']."<br/>";
}

mysql_close($link);

只需将yourrow替换为您要打印的行的名称!不要忘记设置变量$host $user $pass$table