2
Following guys I’ve reviewed this community and got some nice fonts but did not help me, I’m trying to separate my links by categories that are also stored in the database.
If anyone has a tutorial to pass me thanks.
See the prints below
1st print category table 2nd print link table 3rd print home page
As you can see in the third image, it’s not separating by categories it’s a tremendous mess, now let’s go to the codes:
My model:
<?php
class Docs_Model extends Model {
public function __construct() {
parent::__construct();
}
public function getCategories() {
return $this->_db->read('SELECT * FROM ' . DATABASE_PREFIX . 'cats', array());
}
public function getDocsCategories() {
$data = $this->getCategories();
$arr = [];
foreach ($data as $value) {
$arr = $value;
}
//return $this->_db->read('SELECT * FROM ' . DATABASE_PREFIX . 'docs WHERE id_cat=:id', array(
// ':id' => $arr['id_cat']
//));
return $this->_db->read('SELECT * FROM ' . DATABASE_PREFIX . 'docs c1, ' . DATABASE_PREFIX . 'docs c2 WHERE c1.id_cat = 1 AND c1.id_cat = c2.id_cat', array(
//':idcat' => $arr['id_cat']
));
}
}
My view:
<section class="section">
<div class="container">
<div class="row">
<div class="col-md-3">
<?php foreach($data['cats'] as $key => $value): ?>
<div class="panel panel-default">
<div class="panel-heading"><?php echo $value['title'] ?></div>
<div class="list-group">
<?php foreach($data['docs'] as $key2 => $value2): ?>
<a href="#" class="list-group-item"><?php echo $value2['title'] ?></a>
<?php endforeach; ?>
</div>
</div>
<?php endforeach; ?>
</div>
If you need more information I have, I expect help.
looks almost worked out, see print, note that this listing all the same :/ http://i.imgur.com/8Toz1bR.png
– Guilherme SpinXO
is would have to look like this: http://i.imgur.com/sS7dPur.png, look at the prints dad my table, onte id 1 = starting, 2= basic, 3 = helpers, and what’s happening is this: http://i.imgur.com/v3cylJI.png ta tense :/
– Guilherme SpinXO
That’s right, the first query will bring you code and category name, so the GROUP BY ( Getting(1), Basic(2) and Helpers(3)). And with the subconsultation you take the code of each record and bring your data with the WHERE clause (in the case id_cat (1,2 or 3) see A.Category, A.id_cat) with the code that came in the query using GROUP_CONCAT(). In subconsultation you say: (bring all records where id_cat = A.id_cat ).
– Gilberto M G
I’ll try to tidy up, with the tips you gave me I think should be possible, if I can get back here and mark the answer as solved att.
– Guilherme SpinXO
It’s hard to go to sleep, tomorrow I continue, thanks for the help.
– Guilherme SpinXO
I performed a scenario and managed to reach the expected result. I edited the answer. See if you can finish, just remembering that the return needs to be treated.
– Gilberto M G
The direct query in phpmyadmin returns everything to me correctly, however, in logic in my model still keeps returning as in print. :/
– Guilherme SpinXO
I think the problem is in the display there look my code in my view, first time in 3 years fiddling with PHP that I get into a gambiarra of these kkkkkk
– Guilherme SpinXO
Put the query according to its logic here getCategories(); and print_r here getDocsCategories() to see the return. I would send $data to the view and give it a var_dump or print_r() to see what it brings.
– Gilberto M G
You’re really gonna have to go through your view. in your first foreach gets 03 items like id_cat, title and a long return string, for each row of the first the second foreach you do using a explode to treat the return.
– Gilberto M G
Let’s go continue this discussion in chat.
– Guilherme SpinXO
I marked as solved, what I wanted you explained to me and it worked out now is only adjustments, I am now having difficulty in receiving in the view
– Guilherme SpinXO