我对PHP很陌生,所以对某些人来说这可能是一个愚蠢的问题,但我的网站目前已分解为包含,我已设法建立数据库连接,但我希望“关于”页面中的内容来从SQL数据库而不是静态HTML。 我的问题是我如何实际编写PHP以从数据库中获取内容并将其显示在相关标记中?
以下是该网站的链接:http://midway-media.net/3/about.php
这是我目前的代码:
<?php include_once "includes/scripts.php"; ?>
<?php include_once "includes/header.php";?>
<?php
$db_host = "localhost";
$db_user = "root";
$db_pass = "";
$db_name = "camelhorse";
$db_error_one= "<h1>Could not connect to database</h1>";
$db_error_two= "<h1>Database 'camelhorse' is not available</h1>";
@mysql_connect ($db_host,$db_user,$db_pass) or die ($db_error_one);
@mysql_select_db("$db_name") or die ("$db_error_two");
?>
<img id="logo_full_name" src="images/camelhorst_logo_full.png" alt="Camelhorse Creative Studio">
<article>
<img src="images/long_line_single_column.png" style="margin:10px auto 0px auto;">
<h1>ABOUT OUR COMPANY</h1>
<p>Camelhorse is a Creative Agency is multi disciplinary creative partner, specializing in Brand Development and with sub divisions in web development, communication design and photography. We provide effective solutions for various marketing and communication requirements.<br><br>
Companies today are looking for creative partners that will supply them with tangible results, ensuring their brand or products succeed against their competition in this tough and competitive economic environment. We offer clients the edge in their respective industries, by truly understanding their brand through extensive market related research, and strategically positioning their brand or products correctly in the market. We are able to make brands and products stand out from the clutter and help them reach consumers in the most effect way.<br><br>
Camelhorse Creative Agency offers a complete solution from conceptualization of an idea to production, and supplying a finished product to our clients when it comes to Brand Development, Brand Activation, Point-of-Sale, Digital Implementation, Tactical and Strategic development. Contact us today and let see what we can do for your brand.</p>
<img src="images/three_column_grid_line.png" alt="line">
<h2>MISSION</h2>
<p>Camelhorse’s mission is to provide the best creative service in the industry is a fun and humoristic way we approach business seriously and aspire to be the most creative and dynamic media house with one stop in house services for all your branding needs.</p>
<h2>VISION</h2>
<p>We see ourselves a industry leading creative agency in the near future offering the most contemporary designs and development techniques. We aspire to this daily with a dedicated team.</p>
</article>
<?php include_once "includes/footer.php";?>
答案 0 :(得分:1)
您熟悉SQL吗?如果您知道如何使查询提取所需信息。您可以简单地将其查询为php变量:
$variable1 = mysql_query("Your SQL query goes here");
然后在你的html中,你想要那个文本:
<?php echo $variable1; ?>
那应该将变量的内容(实际上是查询)打印到你的html中。