How do I use get_compiled_select or count_all_results before running the query without getting the table name added twice? When I use $this->db->get(‘tblName’) after either of those, I get the error: If I don’t use a table name in count_all_results or $this->db->get(), then I get…
Tag: mysql
Few, complex OR many, simple MySQL queries?
Im working on a onlineshop with php. I work with the mvc model and I divide each small part of my application in: model view controller and service ( service is there for the query ). So for example I would have a Item cart which is divided in discription and price… For each of them I would have a
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row in Laravel9
I have an integrity constraint violation when I run the php artisan db:seed command in Laravel 9. Error PDOException::(“SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (hunger-db.restaurants, CONSTRAINT restaurants_user_id_foreign FO…
How to get multidimensional array grouped by multiple columns in PHP from single MySQL table?
I have table called “guids” that looks like this: From that I would like to get data in this format: Basically, I need to use multiple columns to build a nested array with grouped data. I know that I can achive that structure using foreach loop like this: But if possible I would like a more optimi…
PHP Convert in date and update a database (PhpMyAdmin) with a date (like 22:43:50)
i don’t understand why i can’t update my DataBase with times like “21:20:46”. My table in PhpMyAdmin is in time unit. i already tried to update time differently like SET time = 212046 and it updated my table to 21:20:46 Answer FROM_UNIXTIME is amysql function that will work just fine |…
Laravel 8 – Eloquent Queries Without Database Migration
I’m a newbie with Laravel, but old school PHP developer. I’m in the process of adapting my framework to the Laravel framework. My main goal at this moment is to use eloquent queries without doing a DB schema and migration inside Laravel, as I have my database is built already, up and running. So far, I’ve bee…
Datatype date is not updating in mysql using laravel
A column named ‘Shipment’ in import_request_trackers table having the datatype of Date and initially the default value is null. But when I tried to update the column from another form manually it shows no error but the database table is not being updated. } Answer 1- check your route first, please…
Recount SQL auto increment ID while keeping the other columns intact
I have a table like this ID NAME 1 MICHAEL 2 JORDAN 5 DONALD 7 JAYCE 8 ROY 11 JOHN 16 DOE Is there a way to recount the ID from the beggining so there is a sequel and keeping the others columns intact to be like this: ID NAME 1 MICHAEL 2 JORDAN 3 DONALD 4 JAYCE 5 ROY
SQL – Selecting a users conversation based on members
I am trying to formulate a query to select a conversation based on members passed in, this can be many participants. Users can have multiple conversation with the same users in, and they can rename conversations. Here is my messages members table: And the messages relation table: Messages table for reference:…
Eloquent relationship where not in sub-query
I have got a relationship where I select all row’s based on the category, however I need to exclude some of these if they are within a sub query. So above is my code, nearly works as I want it, however it seems that the $q variable doesn’t have the table name within the query, below is the query o…