henk.io
henk.io

Reputation: 306

Adding website content from SQL database

I am very new to PHP so this might be a silly question to some but my website is currently broken up into includes and I have managed to establish a database connection but i would like the content in the "about" page to come from a SQL database and not be static HTML. My question is how would I actually go about writing the PHP to get the content from the database and have it displayed in the relevant tag?

Here is a link to the site: http://midway-media.net/3/about.php

This is my code at the moment:

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

Upvotes: 0

Views: 258

Answers (1)

Justgrant2009
Justgrant2009

Reputation: 603

Are you familiar with SQL? If you know how to make your query to pull the information you want. You can simply query it to a php variable:

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

Then in your html, where ever you want that text:

<?php echo $variable1; ?>

That should print out the contents of the variable (and in effect, the query), into your html.

Upvotes: 1

Related Questions