So I have a bespoke CMS that allows dynamic creation of forms and lists etc. I have noticed an issue where it grabs the data for the list, which is conflicting with an approval table in the database.
The problem is, if the table with the data has fields names the same as field names in the approvals table, then when i mysql_fetch_array and it returns the values in an array, it will only return one field name
So an example of what is being returned
Array
(
[id] => 1
)
And ideally I would want it returned as
Array
(
[approvals.id] => 1
[affiliates.id] => 2
)
So how can I make it prefix the table name to the results array to counteract field names called the same thing? I dont want to go through changing the field names as its pretty embedded.
Normally you use an alias in the SQL sentence:
SELECT table1.id as t1_id, table2.id as t2_id FROM .....
Then when you have the fetching, you will access it this way:
echo $row['t1_id'];
Use mysql alias
approvals table id alias as [id AS approvals.id]
affiliates table id alias as [id AS affiliates.id]
Use an alias in the query:
SELECT approvals.id AS approvals_id, affiliates.id AS affiliates_id ...
The associative array will then contain:
echo $row['approvals_id'];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With