MySQL Forums
Forum List  »  PHP

Re: one to many PHP app - Query problems
Posted by: Peter Brawley
Date: March 11, 2021 11:42AM

> My events table has: id (primary key/index (Is this necessary?))

Yes. A table without a PK isn't a real table. Re-read EF Codd's 12 rules.

> I got the table set up right

That depends on two sets of factors (i) how accurately & thoroughly it matches the requirement (ii) how sound it is as SQL. We have too little info to evaluate (i); (ii) looks ok as far as it goes, but we'd need to see the actaul SQL, then you'll need to test it, following a process like that described in https://www.artfulsoftware.com/dbdesignbasics.html.

Quote

I am having trouble getting all of the events table information into the database. - The query is wrong.

Here is my current query, I hope this is sufficient information to get some help.

"INSERT INTO events(title, description, dateHappens, createdOn) VALUES(?,?,?,?)";

and I am trying to insert the data like this:

($user->getTitle(), $user->getDesc(), $user->getHappens(), NOW()));

We'd need to see the code that's executing. So do you. To do that, have your script echo the sql it's generating, then play with that code in the mysql client program to see what problems need fixing.

> In the sql query how do I get the referenced id primary key in the events table data?

Given a specific user.id value, you need to have stored it in a PHP variable, say $userid, then query the events table with "select ... from events ... where user_id=$userid ...";



Edited 1 time(s). Last edit at 03/11/2021 11:43AM by Peter Brawley.

Options: ReplyQuote


Subject
Written By
Posted
Re: one to many PHP app - Query problems
March 11, 2021 11:42AM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.