|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
nlefebrve Smarty n00b
Joined: 06 May 2010 Posts: 2
|
Posted: Thu May 06, 2010 12:46 pm Post subject: HELP MYSQL |
|
|
SLT
je cherche a afficher un seul texte, le plus réssant, mais le problème c'est qu'il me sort tous la table du 1 id au dernier. voici mon code php
$smarty->compile_check = true;
$smarty->debugging = false;
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($dbname, $link);
$query_Recordset1 = "SELECT acceuilID, Titre1, article1, titre2, article2 FROM table_motiv_acceuil ORDER BY acceuilID DESC";
$Recordset1 = mysql_query($query_Recordset1, $link) or die(mysql_error());
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
#...your mysql connection & smarty initialization goes here
while ($row = mysql_fetch_assoc($Recordset1))
{
$id[] = $row['acceuilID'];
$titles[] = $row['Titre1'];
$article[] = $row['article1'];
}
$smarty = new Smarty();
$smarty->assign ('ids',$id);
$smarty->assign ('titles',$titles);
$smarty->assign ("articlesdroite",$article);
// Affichage du template après compilation
$smarty->cache_lifetime = 24 * 60 * 60;
$smarty->display('test.tpl');
?>
Voici le code TPL
{section name=id loop=$titles}
{$articlesdroite[id]}
{/section}
Merci pour votre aide |
|
Back to top |
|
Gowser Smarty Pro
Joined: 19 Feb 2008 Posts: 104 Location: Nantes (France)
|
Posted: Wed Jun 02, 2010 2:43 pm Post subject: |
|
|
Vous voulez qu'il y ai qu'une seule lignée d'affichée ?
Si c'est le cas, rajoutez à la fin de votre requête un 'LIMIT 1' afin de ne ramener qu'un seul enregistrement :
Code: |
SELECT acceuilID, Titre1, article1, titre2, article2 FROM table_motiv_acceuil ORDER BY acceuilID DESC LIMIT 1
|
Sinon , étant donné qu'un order by est gourmand en ressource, vous pouvez rechercher l'enregistrement le plus récent par sa date ou son id (je ne sais pas si vous avez des dates en base) avec :
Code: |
SELECT
acceuilID, Titre1, article1, titre2, article2
FROM
table_motiv_acceuil
WHERE
accueilID=(
SELECT
MAX(accueilID)
FROM
table_motiv_acceuil
)
|
par sa date (si vous en avez une, ici j'ai utilisé dateArticle) :
Code: |
SELECT
acceuilID, Titre1, article1, titre2, article2
FROM
table_motiv_acceuil
WHERE
dateArticle=(
SELECT
MAX(dateArticle)
FROM
table_motiv_acceuil
)
|
Cordialement |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|