duanpi7578 2014-01-09 13:45
浏览 35

从php嵌入几次从mysql中获取行

i m dealing with 2 tables.I just want to know whether there is something code that helps me fetching rows for multiple times without writing same query for that many times: Example:

while($row1=mysqli_fetch_array($result1)) {
   while($row2=mysqli_fetch_array($result2)){ 
       //checking for some condition 
   } 
}

In above code unlike array we cant reset a variable outside the inner loop as follows

while($row1=mysqli_fetch_array($result1)) { 
   $number=0;//so that v can start from first row 
   while($row2=mysqli_fetch_array($result2)){
     //checking for some condition 
   } 
}

I m totally aware that rows and array are different,So i m asking if there is FOR loop we can use on rows?? like:

while($row1=mysqli_fetch_array($result1)) { 
  for(...){
    //so dat it will xecute no.of whileloops*no.of for loops.
  }
}

if not clear ask for more. Your suggestions are much obliged.

Edit: table: Year 1999 2000 2002 2004 2000 $result=mysqli_query($con,"select distinct Year from table_name"); dataset=mysqli_fetch_array($result)..

  • 写回答

3条回答 默认 最新

  • dsznndq4912405 2014-01-09 13:51
    关注
    $dataSet1 = mysqli_fetch_all($result1);
    $dataSet2 = mysqli_fetch_all($result2);
    foreach($dataSet1 AS $row1){
      foreach($dataSet2 AS $row2){
    
      }
    }
    

    Something like this might work?

    评论

报告相同问题?

悬赏问题

  • ¥15 基于作物生长模型下,有限水资源的最大化粮食产量的资源优化模型建立
  • ¥20 关于变压器的具体案例分析
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo
  • ¥15 科来模拟ARP欺骗困惑求解
  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式