Hi David ,
I have a table within the same database of the main PT installation database. I'm struggling to get this information to show without having to open up two database connections. One for all the Price Tapestry ones so that the featured products show on the home page and one for this custom database that holds the blurb section. How can I get this to call just using sql without having to create another database connection to the same database? It only uses two fields - home_title and blurb. Any help would be great thanks, it's really bugging me.
Thanks
Ben
Perfect, thanks David. Just one more problem now.
On one page I have three adverts in a row that work like featured products, except that they are adverts. I've stored a few in a database and I only want it to show the latest 3 in the database. I've tried applying the above to it, adding ORDER BY advert_id DESC LIMIT 3 and played about with it, but I either get one show or none. I'm just trying to make it all as easy to update as the featured products page as at the moment I'm going to have to add them all manually which could end up being a lot of work, rather than just going into the admin section and adding some html into a text box and hitting the add button.
$sql = "SELECT * FROM `".$config_databaseTablePrefix."advert` ORDER BY advert_id DESC LIMIT 3";
database_querySelect($sql,$result);
$advert = $result[0]["advert"];
print $advert;
Basically, how do I get the LIMIT to work properly please within Price Tapestry? I know if needs an IF statement, but that's about it.
Cheers
Ben
Hi Ben,
Your query probably is returning the 3 latest (the SQL looks fine), but then what you need to do is loop through the results variable using a foreach loop. Have a go with something like:
$sql = "SELECT * FROM `".$config_databaseTablePrefix."advert` ORDER BY advert_id DESC LIMIT 3";
database_querySelect($sql,$results);
foreach($results as $result)
{
$advert = $result["advert"];
print $advert;
}
(note that I have changed $result to $results) in the call to database_querySelect()...
Cheers,
David.
--
PriceTapestry.com
You're the man! Thank you so much. Can keep everything easy to update now :-)
Cheers
Ben
Hi Ben,
If your table has maintained the Price Tapestry table prefix then you should be able to use the built in library; for example:
$sql = "SELECT * FROM `".$config_databaseTablePrefix."mytable`";
database_querySelect($sql,$result);
$home_title = $result[0]["home_title"];
$blurb = $result[0]["blurb"];
print "<h1>".$home_title."</h1>";
print "<p>".$blurb.'</p>";
If not, then line 1 of the above would just be;
$sql = "SELECT * FROM `mytable`";
Hope this helps!
Cheers,
David.
--
PriceTapestry.com