Support Forums

Inserting data from a database help

This is a discussion on Inserting data from a database help within the TemplateCodes forums, part of the Third Party Support category; Hi Guys, I have populated a mysql database with some data and want to display it on the home page. ...


Go Back   68 Classifieds Forums > Third Party Support > TemplateCodes

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 08-25-2009, 09:58 AM   #1
Customer
 
Join Date: Feb 2009
Location: Hong Kong
Posts: 30
Rep Power: 8
skekum is on a distinguished road
Default Inserting data from a database help

Hi Guys,

I have populated a mysql database with some data and want to display it on the home page.

Using standard mySQL & php, I can retrieve the 3 rows of data, and echo the array to the page, but it somehow breaks the building of the page.

This is the code i've placed onto the home.tpl where I want the data to appear:
PHP Code:
$host="localhost";
$user="***";
$password="***";
$database="***";

$connection mysql_connect($host,$user,$password)
    or die(
"Couldn't select database");

// connect to db
$db mysql_select_db($database,$connection)
    or die(
"Couldn't select the database");
    

// Get the last 3 rows of data from the db
$query "SELECT * FROM whatson ORDER BY id DESC LIMIT 3";
$result mysql_query($query)
    or die(
"Couldn't select anything from the db but don't get upset");

// Count the number of rows retrieved.
$nrows mysql_num_rows($result);

// Start a loop to echo out the results in a table.

for ($i=0;$i<$nrows;$i++)
{
    
$row mysql_fetch_array($result);
    
extract ($row);
    echo 
"<table id='whatsontable'>";
    echo 
"<tr><td class='articletable_title'><a href='$link' target='_blank'>$title</a></td></tr>";
    echo 
"<tr><td>$body�</td></tr>";
    echo 
"</table><br />";

As seen in the attached picture, the data is written correctly but the menus on the right hand column are not completed leaving empty boxes. I suspect my {php} tags on the home.tpl page are breaking the code?



I'm new to smarty and have been through the manual and the forums, but can't seem to get a handle on what I need to do to get this to work.

Any help would be appreciated.

Currently as a work around, I'm "hard coding" the data onto the page, but i'm trying to automate it.

Glenn
__________________
68 Classifieds Developer v4.1.10

Template - Fluid-Ocean
Modules - adpack, debug, freecap, image_upload, listingfilter, maintenance, markitup, payment_providers, quick_search, statistics, tc_jcarousel, tc_site_map, template_switcher, templatezones.

http://www.themarketplace.com.hk
skekum is offline   Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Import new data hel68c Technical Support 7 03-12-2009 12:24 AM
importing old data ombre Technical Support 8 12-05-2008 08:34 PM
inserting extra field on place listing tpl Shadman Technical Support 10 10-29-2008 03:43 PM
Need help inserting Openads.org button ads goose Templates, HTML, CSS, and Design Help 2 09-12-2007 12:44 PM


All times are GMT -4. The time now is 03:46 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0