开发者

While inside while, giving problem

Good morning everyone.

I have a doubt.

I have two table, behind a data request. And another product of the application

EX:

Request: 1
   >> Plan 1 Value: 10.00
   >> Plan 2 Value: 20.00
Request: 2
   >> enter service Value: 10.00

More'm not getting the list thereby placing To other while inside the other.

Repede is not there anymore the request.

My code.

 $query = $this->_CONEXAO->prepare("SELECT * FROM disk_request WHERE request_id = :id ");
 $query->bindParam(":id", $id, PDO::PARAM_STR, 20); 
 $query->execute();
 while ($row2 = $query->fetch()){ 
     echo '<div id="request">'.$row2["request_cod"].'';

     $request = $row2["request"];   
     $query = $this->_CONEXAO->prepare("SELECT * FROM disk_product WHERE cod_request  = :cod");
     $query->bindParam(":cod", 开发者_如何学Python$request, PDO::PARAM_STR, 20); 
     $query->execute();

     while ($row_product = $query->fetch()){ 
         // here is list the products of the order is just above an application for various  products can be a 2,3,4 or products on the list ...
         echo '<div> >> </div><div>'.$row_product["product"].'</div>';
     }
 }

I would be very grateful for the help ..


Your second $query is replacing the first one, which'll mess up the first while.

Rename the second $query to $query2 and it should work.


Why don't you do something like

SELECT * FROM disk_request,disk_product WHERE
disk_product.cod_request=disk_request.request and request_id = :id

queries in queries is not really nice and doesnt use sql optimizations ..

If you want to only select some informations, you could do :

SELECT disk_request.request_cod as request_cod, disk_product.products as product 
FROM disk_request,disk_product 
WHERE disk_product.cod_request=disk_request.request and  request_id = :id 
GROUP BY disk_request.request_cod

Then you do only one loop and you check when the disk_request changed from previous one, you put your <div id="request">


You're stomping on the outside loop's $query. Use a different variable for the inside loop.


You reuse the $query object, and that's what causes trouble.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜