<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>mysql</title>
	<atom:link href="http://www.yackyack.co.uk/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.yackyack.co.uk</link>
	<description>A Search Marketing Blog</description>
	<lastBuildDate>Fri, 20 Jan 2012 19:41:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>mysql</title>
		<link>http://www.yackyack.co.uk/design/how-to-build-a-database-driven-website-part-3/</link>
		<comments>http://www.yackyack.co.uk/design/how-to-build-a-database-driven-website-part-3/#comments</comments>
		<pubDate>Wed, 07 Feb 2007 14:06:34 +0000</pubDate>
		<dc:creator>robwatts</dc:creator>
				<category><![CDATA[Aff Marketing]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[websites]]></category>

		<guid isPermaLink="false">http://www.yackyack.co.uk/2007/02/07/how-to-build-a-database-driven-website-part-3/</guid>
		<description><![CDATA[Tweet In parts one and two we looked at the initial database set up, inserting data into our database using csv and sql files, layout and content issues, relative to both using our database and how we can use other providers to both add value and gain additional income revenue; as well as url and <a href='http://www.yackyack.co.uk/design/how-to-build-a-database-driven-website-part-3/'>[...]</a>


Related posts:<ol><li><a href='http://www.yackyack.co.uk/adsense/monetize-your-blog-or-website-earn-money-from-your-passions/' rel='bookmark' title='Permanent Link: Monetize your blog or website &#8211; Earn money from your passions'>Monetize your blog or website &#8211; Earn money from your passions</a></li>
<li><a href='http://www.yackyack.co.uk/blogging/promote-my-website-online-in-2008/' rel='bookmark' title='Permanent Link: Promote my website online in 2008'>Promote my website online in 2008</a></li>
<li><a href='http://www.yackyack.co.uk/blogging/comprehensive-website-review-for-zero-monetary-cost/' rel='bookmark' title='Permanent Link: Comprehensive website review for zero monetary cost'>Comprehensive website review for zero monetary cost</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="wp_twitter_button" style="float: right; margin-left: 10px;">
					<a href="http://twitter.com/share?counturl=http%3A%2F%2Fwww.yackyack.co.uk%2Fdesign%2Fhow-to-build-a-database-driven-website-part-3%2F" class="twitter-share-button" data-url="http://www.yackyack.co.uk/design/how-to-build-a-database-driven-website-part-3/" data-count="vertical" data-via="robwatts" data-lang="" data-text="">Tweet</a><br />
					<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
				</div>
<p>In parts <a href="http://www.yackyack.co.uk/2007/01/05/how-to-build-a-data-driven-website-part-1/">one</a> and <a href="hhttp://www.yackyack.co.uk/2007/01/05/how-to-build-a-database-driven-website-part-2/">two</a> we looked at the initial database set up, inserting data into our database using csv and sql files, layout and content issues, relative to both using our database and how we can use other providers to both add value and gain additional income revenue; as well as url and navigational topics relative to getting the most from our page templates and site structure.</p>
<p>In this part we are going to look at a typical hotel content page and see how we can best maximise the data we have.</p>
<p>As we already know, we have a database that is made of two distinct tables. The tables have a number of fields that we are going to use to populate our page. Unlike the umbrella pages that we previously looked at, we are going to use all of the data we have to create a unique page for each hotel.</p>
<p>To recap we have a number of fields that can be loosely classified as follows</p>
<p><span id="more-65"></span></p>
<p><strong><a name="location"></a></strong></p>
<p><strong>Locational and contact information<br />
</strong><br />
`name` `address1` `address2` `town` `county` `region` `postcode` `country` `ename` `phone` `www` `email` `etype` `trainstation` `tsdist` `airport` `adist`</p>
<p><strong>Pricing, payment and quality information</strong></p>
<p>`price` `currency&#8220;rating&#8220;testimonials` `visa` `mastercard` `diners` `amex`</p>
<p><strong><a name="detail"></a></strong></p>
<p><strong>Detail and facility information</strong></p>
<p>`numrooms` `photourl` `description` `lifts` `restaurant` `bar` `disabled` `parking` `childrates` `tv` `ensuite` `fax` `computer` `pets` `nonsmoking` `roomservice` `breakfast` `childcare` `attractions`</p>
<p><strong>Admin information</strong><br />
`custype` `date` `ipadd` `username` `password` `renewal`</p>
<p><em>We wont worry too much about our admin information as that doesn&#8217;t really pertain to what we intend to output to our visitors.</em></p>
<p>Our page is outputed as per the picture below. You will notice that each aspect of our page is labelled with some of the field variables above.</p>
<p><strong>Our page with db variable labels</strong></p>
<p><img id="image74" alt="hotelpage.gif" src="http://www.yackyack.co.uk/wp-content/uploads/2007/02/hotelpage.gif" /></p>
<p>Our next graphic is similar, but shows the key html tags that we use to display our variables. Ive omitted tags like table and div and and have just shown the key html tags that are used to give our target keywords emphasis. HTML tags such as Hn, blockquotes, P, B, and I can be used to place extra emphasis on certain words or phrases. The short theory is that we send a message to the reader and the bots, that the page is primarily relatedto our most emphasised words and phrases, usually by way of a mix of repetition and placement within our page.</p>
<p><strong>Maximising our data inside key html tags</strong></p>
<p><img id="image75" alt="hotelpagehtmltags.gif" src="http://www.yackyack.co.uk/wp-content/uploads/2007/02/hotelpagehtmltags.gif" /></p>
<p><strong>Outputting our page</strong></p>
<p>To output our page we need to query our databse.</p>
<p>We start our database query and hotel page output by using a variable called $hotelid which we access from the url with a little help from our modrewrite contained within our .htaccess file.</p>
<p><code></p>
<p>Options +FollowSymLinks<br />
RewriteEngine on<br />
RewriteRule hotels-in-(.*)\.htm$ /county/index.php?place=$1<br />
RewriteRule  (.*)-hotels\.htm$ /town/index.php?place=$1<br />
RewriteRule  hotel-(.*)\.htm$ /hotels/index.php?hotelid=$1</p>
<p></code></p>
<p>Our query</p>
<p><img id="image77" alt="hotelcodequery1.gif" src="http://www.yackyack.co.uk/wp-content/uploads/2007/02/hotelcodequery1.gif" /></p>
<p>We are now ready to output our database variables inside our chosen key html tag holders.</p>
<p><strong>Using tags as the html gods intended<br />
</strong><br />
The most important aspect of any page is the title tag. (<em>Note the highlighted <font color="#ff0000">$trow[ename]</font> variable in the graphic above.)</p>
<p></em>The title tag frames the page. It is what we see in our web browsers when we open a page up there in the blue bar. We also see it within results appearing in the so called SERPs or search engine results pages. Its our one opportunity to gain the search engine users attention, so its important for it to be as relevant to the content of our page as is humanly possible. We want that click!</p>
<p>Our page itself should be framed like we would any  paper document, logical headings, indentations, lists, bolding, the usual formatting suspects that give form and structure to what we write. The slight difference with electronic documents is that instead of using ink and heavy strokes or typefaces, we are using html tags.</p>
<p>Search engines give weight to different tags dependant upon placement and context. We can help them rank pages or score them, by structuring our content in logical ways. So, a heading would be contained within a H1 tag, a secondary heading a h2 tag a relevant quote or set of words central to our topic might be bolded or quoted using the blockquote tag,or an ordered or unordered list with bulleted points and so on and so forth.*</p>
<p><strong>Writing our content and thinking abouthow our visitors might find us..</strong></p>
<p>As our page progresses, we place secondary emphasis on our <a href="#location">locational</a> variables and tie them in with our <a href="#detail">detail and facility variables</a>. One reason why we do this is because a visitor from say a search engine, might well enter a query &#8220;hotel in woolmer that accepts visa cards&#8221; or &#8220;hotel in Woolmer that has free parking&#8221; or &#8220;hotel in woolmer close to the train station&#8221; etc. By outputting the words on our pages and framing them in certain ways, almost thinking about how our users might use the search engines we target, we can again as result, increase the likelihood of our page being returned, thus gaining traffic and visitors.</p>
<p>To further illustrate this it might be a good idea to look at 2 examples of how good and bad copywriting can make a big difference. Note the subtleties and ask yourself which method you believe would be more conducive to both a user and a search bot..no prizes of course, it really is elementary stuff, but you&#8217;d be amazed at how many people miss the whole plot.</p>
<ul>
<li>The nearest main line train station to the Hotel Crown INN Woolmer is ChooTown central</li>
<li>Train station:ChooTown Central</li>
</ul>
<p>Yep you guessed right, the 1st line would be a whole lot more effective at catching a broader range of queries. Whereas the 2nd line is just too basic. Same info, different style, very different possible returns.<br />
Ive ran out of time to continue right now, but will come back and address things like modrewrite and .htaccess. I&#8217;ll also write a little more about some of the thinking behind good navigational structure, as well as a few others that will no doubt, spring to mind whilst i go about my day to day business!</p>
<p><em>Note:It is folly to confuse page structure with page format. HTML tags can be reformatted in terms of shape size placement and visibilty by using css. Css should not be used to lend the appearance of structure, we should always try and stick with what the w3c have to say on the topic. Besides the benefits that may flow to the aurally or visually impaired, there may also be a slight advantage from a Search engine perspective, as well as a distinctive disadvantage for any perceived abuse.</em></p>
<div />
<script src="http://feeds.feedburner.com/~s/yackyack?i=http://www.yackyack.co.uk/design/how-to-build-a-database-driven-website-part-3/" type="text/javascript" charset="utf-8"></script>

<p>Related posts:<ol><li><a href='http://www.yackyack.co.uk/adsense/monetize-your-blog-or-website-earn-money-from-your-passions/' rel='bookmark' title='Permanent Link: Monetize your blog or website &#8211; Earn money from your passions'>Monetize your blog or website &#8211; Earn money from your passions</a></li>
<li><a href='http://www.yackyack.co.uk/blogging/promote-my-website-online-in-2008/' rel='bookmark' title='Permanent Link: Promote my website online in 2008'>Promote my website online in 2008</a></li>
<li><a href='http://www.yackyack.co.uk/blogging/comprehensive-website-review-for-zero-monetary-cost/' rel='bookmark' title='Permanent Link: Comprehensive website review for zero monetary cost'>Comprehensive website review for zero monetary cost</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.yackyack.co.uk/design/how-to-build-a-database-driven-website-part-3/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>mysql</title>
		<link>http://www.yackyack.co.uk/marketing/how-to-build-a-database-driven-website-part-2/</link>
		<comments>http://www.yackyack.co.uk/marketing/how-to-build-a-database-driven-website-part-2/#comments</comments>
		<pubDate>Fri, 05 Jan 2007 21:32:09 +0000</pubDate>
		<dc:creator>robwatts</dc:creator>
				<category><![CDATA[html]]></category>
		<category><![CDATA[marketing]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[seo]]></category>
		<category><![CDATA[webdev]]></category>
		<category><![CDATA[websites]]></category>

		<guid isPermaLink="false">http://www.yackyack.co.uk/?p=20</guid>
		<description><![CDATA[Tweet In part 1 of how to build a database driven website we looked at creating the database and tables and looked at some simple options for inserting data. In this part we are going to look at connecting to the DB using PHP, creating a simple template as well as discussing a few site <a href='http://www.yackyack.co.uk/marketing/how-to-build-a-database-driven-website-part-2/'>[...]</a>


Related posts:<ol><li><a href='http://www.yackyack.co.uk/blogging/promote-my-website-online-in-2008/' rel='bookmark' title='Permanent Link: Promote my website online in 2008'>Promote my website online in 2008</a></li>
<li><a href='http://www.yackyack.co.uk/google/dont-ever-bank-on-free-traffic-build-on-it/' rel='bookmark' title='Permanent Link: Don&#8217;t  ever bank on free traffic, build on it'>Don&#8217;t  ever bank on free traffic, build on it</a></li>
<li><a href='http://www.yackyack.co.uk/blogging/getting-your-website-off-to-a-flying-start-use-a-blog-kickstart-your-domain/' rel='bookmark' title='Permanent Link: Getting your website off to a flying start &#8211; use a blog, kickstart your domain'>Getting your website off to a flying start &#8211; use a blog, kickstart your domain</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="wp_twitter_button" style="float: right; margin-left: 10px;">
					<a href="http://twitter.com/share?counturl=http%3A%2F%2Fwww.yackyack.co.uk%2Fmarketing%2Fhow-to-build-a-database-driven-website-part-2%2F" class="twitter-share-button" data-url="http://www.yackyack.co.uk/marketing/how-to-build-a-database-driven-website-part-2/" data-count="vertical" data-via="robwatts" data-lang="" data-text="">Tweet</a><br />
					<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
				</div>
<p>In part 1 of <a href="http://www.yackyack.co.uk/2007/01/05/how-to-build-a-data-driven-website-part-1/">how to build a database driven website</a> we looked at creating the database and tables and looked at some simple options for inserting data. In this part we are going to look at connecting to the DB using PHP, creating a simple template as well as discussing a few site architecture issues.</p>
<p>In this part we are going to look at connecting to the DB using PHP, creating<br />
a simple template as well as touching on a few site architecture issues along<br />
the way.</p>
<p>We are going to use a simple PHP connection script to connect to your DB, which<br />
will be saved in a separate file and stored outside of root.The connection script<br />
will contain the username and password for connecting to our database.</p>
<p>It looks like this.</p>
<p><strong>&lt;?</strong></p>
<p><strong>@ $db = mysql_connect(&#8220;localhost&#8221;, &#8220;username&#8221;, &#8220;password&#8221;);</strong></p>
<p><strong>//this line specifies the user and password for the database we intend to access</strong></p>
<p><strong>if (!$db) //if we are unable to connect to the database we tell people {</strong></p>
<p><strong>echo &#8220;Error: Could not connect to database. Please try again later&#8221;;<br />
}</strong></p>
<p><strong> mysql_select_db(&#8220;hotels&#8221;);</strong></p>
<p><strong> ?&gt;</strong></p>
<p>We save the above code in a file and call it conn.php. We can then use a PHP<br />
include or a require at the top of pages that access the database like so.</p>
<p><strong>&lt;?</strong></p>
<p><strong>require &#8220;../conn.php&#8221;;</strong></p>
<p><strong>$country=&#8221;England&#8221;;</strong> //set the country for the database</p>
<p><strong>?&gt;</strong></p>
<p>More on connecting to the database further on, for now, lets briefly look at<br />
a typical page and how we intend to output our content and urls.</p>
<p><strong><font size="5">Page structure and URL formats</font></strong></p>
<p>Our database will be used to determine our url naming conventions. We will use<br />
the place names and hotel names and hotel id&#8217;s to form our linking and navigational<br />
structure.Our database contains a series of places from across a region. For<br />
brevity sake lets assume that our site is specific to England.</p>
<p>England is made up of around 39 specific counties. These counties contain a<br />
number of towns and cities. Our plan is to output hotels specific to each county<br />
and town within.We would aim for a clean url structure so that each section<br />
of our site has a url that is logical to the area it represents, is easy to<br />
read and book mark.</p>
<p>Even though our site is dynamic, we can use a handy little feature of the apache<br />
webserver model to change our urls from ugly difficult to read concepts like.</p>
<p><strong>/filename.php?county=hertfordshire&#038;town=hitchin</strong></p>
<p>By using something called an .htaccess file we can rewrite urls so that the<br />
above can be made to look like this</p>
<p><strong>/hertfordshire-hotels-hitchin.html</strong></p>
<p>The .htaccess entry that enables this might look something like this.</p>
<p><strong>RewriteEngine on</strong></p>
<p><strong>RewriteBase /</strong></p>
<p><strong>RewriteRule (.*)-hotels-(.*)\.html$ /filename.php?county=$1&#038;town=$2 [L]</strong></p>
<p>It uses an apache module called mod_rewrite.</p>
<p>This is very handy indeedy as it allows us to have the clean uniform url file<br />
structure we are seeking to use, enabling naming structures throughout thus.</p>
<p><strong>$county-hotels-$town.html</strong> becomes  <strong>hertfordshire-hotels-hitchin.html</strong></p>
<p><em>* We can add additional lines for additional pages and files specific to whatwe want to achieve.  A link to al the site files will be supplied at the end of the series. </em></p>
<p>A database query for say, hotels in hertfordshire would then use the <strong>$county</strong><br />
variable (referenced as <strong>$1</strong> in the .htaccess file above), and return a list of<br />
towns or hotels for that particular area.</p>
<p><font size="5"><strong>Page Template and contents</strong></font></p>
<p><img alt="hotengsml1.gif" src="http://robwatts.wordpress.com/files/2007/01/hotengsml1.gif" /></p>
<p>Our sample page is going to be very simple. It consists of a logo at the top,<br />
with a main body content area.</p>
<p><em>*Ive omitted <a href="http://www.w3schools.com/html/html_head.asp">&lt;head&gt; </a>content for now. The information that follows concentrates on the content that will appear between the <a href="http://www.w3schools.com/tags/tag_body.asp">&lt;body&gt;</a><a href="http://www.w3schools.com/tags/tag_body.asp">&lt;/body&gt;</a> tags. Full html code will be supplied at the end of the series. </em></p>
<p><strong><font size="5">Header Logo</font></strong></p>
<p>Our header &#8216;logo&#8217; is a styled <a href="http://www.w3schools.com/tags/tag_hn.asp">header or Hn tag </a>which uses a background image to sit<br />
behind the text and gives it the appearance of being an image..</p>
<p>The <a href="http://www.w3schools.com/tags/tag_style.asp">&lt;style&gt;</a> is contained in the &lt;head&gt; of the document and looks<br />
like this.</p>
<p><font color="#666666">&lt;style&gt;</font></p>
<p><font color="#666666">H1 { font-size: 12pt; height: 24px; width: 100%; letter-spacing:<br />
4px; vertical-align: bottom; color: #000066; font-weight: 35; background:0 url(/header.jpg)<br />
no-repeat; float: left}<br />
</font></p>
<p><font color="#666666">&lt;/style&gt;</font></p>
<p><strong>&lt;h1&gt;Hotels and Accommodation in </strong><strong>&lt;?=ucfirst($town);?&gt;</strong><strong>&lt;/h1&gt;</strong></p>
<p><strong><font size="5">Area related images</font></strong></p>
<p>The images are sourced via a flickr plug in using the tag aspect of the flickr<br />
url to order area specific images.</p>
<p><font color="#660000">&lt;script type=&#8221;text/javascript&#8221; xsrc=&#8221;fullflickurl&#038;tag=&lt;?=$town;?&gt;&#8221; mce_src=&#8221;fullflickurl&#038;tag=&lt;?=$town;?&gt;&#8221; &gt;&lt;/script&gt;</font></p>
<p><img alt="flickr.gif" src="http://robwatts.wordpress.com/files/2007/01/flickr.gif" /></p>
<p><strong><font size="5">Contextual adverts<br />
</font></strong><br />
We may as well accrue some residual income. Not everyone will like the hotels<br />
outputted, so if they click on our ads and find what they want its all good,<br />
we win, they win.</p>
<p><strong>&lt;h2&gt;&lt;?=$town;?&gt; Travel Ads &lt;/h2&gt;</strong></p>
<p><font color="#660000">&lt;script type=&#8221;text/javascript&#8221; &gt;Contextual<br />
ad code &lt;/script&gt;</font></p>
<p><img alt="ads.gif" src="http://robwatts.wordpress.com/files/2007/01/ads.gif" /></p>
<p><strong><font size="5">Outputted Hotel</font></strong></p>
<p>We are outputting our hotel to give a brief outline of its key points . We  will<br />
include high level information such as name, price, star ratings, booking url,<br />
full detail url as well as a teaser of its full description.</p>
<p>We achieve this using the following code.</p>
<p>First our query<br />
<strong>&lt;?</strong></p>
<p><strong>$query = &#8220;select * from hotelcontent1, hotelcontent2</strong></p>
<p><strong>where hotelcontent1.custid = hotelcontent2.custid and town</strong></p>
<p><strong>= &#8216;$town&#8217; and county  =&#8217;$county&#8217;  and country = &#8216;$country&#8217; order by custid limit 0, 1 &#8221; ;</strong></p>
<p><strong>$result = mysql_query($query); </strong></p>
<p><strong>?&gt;</strong></p>
<p>Then we want to do some manipulation on the description element of the returned content.</p>
<p><strong>&lt;?</strong></p>
<p><strong>$row=mysql_fetch_array($result);</strong></p>
<p><strong> $desc = stripslashes($row['description']);</strong></p>
<p><strong>$content = $desc;</strong></p>
<p><strong> $text_length =300;</strong></p>
<p><strong>$add=strlen($row[town]);</strong></p>
<p><strong>$text_length=($text_length + $add);</strong></p>
<p><strong>$stricon=($content);</strong></p>
<p><strong>$all_content=strlen(&#8220;$stricon&#8221;);</strong></p>
<p><strong>$standard_content=substr($stricon ,$text_length);</strong></p>
<p><strong>$compare=stristr($standard_content ,&#8221; &#8220;);</strong></p>
<p><strong>$minus_content=strlen(&#8220;$compare&#8221;);</strong></p>
<p><strong>$result_content=$all_content-$minus_content;</strong></p>
<p><strong>$display_content=substr($stricon ,0, $result_content);</strong></p>
<p><strong>$stripped_content=stripslashes($display_content);</strong></p>
<p><strong>$stripped_content=nl2br($stripped_content);</strong></p>
<p><strong>$description=$stripped_content;</strong></p>
<p><strong>?&gt;</strong></p>
<p>Before finally putting it all together and outputting our hotel.</p>
<p><strong>&lt;h2&gt;&lt;?=ucfirst($town);?&gt; Hotel of the Month &lt;/h2&gt;</strong></p>
<p><strong>&lt;?</strong></p>
<p><strong>echo&#8221;&lt;div class=message&gt;&lt;h2&gt;$row[ename]&lt;/h2&gt;&lt;i class=p2&gt;<br />
$row[country] &gt; $row[region] &gt; $row[county]&gt; $row[town] &lt;/i&gt;&lt;br&gt;&lt;table<br />
width=\&#8221;95%\&#8221; CLASS=\&#8221;hoteltables\&#8221;&gt;&lt;thead&gt; &lt;tr&gt;&lt;td<br />
bgcolor=\&#8221;#999999\&#8221;&gt; &lt;b&gt;&lt;font color=\&#8221;#FFFF33\&#8221;&gt;Hotel<br />
in $row[PostalTown] &lt;/font&gt;&lt;/b&gt;&lt;/td&gt; &lt;/tr&gt;&lt;/thead&gt;<br />
&lt;tr&gt;&lt;td&gt; &lt;p class=p2&gt;&lt;img xsrc=\&#8221; /$row[photourl]\&#8221;<br />
height=\&#8221;68\&#8221; width=\&#8221;90\&#8221; alt=\&#8221;$county hotels:$row[ename]\&#8221;<br />
align=left id=thephoto&gt; &lt;strong&gt; $row[ename] &lt;/strong&gt; &#8211; $description<br />
&#8230;&lt;br&gt; &lt;a xhref=\&#8221;/book.php?id=$row[hotelid]\&#8221;&gt;Book&lt;/a&gt;<br />
&lt;a xhref=\&#8221; /more.php?id=$row[hotelid]\&#8221;&gt;More&lt;/a&gt;<br />
&lt;/font&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt; &lt;br&gt;&lt;/div&gt;&#8221;;<br />
</strong></p>
<p><strong>?&gt;</strong></p>
<p><img alt="hotel.gif" src="http://robwatts.wordpress.com/files/2007/01/hotel.gif" /></p>
<p><strong><font size="5">Navigational links</font></strong></p>
<p>Links are an important aspect of the sites architecture they are used by humans<br />
and bots to give anchored clues to the content of their target pages. Search<br />
engine bots use these anchors or its better known phrase of anchor text to help<br />
weight documents in their search engine databases.</p>
<p>To output our links we used the following sql.</p>
<p><strong>&lt;?</strong></p>
<p><strong>$query = &#8220;select Distinct county from hotelcontent2 where country = &#8216;$country&#8217;     ORDER BY county&#8221; ;</strong></p>
<p><strong>$result = mysql_query($query);</strong></p>
<p><strong>?&gt;</strong></p>
<p>The query here is very simple, it says give me a set of distinct counties from<br />
the database table named hotelcontent1 where the counties returned are a subset of England. These are then  outputted via a loop producing a series of links for our navigation footer.</p>
<p>The for loop for which makes this possible, might look a little like this.</p>
<p><strong>&lt;h3&gt;Regions of  &lt;?=$country;?&gt;&lt;/h3</strong>&gt;<br />
<strong>&lt;p&gt;</strong></p>
<p><strong>&lt;?</strong></p>
<p><strong>$num_results=mysql_num_rows($result); //number of rows </strong></p>
<p><strong>for ($i=0; $i &lt;$num_results; $i++) { </strong></p>
<p><strong>$row = mysql_fetch_array($result);</strong></p>
<p><strong>$countyname=strtolower($row[county]); //ensure the county name is lower case</strong></p>
<p><strong>echo &#8220;&lt;a xhref=\&#8221;/$countyname-hotels.html\&#8221;&gt;$row[county]<br />
hotels &lt;/a&gt;  &#8220;; </strong></p>
<p><strong> } </strong></p>
<p><strong>?&gt;</strong></p>
<p><strong>&lt;/p&gt; </strong></p>
<p>The above loop outputs something like this in our footer<br />
<img alt="navlinks.gif" src="http://robwatts.wordpress.com/files/2007/01/navlinks.gif" /></p>
<p>We could also produce other links relative to the county we are in. We are in a page that is a subset of Hertfordshire (Hitchin) . Contextually, it makes sense for our users to see what other towns are in Hertfordshire. It also helps our other pages to get indexed by search engines and has the added bonus of making our pages that little bit different for others within in our site.</p>
<p>Lets output the towns relative to our <strong>$county</strong> and <strong>$town</strong> variables referenced from the url for our page about Hitchin hotels in Hertfordshire.</p>
<p><strong>&lt;?</strong></p>
<p><strong>$query = “select Distinct town from hotelcontent2 where county =  ‘$county’ and country =&#8217;$country&#8217; AND town != ‘NULL’ ORDER BY town Limit 0, 20? ;</strong></p>
<p><strong>$result = mysql_query($query);</strong></p>
<p><strong>?&gt;</strong></p>
<p>The query here is very simple, it says give me a set of distinct towns  from<br />
the database table named hotelcontent1 where the town is a subset of a variable<br />
named <strong>$county</strong> (hertfordshire in this  instance) .Which when looped and<br />
outputted   produces a maximum of 20 urls,  or links for our nav footer.</p>
<p>The for loop for which makes this possible, as in the one outlined aboved might look a little like  this.</p>
<p><strong>&lt;h4&gt;Towns within  &lt;?=ucfirst($county);?&gt;&lt;/h4&gt;</strong> <strong><br />
&lt;p&gt; </strong></p>
<p><strong>&lt;?</strong></p>
<p><strong>$num_results=mysql_num_rows($result); //number of rows </strong></p>
<p><strong>for ($i=0; $i &lt;$num_results; $i++) { </strong></p>
<p><strong>$row = mysql_fetch_array($result);</strong></p>
<p><strong>$townname=strtolower($row[town]); //ensure the town name is lower  case</strong></p>
<p><strong>echo “&lt;a xhref=\”/$county-hotels-$townname.html\”&gt;$row[town]<br />
hotels  &lt;/a&gt; “; </strong></p>
<p><strong>} </strong></p>
<p><strong>?&gt;</strong></p>
<p><strong>&lt;/p&gt; </strong></p>
<p>In the next part we will look at building an individual hotel detail page and look at some of the structural elements that will, <em>given a multitude of other factors</em>,   help our pages perform relatively well for our target keywords within the search engines.</p>
<script src="http://feeds.feedburner.com/~s/yackyack?i=http://www.yackyack.co.uk/marketing/how-to-build-a-database-driven-website-part-2/" type="text/javascript" charset="utf-8"></script>

<p>Related posts:<ol><li><a href='http://www.yackyack.co.uk/blogging/promote-my-website-online-in-2008/' rel='bookmark' title='Permanent Link: Promote my website online in 2008'>Promote my website online in 2008</a></li>
<li><a href='http://www.yackyack.co.uk/google/dont-ever-bank-on-free-traffic-build-on-it/' rel='bookmark' title='Permanent Link: Don&#8217;t  ever bank on free traffic, build on it'>Don&#8217;t  ever bank on free traffic, build on it</a></li>
<li><a href='http://www.yackyack.co.uk/blogging/getting-your-website-off-to-a-flying-start-use-a-blog-kickstart-your-domain/' rel='bookmark' title='Permanent Link: Getting your website off to a flying start &#8211; use a blog, kickstart your domain'>Getting your website off to a flying start &#8211; use a blog, kickstart your domain</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.yackyack.co.uk/marketing/how-to-build-a-database-driven-website-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mysql</title>
		<link>http://www.yackyack.co.uk/marketing/how-to-build-a-data-driven-website-part-1/</link>
		<comments>http://www.yackyack.co.uk/marketing/how-to-build-a-data-driven-website-part-1/#comments</comments>
		<pubDate>Fri, 05 Jan 2007 14:40:27 +0000</pubDate>
		<dc:creator>robwatts</dc:creator>
				<category><![CDATA[html]]></category>
		<category><![CDATA[marketing]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[seo]]></category>
		<category><![CDATA[webdev]]></category>
		<category><![CDATA[websites]]></category>

		<guid isPermaLink="false">http://www.yackyack.co.uk/?p=18</guid>
		<description><![CDATA[Tweet Building a simple database driven website. This is part one of a multi part yet to be determined &#8216;how to&#8217; aimed at showing you how to build a database driven website. There are squillions out there already of course, but in this one I&#8217;m gonna try and do it a little differently. *disclamer:I&#8217;m not <a href='http://www.yackyack.co.uk/marketing/how-to-build-a-data-driven-website-part-1/'>[...]</a>


Related posts:<ol><li><a href='http://www.yackyack.co.uk/blogging/promote-my-website-online-in-2008/' rel='bookmark' title='Permanent Link: Promote my website online in 2008'>Promote my website online in 2008</a></li>
<li><a href='http://www.yackyack.co.uk/google/dont-ever-bank-on-free-traffic-build-on-it/' rel='bookmark' title='Permanent Link: Don&#8217;t  ever bank on free traffic, build on it'>Don&#8217;t  ever bank on free traffic, build on it</a></li>
<li><a href='http://www.yackyack.co.uk/blogging/getting-your-website-off-to-a-flying-start-use-a-blog-kickstart-your-domain/' rel='bookmark' title='Permanent Link: Getting your website off to a flying start &#8211; use a blog, kickstart your domain'>Getting your website off to a flying start &#8211; use a blog, kickstart your domain</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="wp_twitter_button" style="float: right; margin-left: 10px;">
					<a href="http://twitter.com/share?counturl=http%3A%2F%2Fwww.yackyack.co.uk%2Fmarketing%2Fhow-to-build-a-data-driven-website-part-1%2F" class="twitter-share-button" data-url="http://www.yackyack.co.uk/marketing/how-to-build-a-data-driven-website-part-1/" data-count="vertical" data-via="robwatts" data-lang="" data-text="">Tweet</a><br />
					<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
				</div>
<p><span id="more-18"></span><strong>Building a simple database driven website.</strong></p>
<p>This is part one of a multi part yet to be determined &#8216;how to&#8217; aimed at showing you how to build a database driven   website. There are squillions out there already of course, but in this one I&#8217;m gonna try and do it a little differently.</p>
<p><font size="1" color="red">*disclamer:I&#8217;m not frickin perfect, this is  not intended to be the best resource on the topic there is. I&#8217;m just sharing the benefits of my experience. Take it in that vein and hopefuly you&#8217;ll enjoy!</font><em><font size="1"> </font></em></p>
<p><strong>Ok for this recipe you will need.</strong></p>
<ul>
<li>An idea of what you want to do</li>
<li>Basic knowledge of HTML</li>
<li>PHP enabled webspace</li>
<li>An Apache hosted website</li>
<li>A Mysql Database</li>
<li>PhpMyAdmin</li>
<li>A dataset</li>
<li>Will and determination to get it done</li>
</ul>
<p>Optional extras (desirable but not absolutely necessary)</p>
<ul>
<li>Flashy logo</li>
<li>Cool design</li>
</ul>
<p><strong>An idea of what you want to do</strong></p>
<p>When I built things like this in the past, I had to build from the ground up and learn things as I went. When I first went on the net back in um..1995 I think it was, I recall being vaguelly intrigued thinking, cool, I wonder how they do that.</p>
<p>My 1st ever webpage used the <a href="http://en.wikipedia.org/wiki/Marquee_tag">&lt;marquee&gt;</a> tag! It slid a photo of a Ford Mondeo across the screen!Ha, I had this nutty idea that I was gonna create a raffle or draw of some kind and enthuse everybody to enter some &#8216;win a car&#8217; competition. I never did put it on line but it did get me thinking about how people would find it and that search engines would probably be a tool they&#8217;d use. Here is a funny thought. I once thought that when you entered a search term into a search box, the search engine then went and &#8216;looked&#8217; at all the computers in the world and found pages to give back, ha! I guess I wasn&#8217;t so far off, they kinda do that, only that they&#8217;ve already been out into the web and grabbed the data beforehand.</p>
<p>Ok, enough of my waffle, on to the meat and potatoes.</p>
<p><strong>The project</strong></p>
<p>In this part we will look at discussing the base concept, creating  a database, creating the tables, discussing the data, inserting the data into our database.</p>
<p>Ok, having briefly introduced what this is about in the title of the page. Its time to be a little more specific.We are going to build a hotel brochure website from the ground up. We will discuss the creation of the site from A to Z . From initial site set up through to  getting indexed in the search engines. During this process we will look at issues facing site owners and offer up good examples for avoiding the pitfalls.  We wil look at adding value to affiliate feeds and offer up solutions to the many mistakes and problems that site owners encounter. Some of the areas we will look at will include.</p>
<ul>
<li>Planning issues</li>
<li>Getting started</li>
<li>Obtaining and working with a dataset</li>
<li>Creating a database</li>
<li>Using  Mysql and PHP to output  content</li>
<li>Good site architecture and design</li>
<li>Website script security</li>
<li>Getting indexed in the search engines</li>
<li>Promoting your website</li>
<li>Common pitfalls to avoid</li>
</ul>
<p><strong> Planning issues</strong></p>
<p>Whilst this isn&#8217;t a typical real world project its useful nonetheless to look briefly at what we are looking to do. Any good website serves a purpose, in our case we are going to build a hotel brochure website we are going to assume that none exist already, we are going to act like our pages are the only ones in the world and that search engines and users alike are going to love our content and gobble it all up. Our website will give its users what they need in a simple, easy to use way. It will be easy to navigate, quick to load and on topic to its theme. Ordinarily we would all sit around a table in a huddle and discuss our aims and objectives. We would look at our market, look at our competitors, aim towards building a niche with a long term view of steady user growth by way of new sign ups and traffic. Monetisation would be a key factor too. luckily for us, none of these are pressing issues for this project as its purely educational.</p>
<p><strong>Getting started</strong></p>
<p>Our first stop is to grab a dataset. There are two approaches we could take. We could start from scratch. Go out and canvaas lots of hotels and invite them to join our website by sending them our details, or a quicker supplemental route would be to go to a big provider like Venere or Superhotels, or IAN or even individual big hotel chains like Holiday Inn and sign up for one of their affiliate programs.</p>
<p>Most Ive looked at will provide you the data as a direct download. You can choose which fields you want to use, which areas such as countries or regions, you can also choose which informational data you&#8217;d like to show too. The data can usually be saved to your computer as a text file, delimited, by tab, comma, or any other delimiter of your choosing which can then be uploaded to a database. Some will even provide for the data to be obtained as an sql file which can then be directly ran through an sql interpreter and inputted direct tot he database. In this instance we will be using a Mysql database to store our data, and will be using PhpMyAdmin as the interface for inputting our data.</p>
<p><strong>Create the database</strong></p>
<p>Most hosts will offer you the facility to use a GUI to create the database. Plesk is one popular GUI as is CPanel. There are others too. Sometimes you might have to request your host to create one for you.Most good hosts provide the tools for you to do so.</p>
<p>If push comes to shove you can use php to create one for you using the <strong>mysql_create_db() </strong>function, something like.</p>
<p>&lt;?php<br />
<strong>$query  = &#8220;CREATE DATABASE hotels&#8221;;<br />
$result = mysql_query($query);<br />
</strong>?&gt;</p>
<p>For the purposes of this though, we are going to assume that youve created a database named &#8216;hotels&#8217; and have opened your PhpMyAdmin interface and are ready to create the tables.</p>
<p><strong>Create the tables</strong></p>
<p>In this example Ive chosen to stick with a basic data set and have placed the data into two logically named tables. The first table Ive called &#8216;hotelcontent1&#8242; and the second &#8216;hotelcontent2&#8242;</p>
<p>We will need to create all sorts of fields relative to what the hotel provides. Email address field (<strong>email</strong>), establishment name field (<strong>ename</strong>) , web address field (<strong>www</strong>), price field (<strong>price</strong>) and so on. The code below is the sql that we will use to create our tables.</p>
<pre>CREATE TABLE `hotelcontent1` (

`hotelid` int(9) NOT NULL auto_increment,

`custid` int(9) default NULL,

`<strong>ename</strong>` varchar(50) NOT NULL default '0',

`phone` varchar(60) NOT NULL default '0',

`<strong>www</strong>` varchar(250) NOT NULL default '0',

`<strong>email</strong>` varchar(160) NOT NULL default '0',

`etype` varchar(20) NOT NULL default '0',

`<strong>price</strong>` varchar(10) NOT NULL default '0',

`currency` varchar(10) NOT NULL default '0',

`rating` char(2) NOT NULL default '0',

`numrooms` varchar(4) NOT NULL default '0',

`trainstation` varchar(50) NOT NULL default '0',

`tsdist` varchar(4) NOT NULL default '0',

`airport` varchar(75) NOT NULL default '0',

`adist` char(2) NOT NULL default '0',

`photourl` varchar(250) NOT NULL default '0',

`description` text NOT NULL,

`visa` char(1) NOT NULL default '0',

`mastercard` char(1) NOT NULL default '0',

`diners` char(1) NOT NULL default '0',

`amex` char(1) NOT NULL default '0',

`lifts` char(1) NOT NULL default '0',

`restaurant` char(1) NOT NULL default '0',

`bar` char(1) NOT NULL default '0',

`disabled` char(1) NOT NULL default '0',

`parking` char(1) NOT NULL default '0',

`childrates` char(1) NOT NULL default '0',

`tv` char(1) NOT NULL default '0',

`ensuite` char(1) NOT NULL default '0',

`fax` char(1) NOT NULL default '0',

`computer` char(1) NOT NULL default '0',

`pets` char(1) NOT NULL default '0',

`nonsmoking` char(1) NOT NULL default '0',

`roomservice` char(1) NOT NULL default '0',

`breakfast` char(1) default '0',

`childcare` char(1) NOT NULL default '0',

`attractions` text NOT NULL,

`testimonials` text NOT NULL,

PRIMARY KEY  (`hotelid`),

UNIQUE KEY `hotelid` (`hotelid`)

) TYPE=MyISAM AUTO_INCREMENT=0 ;</pre>
<pre>CREATE TABLE `hotelcontent2` (

`custid` int(9) NOT NULL auto_increment,

`name` varchar(50) default NULL,

`address1` varchar(50) default NULL,

`address2` varchar(50) default NULL,

`town` varchar(100) default NULL,

`county` varchar(100) default '0',

`region` varchar(50) default 'no address recorded',

`postcode` varchar(12) NOT NULL default '0',

`country` varchar(30) NOT NULL default '0',

`custype` char(2) NOT NULL default '0',

`date` date default NULL,

`ipadd` varchar(30) default '000000000',

`username` varchar(100) NOT NULL default 'user',

`password` varchar(28) NOT NULL default 'pass',

`renewal` varchar(20) NOT NULL default '0000-00-00',

PRIMARY KEY  (`custid`),

KEY `town` (`town`),

KEY `county` (`county`),

KEY `region` (`region`),

KEY `country` (`country`)

) TYPE=MyISAM AUTO_INCREMENT=0 ;</pre>
<p><strong>The data</strong></p>
<p>One of the great features that mysql has is that it allows you to insert text files straight in to a table. Provided they are properley formatted, and you specify the correct delimiter used, then it will insert the data into the fields you specify</p>
<p>In this \t or tab delimited example for our &#8216;hotelcontent1&#8242; table, we would upload it using PhpMyAdmins &#8216;import&#8217; feature. We would specify csv as the option and enter \t as the delimiter of choice. A sample row of such data might look a little like this;</p>
<p><strong>A typical line from a tab delimited file</strong></p>
<p><code>"1" "1" "The supergroovynicehotel" "0044(0)*********" "www.supergroovynicehotelofchoice.com"<br />
"info@supergroovynicehotelofchoice.com" "Hotel" "45" "pounds" "3" "32" "Aberdeen"<br />
"5" "Aberdeen" "10" "http://www.supergroovynicehotelofchoice.com/Images/<br />
supergroovynicehotelofchoice.jpg" "The supergroovynicehotelofchoice Hotel is now<br />
under the new management of Rob and Delia Blogs. blah blah blah. " "y" "y" "y" "N" "y" "y" "y" "y" "N" "N" "y" "y" "y" "N" "N" "y" "N" "y" "N" "N"</code></p>
<p>Each &#8220;&#8221; enclosed piece of data and corresponding gap (tab) specifies that its to be treated as a seperate field. Multiple insertions would be picked up by way of a \n or new line within the interpreter.</p>
<p><em>Note: Full sample files will be provided at the end of the piece so don&#8217;t worry too much about where the data is at the moment, it&#8217;ll be there at the end. <img src='http://www.yackyack.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </em></p>
<p>An alternative way of getting our data into our database, would be via use of an actual .sql file containing the full insert instructions a typical line within would read something like this;</p>
<p><strong>A typical line from an sql file</strong><br />
<code>INSERT INTO `hotelcontent1` VALUES (1, 1, 'The supergroovynicehotel', '0044(0)**********', 'www.supergroovynicehotelofchoice.com',<br />
'info@supergroovynicehotelofchoice.com', 'Hotel', '45', 'pounds', '3"', '32','Aberdeen', '5',<br />
'Aberdeen', '10','http://www.supergroovynicehotelofchoice.com/<br />
Images/supergroovynicehotelofchoice.jpg', 'The supergroovynicehotelofchoice<br />
Hotel is now under the new management of Rob and Delia Blogs. blah blah blah.', 'y', 'y', 'y', 'N', 'y', 'y', 'y', 'y', 'N', 'N', 'y', 'y', 'y', 'N', 'N', 'y', 'N', 'y', 'N', 'N', '');</code><br />
The outcomes of either method is the same, the route to which all depends on the tools, knowledge and requirements you have to hand.</p>
<p>Some data sets can be very clunky to work with and require all sorts of processing and preparation before use. In the past I&#8217;ve used combinations of excel, odbc, and phpmyadmin locally, to prepare my files for the live database. These have been especially useful where the datasets provided were particularly large or in need of adjustment to fit my purposes.</p>
<p>Ok, so  having stored our sample data in our database and tables, we are a step nearer the  process of retrieving and outputting it to our webpage. <a href="http://www.yackyack.co.uk/2007/01/05/how-to-build-a-database-driven-website-part-2/">In part 2</a> I&#8217;ll be showing you how to connect to the database using PHP choosing a good page template and discussing a few site architecture and design issues.</p>
<script src="http://feeds.feedburner.com/~s/yackyack?i=http://www.yackyack.co.uk/marketing/how-to-build-a-data-driven-website-part-1/" type="text/javascript" charset="utf-8"></script>

<p>Related posts:<ol><li><a href='http://www.yackyack.co.uk/blogging/promote-my-website-online-in-2008/' rel='bookmark' title='Permanent Link: Promote my website online in 2008'>Promote my website online in 2008</a></li>
<li><a href='http://www.yackyack.co.uk/google/dont-ever-bank-on-free-traffic-build-on-it/' rel='bookmark' title='Permanent Link: Don&#8217;t  ever bank on free traffic, build on it'>Don&#8217;t  ever bank on free traffic, build on it</a></li>
<li><a href='http://www.yackyack.co.uk/blogging/getting-your-website-off-to-a-flying-start-use-a-blog-kickstart-your-domain/' rel='bookmark' title='Permanent Link: Getting your website off to a flying start &#8211; use a blog, kickstart your domain'>Getting your website off to a flying start &#8211; use a blog, kickstart your domain</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.yackyack.co.uk/marketing/how-to-build-a-data-driven-website-part-1/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  www.yackyack.co.uk/category/mysql/feed/ ) in 0.73511 seconds, on Feb 8th, 2012 at 8:41 am UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 8th, 2012 at 9:41 am UTC -->
