View previous topic :: View next topic |
Author |
Message |
gtgibson Smarty Rookie
Joined: 30 Jul 2003 Posts: 9 Location: New Zealand
|
Posted: Thu Jul 31, 2003 9:19 am Post subject: querystrings have no effect on my ouput - silly cache |
|
|
query strings...
I have a php file with an SQL query
<?php
# retrieve an article, and author information
$query = "SELECT * from articles WHERE articles.ID = ".$_GET["ID"]." LIMIT 1";
$article = mysql_fetch_array($result, MYSQL_BOTH);
$smarty->assign('article',$article);
$smarty->display('article.tpl');
?>
The problem I have is that when I view the pages on the site view the article.tpl file, e.g. when I ask for:
article.php?ID=1
it works great the first time, after that the template isn't recompiling, and I keep getting the original article no matter what article ID I pass in the querystring. e.g:
article.php?ID= 2
When I resave the template file, it displays the new article. Obviously this has something to do with caching, but how can I get around this? Is smarty not designed to retrieve information this way? What shoudl I be doing?
Thanks,
GG _________________ I suck at web development. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Jul 31, 2003 9:33 am Post subject: |
|
|
if you set $smarty->caching=true you have to supply a unique cache_id if you want to display different things. try:
$smarty->display('index.tpl', $_GET['ID']);
see: http://smarty.php.net/manual/en/caching.multiple.caches.php for reference.
greetings
messju |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Jul 31, 2003 10:07 am Post subject: |
|
|
umm, my advice was only a quick fix.
you shouldn't pass get-parameters directly as cache-ids, but check them for sanity. in your case:
$smarty->display('article.tpl', ($article) ? (int)$_GET['id'] : 0);
may be sufficient, but (as always) YMMV |
|
Back to top |
|
gtgibson Smarty Rookie
Joined: 30 Jul 2003 Posts: 9 Location: New Zealand
|
Posted: Thu Jul 31, 2003 10:09 am Post subject: |
|
|
Perfekt! _________________ I suck at web development. |
|
Back to top |
|
gtgibson Smarty Rookie
Joined: 30 Jul 2003 Posts: 9 Location: New Zealand
|
Posted: Thu Jul 31, 2003 10:09 am Post subject: |
|
|
YMMV _________________ I suck at web development. |
|
Back to top |
|
gtgibson Smarty Rookie
Joined: 30 Jul 2003 Posts: 9 Location: New Zealand
|
Posted: Thu Jul 31, 2003 10:23 am Post subject: |
|
|
what does the " : 0" part do?
actually, now that I take a deeper look... what does most of that mean inside $smarty->display():
$smarty->display('article.tpl', ($article) ? (int)$_GET['id'] : 0); _________________ I suck at web development. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Jul 31, 2003 10:37 am Post subject: |
|
|
YMMV: your mileage may vary
"($article) ? (int)$_GET['id'] : 0" is the ?-operator borrowed from c. it says: if $article is someting true use "(int)$_GET['id']" (which means $_GET['id'] converted to an integer value) else use "0" as a cache_id.
overall the example above is a short-hand for:
[php:1:e71c07ec99]
if ($article) {
$cache_id = (int)$_GET['id'];
} else {
$cache_id = 0;
}
$smarty->display('article.tpl', $cache_id);
[/php:1:e71c07ec99]
which is virtually the same |
|
Back to top |
|
|