Hello.

Help, plz, optimize the code. Here he is:

$result = mysql_query("SELECT * FROM `video_dating` ORDER BY id DESC",$db); while($myrow = mysql_fetch_array($result)){ $result_user = mysql_query("SELECT * FROM `go-users` WHERE id='".$myrow['author']."'",$db); $myrow_u = mysql_fetch_array($result_user); //параметры дальше выводятся } 

And I'm trying to make a complex query, but something does not work.
Here is what I write:

 $result = mysql_query("SELECT `video_dating.author`,`go-users.id` FROM `video_dating` JOIN `go-users` ON `video_dating.author`=`go-users.id` ",$db); $myrow = mysql_fetch_array($result); 

As a result, he writes:

Database Error. MySQL writes: Unknown column 'video_dating.author' in 'field list'

Help, plz.
In general, how can you simplify the code of the above worker, the topmost one? I will be very grateful.

    1 answer 1

    Try to change

     SELECT `video_dating.author`,`go-users.id` 

    On

     SELECT `video_dating`.`author`,`go-users`.`id` 

    and further too. In quotes taken each identifier. Those.

     `идентификатор таблицы`.`идентификатор поля` 

    Update

    You can refer to the fields

    • full name таблица . поле
    • if a table is given an alias, then by псевдоним . поле
    • In the select expression, to select both fields, for example, id from one table and from another, you can specify an all-name for the select field, the таблица . поле as alias.

    An example of how queries with aliases usually look like:

     SELECT vd.author, vd.id as vd_id, gu.id as gu_id FROM `video_dating` as vd JOIN `go-users` as gu ON vd.author=gu.id 
    • thank you very much, the error has disappeared, I will know) - Dminko93
    • and I also have an id in two tables, how do I turn to one? - Dminko93
    • @ Dminko93, you can * access fields by the full name of the таблица . поле * if the table is given an alias, then by псевдоним . поле * in the select expression, to select both fields, for example, id from one table and from another, you can set an all-name for the select field, таблица . поле as alias. An example of how queries with aliases usually look like: SELECT vd.author, vd.id as vd_id, gu.id as gu_id FROM video_dating as vd JOIN go-users as gu ON vd.author = gu.id - Yura Ivanov