In one MYSQL query, the data is taken from 3 tables in 2 of which fields with the same name are t1.alt_name and t3.alt_name. Here is the code:

$query = mysql_query( 'SELECT t1.id, t1.title, t1.autor, t1.date, t1.category, t1.short_story, ***t1.alt_name***, t2.images, t2.news_id, t3.id, t3.alt_name FROM dle_post AS t1, dle_images AS t2, dle_category AS t3 WHERE t1.id = t2.news_id, t1.category = t3.id ORDER BY date DESC') or die("Invalid query: " . mysql_error()); 

Tell me how to correct this request correctly so that later in the code, these would be different variables in the array.

    1 answer 1

    You can assign a pseudonym to a column with a conflicting name using the AS keyword, just as you assign aliases to the tables in the FROM clause.

     $query = mysql_query( 'SELECT t1.id, t1.title, t1.autor, t1.date, t1.category, t1.short_story, t1.alt_name AS t1_alt_name, t2.images, t2.news_id, t3.id, t3.alt_name FROM dle_post AS t1, dle_images AS t2, dle_category AS t3 WHERE t1.id = t2.news_id, t1.category = t3.id ORDER BY date DESC') or die("Invalid query: " . mysql_error()); 

    Further, in the resulting table you can refer to such a field by the name t1_alt_name , as if the table has a column with that name.