|
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 |
almlf Smarty n00b
Joined: 15 Dec 2019 Posts: 1
|
Posted: Sun Dec 15, 2019 5:43 am Post subject: problem with html_radios |
|
|
hi All,
greetings,
i have two table and im using PDO in my work
1st Table have columns ( Name Table is Genre )
ID TAG NAME
2nd Table have columns ( Name Table IS Genre_relation )
ID item_id Genre_id
the query like this in class
Code: |
//function name is getgenresList
$query = $this->db->prepare("SELECT * FROM `genres`");
$query->execute();
$total = $query->rowCount();
if($total != 0){
while($row = $query->fetch(PDO::FETCH_ASSOC)){
$array[] = $row;
}
return($array);
}else{
return(false);
}
$data = $vareble->getgenresList();
$smarty->assign('data',$data);
|
in template
Code: |
{foreach from=$data item="g"}
<tr>
<td>{$g.name}</td>
<td>{$g.tag}</td>
<td>{$g.id}</td>
<td>{request}</td>
</tr>
{/foreach}
|
my question that i want to get total item in table Genre_relation related to the Genre and the result it will be in row {request}
the second question if i make edit to this item i want to make genre list all and checked all genre what in the table Genre_relation related to the item id |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sun Dec 15, 2019 8:32 am Post subject: Re: problem with html_radios |
|
|
almlf wrote: | $query = $this->db->prepare("SELECT * FROM `genres`"); |
SELECT without WHERE is almost always an error.
Quote: | $total = $query->rowCount(); |
rowCount() only counts affected rows in INSERT/UPDATE/MERGE statements, and is not reliable for SELECT statements.
Quote: | if($total != 0){
while($row = $query->fetch(PDO::FETCH_ASSOC)){
$array[] = $row;
}
return($array);
|
Useless code is useless.
Replace it with
Code: | return $query->fetchAll(); |
Quote: | }else{
return(false);
} |
Why your function returns two different types of result?
That's bad. Remove this crap.
Quote: | my question that i want to get total item in table Genre_relation related to the Genre and the result it will be in row {request} |
Then get that data from DB and pass it to the template.
Quote: | the second question if i make edit to this item i want to make genre list all and checked all genre what in the table Genre_relation related to the item id |
wat |
|
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
|