Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]smarty podstawy, Wyświetlanie w tpl
login90
post 25.09.2019, 12:12:31
Post #1





Grupa: Zarejestrowani
Postów: 52
Pomógł: 0
Dołączył: 8.02.2016

Ostrzeżenie: (0%)
-----


Witajcie

Jest tu ktoś kumaty w bibliotece smarty. Jak zrobić aby w tpl wyświetlały się te wartości. Chodzi mi o to np
<h1>{$art_tresc}</h1>
Mam tabele system news
id, namenews, content

Ja próbuje robić tak

<?php
require_once('connect.php');
include_once("./libs/Smarty.class.php");


$smarty = new Smarty;

$query = mysql_query("select * from news") or die(mysql_error());
while($row = mysql_fetch_row($query)) {
$art_tytul[]=$row['id'];

$id[]=$row['id'];
$art_tytul_n[]=$row['namenews'];
$art_tresc[]=$row['content'];
$smarty->assign("id",$row['id']);
$smarty->assign("namenews",$row['namenews']);
$smarty->assign("content",$row['content']);


$smarty->assign("id",$id);
$smarty->assign("namenews",$namenews);
$smarty->assign("content",$content);
}


$smarty->display('artykul.tpl');
?>
Dzięki

Ten post edytował login90 25.09.2019, 12:14:38
Go to the top of the page
+Quote Post
viking
post 25.09.2019, 12:38:09
Post #2





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


Żeby coś widzieć w szablonie to musisz to do niego przypisać. {$art_tresc} to u ciebie content.
Poza tym to jakiś stary projekt czy obudziłeś się z hibernacji?


--------------------
Go to the top of the page
+Quote Post
login90
post 25.09.2019, 13:00:45
Post #3





Grupa: Zarejestrowani
Postów: 52
Pomógł: 0
Dołączył: 8.02.2016

Ostrzeżenie: (0%)
-----


Mam tak
<?php
require_once('connect.php');
require 'libs/Smarty.class.php';
require_once('db_function.php');
$smarty = new Smarty;
$Query='SELECT * FROM news order by id desc ';
$result = db_query($Query) or die(db_error());
while ($row = db_fetch($result))
{

$id[]=$row['id'];
$text[]=$row['namenews'];
$content[]=($row['content']);

}


$smarty->assign("id",$id);
$smarty->assign("namenews",$text);
$smarty->assign("content",$content);

$smarty->display('artykul.tpl');
?>

i wyświetla mi się tyko array
Go to the top of the page
+Quote Post
viking
post 25.09.2019, 13:05:51
Post #4





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


No bo przypisujesz array a w zasadzie jego ostatni element. Może poczytaj o podstawach tablic pętli w php.


--------------------
Go to the top of the page
+Quote Post
login90
post 25.09.2019, 13:11:36
Post #5





Grupa: Zarejestrowani
Postów: 52
Pomógł: 0
Dołączył: 8.02.2016

Ostrzeżenie: (0%)
-----


To weż napisz jak powinno być bo nie moge sam do tego dojść
Go to the top of the page
+Quote Post
viking
post 25.09.2019, 13:14:27
Post #6





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


Jak masz wiele wyników z mysql to zastosuj foreach w smarty.
https://www.smarty.net/forums/viewtopic.php?p=26572


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 25.04.2024 - 07:45