Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

problem with html_radios

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
almlf
Smarty n00b


Joined: 15 Dec 2019
Posts: 1

PostPosted: Sun Dec 15, 2019 5:43 am    Post subject: problem with html_radios Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1615

PostPosted: Sun Dec 15, 2019 8:32 am    Post subject: Re: problem with html_radios Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP