I can not understand what this condition literally means:

if($data=mysql_fetch_row($res)) { } 

This condition is part of the id check.

The $res variable contains an array with the result of mysql_query .

    2 answers 2

    Call the mysql_fetch_row method, which returns the next line of the result, and save it to the data variable. If what is stored in data is not equal to FALSE (that is, there are no more records), then the condition is true.

    This can be rewritten so:

     $data=mysql_fetch_row($res); if($data) { } 

    In your case, apparently, only one record is checked.

    This recording format is quite popular, it allows you to save one, and sometimes two lines, although readability usually suffers a lot.

    • Yes. This is an id check. all the code looks like this. $ res = mysql_query ('select * FROM'. $ carBrand. 'where id ='. (int) $ _ GET ['id']); if ($ data = mysql_fetch_row ($ res)) {} else {header ("HTTP / 1.1 404 Not Found"); header ('Location: ./ 404.php'); exit (); } But I can not understand. It turns out that if strings with such id exist then we execute the code further. if not, then 404 error. And if you need to check a few parameters? for example id, marka, model? how then to write this code? - Makdak
    • if you need to check several parameters, then you need to think about how exactly you need to check, make a request and check. For example, if you need to check that there is an entry for this model and brand (that is, on one line), then you just need to rewrite the query select * FROM '. $ CarBrand.' where model = '. $ _ GET [' model '].' and marka = '. $ _ GET [' marka '] true to insert get parameters directly into the request - this is a very bad idea - for one test it is normal, for everything else - sadness, sadness. - KoVadim

    See the office. documentation, it clearly states what the function is and what it returns http://php.net/manual/ru/function.mysql-fetch-row.php
    Specifically, this condition checks whether there is still data to be sampled from the database.

    • @ Anton Lakotko, well, still not. This function pulls the following result, and if it does not, then returns false. That is, this condition checks whether the function has pulled out any data. - etki
    • @Etki yes, you are right. Not correctly expressed his thoughts, even erroneously. - Anton Lakotko September