Hello, good people! Help the student. I bring all the information about the product through the cycle:

$result = pg_query("SELECT r.picture, r.name as estate_name, s.name as subcategory_name, r.price, date_trunc('minute', r.datetime) as datetime, r.address, r.square FROM realestate as r left join subcategories as s on s.id = r.subcategory_id ORDER BY r.id LIMIT $quantity OFFSET $list"); $num_result = pg_num_rows($result); for ($i = 0; $i < $num_result; $i++) { $realestate_catalog = pg_fetch_array($result); echo " <div class=\"box-sin\"> <div class=\"col-md-9 single-box\"> <div class=\"box-col\"> <div id = \"forimage\" class=\"col-sm-7 left-side\"> <img class='img-responsive' src='$realestate_catalog[picture]' alt=''> </div> <div class=\"col-sm-5 middle-side\"> <h4>$realestate_catalog[estate_name]</h4> <p><span style = \"margin-right: 7% \" class=\"bath\">Подкатегория </span>: <span class=\"two\">$realestate_catalog[subcategory_name]</span></p> <p><span style = \"margin-right: 17.5%\" class=\"bath1\">Площадь </span>: <span class=\"two\"> $realestate_catalog[square]</span></p> <p><span style = \"margin-right: 16%\" class=\"bath2\">Стоимость</span>: <span class=\"two\">$realestate_catalog[price]</span></p> <p><span style = \"margin-right: 0.5%\" class=\"bath3\">Дата публикации </span>:<span class=\"two\">$realestate_catalog[datetime]</span></p> <p><span style = \"margin-right: 24%\" class=\"bath4\">Адрес</span> : <span class=\"two\">$realestate_catalog[address]</span></p> <div class=\" right-side\"> <a href=\"estateredact.php\" class=\"hvr-sweep-to-right more\" target =\"parent\">Подробнее</a> </div> </div> <div class=\"clearfix\"> </div> </div> </div> </div> "; } 

Then, when I click on the "Details" link, I turn to the page where there is a container for information about one product. There I derive variables from the table I need:

 $doquery = pg_query("SELECT * FROM realestate"); $extract = pg_fetch_array($doquery); $id_in = $extract['id']; $name_in = $extract['name']; $subcategory_id_in = $extract['subcategory_id']; $square_in = $extract['square']; $address_in = $extract['address']; $price_in = $extract['price']; $picture_in = $extract['picture']; $datetime_in = $extract['datetime']; $description_in = $extract['description']; 

Information is displayed about the first product from the database. I need the information to be displayed about the product, next to which I click the link "More". How would this all tie up. Many thanks in advance to those who help.

  • He got the variables that are needed on the page, but now the last entry from the database is displayed. Where to break? - lihim

1 answer 1

pg_fetch_array () returns an array corresponding to the selected row (record).

Also in the documentation:

  • row
    Line number in result for selection. The lines are numbered from 0 to ascending. If the parameter is omitted or passed NULL, the next line will be selected.

The following line in your case is the first line in the selection. Try this

  $extract = pg_fetch_array($doquery,$objectId); // $objectId номер товара. Можно передовать в GET-запросе