Answer the question
In order to leave comments, you need to log in
Codeigniter how to create a directory correctly?
Good afternoon, I'm studying Codeigniter, I don't have much experience in PHP development.
At the moment, the task is to create a catalog of two related tables, unfortunately I can’t figure out how to do it correctly)
Table structure
mysql> desc items;
+----------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+------------------+------+-----+---------+----------------+
| id | int(11) unsigned | NO | PRI | NULL | auto_increment |
| items_id | int(11) unsigned | YES | MUL | NULL | |
| title | varchar(128) | YES | | NULL | |
| userfile | varchar(128) | YES | | NULL | |
+----------+------------------+------+-----+---------+----------------+
4 rows in set (0.06 sec)
mysql> desc category;
+-------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+------------------+------+-----+---------+----------------+
| category_id | int(11) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(128) | YES | | NULL | |
+-------------+------------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
<?php
var_dump($uniq);
foreach ($uniq as $uniq_item)
{
$uniq_item['name'];
}
?>
<?php foreach ($category as $category_item): ?>
<a style="display: block" href="/catalog/<?= $uniq_item['name'] ?>"><?= $category_item['name'] ?></a>
<?php endforeach ?>
Answer the question
In order to leave comments, you need to log in
1. Database fields, and functions too - should be named in such a way that it would be clear what is at stake.
That items_id is a category_id is not obvious at all
2. Don't use *. This is potentially a source of wild hemorrhoids. Do not be lazy to list the fields with the names of the tables.
3. ALWAYS use sorting in sql.
4. I didn't really understand from the code and description what exactly you want to do.
List categories? Display tree category-products? What?
What does it have to do with some news? What's with all the links?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question