Jump to content

mactron

Members
  • Content Count

    30
  • Joined

  • Last visited

Everything posted by mactron

  1. Yes I know, but I would like to link to categories also...
  2. 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!!
  3. echo $model->category_id . " " . $model->model_category_name ; ?>
  4. 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
  5. Should I write another query for categories?
  6. 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
  7. I just resolve the issue!
  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..
  13. Sorry, but what do you mean with multiple, I would simple update that columns ..
  14. Yeah I'm using InnoDB .. What about if someday I decided to add likes, dislikes and views for each person. That's mean 3 additional columns inside people_tbl and 13 columns in total. I'm worried about JOINS because I already use three JOINS in one query. I have heard people complain that JOINS may be pretty slow. Thanks!
  15. Done with JOINs and work like a charm. Thanks! Just another question .. I would like to add photo of each person, so I will have two additional columns inside my persons_tbl (person_avatar_path, person_avatar_name). Is it better to create new table for avatars?
  16. I have three tables, people_tbl, people_category and people_country, but let's get focused on 1st and 2nd table only. people_tbl = people and their info (please check MySql architecture above) people_category_tbl = occupation Witch my code below, I fetch the data between both tables. All the data are correctly fetched and completely relevant. Actually everything works just fine, but I'm curious If I'm on the right path. is there anything that I can fix, improve.. Should I use only one query with JOIN syntax? Thanks! func.php <?php class PeopleData extends dbh{ public function getPeople () { $sql = "SELECT * FROM people_tbl"; $stmt = $this->conn->prepare($sql); $stmt->execute(); $result = $stmt->fetchAll((PDO::FETCH_OBJ)); return $result; } public function getPeopleCategoryName() { $sql = "SELECT * FROM people_category_tbl"; $stmt = $this->conn->prepare($sql); $stmt->execute(); $category = $stmt->fetch(PDO::FETCH_OBJ); if($category == null) { return null; }else { return $category->people_category_name; } } } fetch.php <?php $people = new PeopleData(); $peoples = $people->getPeople(); $category = new PeopleData(); ?> <?php foreach ($peoples as $people) { ?> <?php echo $people->people_id . " "; echo $people->people_name . " "; echo $category->getPeopleCategoryName($people->people_category) . " "; ?>
  17. Try $msg = "<script type="text/javascript"> $(document).ready(function(){ demo.initChartist(); $.notify({ icon: 'pe-7s-gift', message: 'TESTING!' },{ type: 'info', timer: 4000 }); }); JS; print '<script>'.msg.'</script>'; P.S. Your code is not safe. Use PDO instead MySQLi.
  18. Hello, I have a table with people and some details insde. So, my question is if my MySQL architecture down below is good or not. Should I devide the table into two tables and kept only p_id, p_name and p_slug inside my table (people_tbl). Thank you! p = person p_description = bio p_category = occupation (people_category_tbl) people_tbl +------+---------+---------+---------------+-------------+-------------------+-----------+------------+---------+ | p_id | p_name | p_title | p_description | p_seo_title | p_seo_description | p_country | p_category | p_slug | +------+---------+---------+---------------+-------------+-------------------+-----------+------------+---------+ | 1 | John Li | title | johns bio | 70 charsets | 170 charsets | Germany | 1 | john-li | | 2 | Bob Stu | title | bobs bio | 70 charsets | 170 charsets | Italy | 2 | bob-stu | +------+---------+---------+---------------+-------------+-------------------+-----------+------------+---------+
  19. persons_tbl person_id | person_name | person_surname | person_description | person_slug -----------+--------------+-------------------+--------------------+------------- 1 | John | Doe | bla bla bla | john-doe 1 | Jane | Doe | bla bla bla | jane-doe 2 | Greg | Stue | bla bla bla | greg-stue -----------+--------------+----------------+--------------------+------------- persons_web_tbl person_web_id | person_web_linkedin | person_web_twitter | person_web_facebook | person_web_website | person_id ---------------+----------------------+--------------------+---------------------+--------------------+--------- 1 | linkedin.com/john | twitter.com/john | facebook.com/john | www.johndoe.com | 1 1 | linkedin.com/jane | twitter.com/jane | facebook.com/jane | www.janedoe.com | 2 2 | linkedin.com/greg | twitter.com/greg | facebook.com/greg | NULL | 3
  20. persons_web_tbl will look something like that person_web_id | person_web_linkedin | person_web_twitter | person_web_facebook | person_web_website | person_id
  21. From form ... I have two person tables, both get data from forms. I just added $person_web_twitter = "add something" and echo "found"; to test the class.. table 1 -> table person_tbl as an index of all people. table 2 -> persons_web_tbl where I will store people's links such as websites, twitter & facebook profiles. So, that's wrong approach?
×
×
  • 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.