question

swarner22 avatar image
swarner22 asked

How do you use the "references" keyword properly?

I've created a table in a MySQL database that has three columns. The names are (first_name, last_name, email, reference_id). The column named reference_id is Integer, Auto_increment, Primary key. In my PhP I've an Intval($_GET['id'] set up as a URL Parameter. What I would like to do is have some sort of query statement applied, allowing me to reference the data from the other columns of the same table, that are strings, like so. ALTER TABLE Tableone MODIFY COLUMN (reference_id) REFERENCES (first_name); Is this possible, is there a better way, tips, tricks, I'm early in my programming life so take it easy on me :) Seth
sqldatabasemysqlphp
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
Tom Staab avatar image
Tom Staab answered
I'm not familiar with MySQL, so I looked up the REFERENCES keyword. It is used to establish a foreign key relationship. Is that what you are trying to do?
1 comment
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

hey tom, I think I found out you can't use the reference keyword in the way I wanted to. I what I wanted to do was somehow obtain the data from a database into my php through its primary key numbers. So in php instead of just typing in the column name that contains the strings I want to obtain as results in php I wanted to type the column name of a column that was auto_incrementing along side it. So using one columns auto incrementing numbers to call the column next to it, associated with it. I was trying to figure out how to join to columns together that are in the same table.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.