I have a small problem with a MYSQL select query involving an INNER JOIN. Both tables that I'm joining have a field that have identical names. So when I use

$array = mysqli_fetch_array($result,1);
$field = array['fieldname'];

it returns the wrong value from the wrong table.

Is there any way around this?

Recommended Answers

All 3 Replies

not really a fix but, how about swapping the order of the tables in the query?
When you have conflicts like that, all kinds of confusion can happen.
change the conflicting name if possible, otherwise do two queries in tandem.

Thanks for your reply, which is the correct order to select the tables in the query?

And also does anyone know if it is possible to combine SELECT * with an AS query like:

SELECT *, project.status AS pstatus

Thanks for your reply, which is the correct order to select the tables in the query?

And also does anyone know if it is possible to combine SELECT * with an AS query like:

SELECT *, project.status AS pstatus

you never posted the query, but the order depends on the objective and which table needs data from the other to perform the join.

the second question is too vaugue but if :
project = database name and status = table , yes you can alias a table.
the columns are referenced like pstatus.date.
Usually you work omn tables within a database which is already set, so
you just do the alias of the table. i like them short like in the MySql docs.
my_big_table_name AS t1, etc...

Speaking of MySql docs, all of this is there for the reading in much more depth.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.