Jump to content

mactron

Members
  • Posts

    32
  • Joined

  • Last visited

mactron's Achievements

Member

Member (2/5)

0

Reputation

  1. I would like to write all files from specific folder into .txt file. The output working just fine, but I'm getting only one file saved into my txt file. Any idea? Thanks! $fileList = glob('C:\users\John\Documents\*pdf'); foreach($fileList as $filename){ if(is_file($filename)){ echo $filename, '<br>'; $save_files = fopen("list.txt", "w"); fwrite($save_files,$filename); fclose($save_files); } }
  2. Yes I know, but I would like to link to categories also...
  3. Works like a charm, but I can't set the link pointed to the each category based on category id. Among GROUP_CONCAT(), what is another way to resolve the issue? I would be thankful to you if you could provide me some reference. Thanks!!
  4. echo $model->category_id . " " . $model->model_category_name ; ?>
  5. Now I'm getting error in PHP:: Notice: Undefined property: stdClass::$category_id in C:\laragon\www\sys\admin\people.php on line 19 Notice: Undefined property: stdClass::$model_category_name in C:\laragon\www\sys\admin\people.php on line 19
  6. Should I write another query for categories?
  7. Me again.. I'm fetching data from MySQL but each person in people.php is displayed two times instead one.. The issue must be inside models_category_tbl table, because each person have more then one result. Any advice is appreciated. What should I do? I would like to display people something like that: 1 John Doe 1 IT developer, 3 mechanic models/model = person category = occupation/skills MySQL: model_index table +---------+------------+-------------+-------------------+---------------+----------------+ |model_id | model_name | model_title | model_description | model_country | model_slug | +---------+------------+-------------+-------------------+---------------+----------------+ | 1 | John Doe | Johns title | Johns desc | Hungary | john-doe | +---------+------------+-------------+-------------------+---------------+----------------+ models_category_tbl table +-------------+---------------------+---------------------+ | category_id | model_category_name | model_category_slug | +-------------+---------------------+---------------------+ | 1 | it developer | it-developer | | 2 | photographer | photographer | | 3 | mechanic | mechanic | +-------------+---------------------+---------------------+ models_category_ids table +----+----------+-------------+ | id | model_id | category_id | | 1 | 1 | 1 | | 1 | 1 | 3 | +----+----------+-------------+ PHP function to fecth data: public function getAllModels1 () { $sql = "SELECT * FROM models_index JOIN models_category_ids ON models_index.model_id=models_category_ids.model_id JOIN models_category_tbl ON models_category_tbl.category_id=models_category_ids.category_id" ; $stmt = $this->conn->prepare($sql); $stmt->execute(); $result = $stmt->fetchAll((PDO::FETCH_OBJ)); return $result; } people.php <?php declare(strict_types=1); ob_start(); include "includes/connect.php"; include "includes/functions.php"; $model = new ModelsData(); $models = $model->getAllModels1(); foreach ($models as $model) { ?> <a href="model.php?id=<?= $model->model_id ?>"><img src="<?= $model->model_img_path ?><?=$model->model_img_name ?>"></a> <?php echo $model->model_id . " " . $model->model_name . " " . $model->category_id . " " . $model->model_category_name ; ?> <h3><?= $model->model_name ?></h3> <?php } ?> Output: 1 John Doe 1 IT developer 1 John Doe 3 mechanic
  8. From insert query for posts.. $id = $this->conn->lastInsertId(); I would like something like this.. +----+---------+-------------+ | id | post_id | category_id | +----+---------+-------------+ | 1 | 2 | 3 | | 2 | 2 | 5 | | 3 | 3 | 1 | | 4 | 3 | 2 | +----+---------+-------------+ The hole problem is inside my array.
  9. I'm trying to insert array of posts categories into MySQL. I'm getting category IDs from drop down list.. ERR: Notice: Notice: Array to string conversion in C:\laragon\*********\includes\functions.php on line 477 Array Array ( [0] => Array ( [0] => 4 [1] => 5 ) ) PHP try { $sql = "INSERT INTO posts_category_ids (post_id, category_id) VALUES"; $insertQuery = array(); $insertData = array(); foreach ($filter_category as $row) { $insertQuery[] = '(?, ?)'; $insertData[] = $id; $insertData[] = $row; } if (!empty($insertQuery)) { $stmt = $this->conn->prepare($sql); $stmt->execute($insertData); //477 } }catch (Exception $e){ echo $e->getMessage(); } }
  10. I'm working on a simple CMS system. So my question is how to add categories of blogs inside database correctly. If I understand EAV I need to add two tables; one table for names, descriptions of categories and one table for categories IDs and posts IDs. I'm correct? Cheers blog_tbl +------+---------+--------+---------------+-------------------+---------+ | b_id | b_title | b_text | b_seo_title | b_seo_description | slug | +------+---------+--------+---------------+-------------------+---------+ | 1 | Title 1 | txt 1 | 70 charsets | 170 charsets | title-1 | | 2 | Title 2 | txt 2 | 70 charsets | 170 charsets | title-2 | +------+---------+--------+---------------+-------------------+---------+
  11. I will do that way but I'm worried about too many JOINS. I already have 3 queries with 3 JOINS in each.
  12. Ahh I see, another table & another JOIN..
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.