Home >Backend Development >PHP Tutorial >mysql_query老是查不到数据
mysql_query总是查不到数据
<br /><?php<br />$dbhost = "localhost";<br />$dbuser = "root";<br />$dbpassword = "";<br />$dbdatabase = "blogtastic";<br /><br />$config_blogname = "Funny old world";<br />$config_author = "Pengsc";<br /><br />$config_basedir = "htpp://127.0.0.1/blogtastic/";<br />?><br /><br /><?php<br />//require("config.php"); //include config.php<br />$db = mysql_connect($dbhost, $dbuser, $dbpassword);<br />if(!$db)<br />{<br /> die('Could not connect: ' . mysql_error());<br />}<br /><br />$db_selected = mysql_select_db($dbdatabase, $db);<br />if (!$db_selected)<br />{<br /> die ("Can not use $dbdatabase : " . mysql_error());<br />}<br />?><br /><br /><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><br /><html><br /><head><br /><title><?php echo $config_blogname; ?></title><br /><link rel="stylesheet" href="stylesheet.css" type="text/css" /><br /></head><br /><br /><body><br /><!--div居中--><br /><div id="header"><br /><h1><?php echo $config_blogname; ?></h1> <!--设置网页中的标题文字,被设置的文字将以黑体或粗体的方式显示在网页中--><br />[<a href="index.php">home</a>] <!--<a></a>这个标签是HTML中超链接, 输出结果是[home]--><br /></div><br /><br /><div id="main"><br /><!--the other mark, in footer--><br /><br /><?php<br />$sq1 = "SELECT entries.*, categories.cat From entries, categories<br /> WHERE entries.cat_id = categories.id<br /> ORDER BY dateposted DESC<br /> LIMIT 1;";<br />mysql_query("set names 'utf8'"); //数据库输出编码 应该与你的数据库编码保持一致.南昌网站建设公司百恒网络PHP工程师建议用UTF-8 国际标准编码. <br />$result = mysql_query($sql, $db);//执行一条 MySQL 查询<br />if($result)<br />{<br /> echo "<p>ctergories and entries</p>";<br /> echo "<p>ctergories and entries</p>";<br /> echo "<p>ctergories and entries</p>";<br /> echo "<p>ctergories and entries</p>";<br /> echo "<p>ctergories and entries</p>";<br /> $row = mysql_fetch_assoc($result); //从结果集中取得一行作为关联数组<br /> <br /> print_r($row);<br /> <br /> echo "<h2><a href=‘viewentry.php?id=" . $row['id']<br /> . "'>" . $row['subject'] . "</a></h2><br />";<br /> echo "<i>In <a href='viewcat.php?id" . $row['cat_id']<br /> . "‘>" . $row['cat'] . "</a> - Posted on " . date("D jS F Y g.iA", strtotime($row['dateposted'])) . "</i>";<br /> echo "<p>";<br /> echo nl2br($row['body']);<br /> echo "</p>";<br />}<br />else<br />{<br /> print_r($row);<br /> echo "no ctergories and entries";<br />}<br /><br />?><br /><br /></div><br /><br /><div id="footer"><br /><br /> © <?php echo $config_author; ?><br /></div><br /><br /></body><br /></html><br />