从 SQL 数据库添加网站内容


Adding website content from SQL database

我对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";?>

你熟悉 SQL 吗? 如果您知道如何进行查询以提取所需的信息。 您可以简单地将其查询到 php 变量:

$variable1 = mysql_query("Your SQL query goes here");

然后在您的 html 中,您想要该文本的任何位置:

<?php echo $variable1; ?>

这应该将变量的内容(实际上是查询)打印到您的 html 中。