Jump to content


  • Content Count

  • Joined

  • Last visited

  • Days Won


Barand last won the day on February 17

Barand had the most liked content!

Community Reputation

1,448 Excellent

About Barand

  • Rank
    Sen . ( ile || sei )

Profile Information

Recent Profile Visitors

60,943 profile views
  1. Also, change the order of the code in your page, putting the php section first. Code flow should be something like this if POST data exists Validate data storing error messages if no errors do updates header("location: #") // reload page exit end if end if if GET data process GET data endif any other code necessary for building page e.g. menus !DOCTYPE html html output any validation error messages form form fields end form end html
  2. Nearly - you need to test $del[$key], not just $del
  3. E.G. $res = $conn->query("SELECT i.model_id , i.model_name , c.category_id as cat_id , c.model_category_name as cat_name FROM model_index i JOIN models_category_ids USING (model_id) JOIN models_category c USING (category_id) "); $data = []; foreach ($res as $r) { if (!isset($data[$r['model_id']])) { $data[$r['model_id']] = [ 'name' => $r['model_name'], 'cats' => [] ]; } $data[$r['model_id']]['cats'][$r['cat_id']] = $r['cat_name']; } /* $data = Array ( [1] => Array ( [name] => John Doe [cats] => Array ( [1] => IT Devloper [3] => Mechanic ) ) [2] => Array ( [name] => Laura Norder [cats] => Array ( [2] => Photographer ) ) ) */
  4. The link in your code is to the model_id Add "i.model_id" to the selected columns in the query, then the output will have $model->model_id If you need individual category_ids, revert your query to that getting several rows for each model and store the results in an array, indexed by model, so each model has an array of categories.
  5. My query returns two output columns model_name cats Try echo model->model_name . " " . $model->cats . "<br>"; (of course, without seeing the code that actually runs the query and gets the results, that's just a guess.)
  6. One way is with GROUP_CONCAT() SELECT i.model_name , GROUP_CONCAT(c.category_id,' ',c.model_category_name SEPARATOR ', ') as cats FROM model_index i JOIN models_category_ids USING (model_id) JOIN models_category_tbl c USING (category_id) GROUP BY i.model_id;
  7. ... or as you are using mysqli, put this line before your connection creation mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
  8. Below is an extract from the mysql reference manual As you can see, with the exceptions of "PRIMARY KEY" and "FOREIGN KEY" (which can be considered to be reserved phrases) the terms "index" and "key" are interchangeable.
  9. That would the meet the requirement for "logical, meaningful and unique". Beware name clashes though. They (constraint names) need to be unique within the scope of the database schema. Table alias name scope is only the query.
  10. As with the example I gave earlier for an index name (idx_xxx_yyy) then use similar for, say, foreign key constraints (FK_xxx_yyy) Keep them logical, meaningful and unique (eg FK_Pinocchio )
  11. Disney character names for constraints
  12. To me it sounds like I don't name them because they will be given reasonable names automatically
  13. I'm surprised it got past the prepare statement before giving an error. Where do $id and $row come from? Are the two sections of code above related in any way? If, say, you want to add 3 records inserting post_id and category_id into each then the query that gets prepared should look like "INSERT INTO posts_category_ids (post_id, category_id) VALUES (?,?),(?,?),(?,?)"
  14. I name mine after Harry Potter characters. However if I create an index without a name using MySQL Workbench it auto names it for me. If I index column yyy in table xxx it gives it the name "idx_xxx_yyy"
  • 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.