doushe8577 2015-05-25 13:18
浏览 25
已采纳

我想从第一个表中获取数据然后再次需要使用第一个表从另一个表中获取第二个数据,其中value [关闭]

I have 3 tables, 1). mobile, 2). store1, 3). store2 Fetching from table "mobile" then we received 4 rows of record from table. then i am fetching this row to store1 and store2 for other details.

Please suggest me what i need to do.

<?php
$mysqli = new mysqli("host" , "user" , "pass" , "database");
$result = $mysqli->query( "SELECT * FROM mobile WHERE live= '1' ") ;
while ( $rows =  $result->fetch_assoc() ) {

$store = $rows["store"];
$productId = $rows["productId"];
$store2 = $rows["store2"];
$productId2 = $rows["productId2"];

php?>

<?php
$result = $mysqli->query( "SELECT * FROM $store where productId='$productId' ") ;
while ( $rows =  $result->fetch_assoc() ) {

$title = $rows["title"];

$productImage = explode (",", $rows['imageUrlStr']);
$mrpPrice = explode (",", $rows['mrp']);
$offerPrice = explode (",", $rows['price']);
}

$result = $mysqli->query( "SELECT * FROM $store2 where productId= '$productId2'  ") ;
while ( $rows =  $result->fetch_assoc() ) {

$title2 = $rows["title"];

$productImage2 = explode (",", $rows['imageUrlStr']);
$mrpPrice2 = explode (",", $rows['mrp']);
$offerPrice2 = explode (",", $rows['price']);
} ?>

    <li class="mobile-box als-item">
        <div class="mobile-box-top">
            <div class="mobile-box-top-img"><img src="<?php echo $productImage[5]; ?>" alt="" title="" /></div>
            <div class="mobile-box-top-txt"><?php echo $title; ?></div>
            <div class="mobile-box-top-tag"><i class="fa fa-inr"></i> <?php echo $offerPrice[0]; ?></div>
        </div>
        <div class="mobile-box-bottom border-bottom">
            <div class="mobile-box-bottom-img"><img src="<?php echo $productImage2[5]; ?>" alt="" title="" /></div>
            <div class="mobile-box-bottom-txt"><?php echo $title2; ?></div>
            <div class="mobile-box-bottom-tag"><i class="fa fa-inr"></i> <?php echo $offerPrice2[0]; ?></div>
        </div>
        <div class="mobile-box-button"><a href="">Compare Now</a></div>
    </li>
  • 写回答

1条回答 默认 最新

  • doubei2340 2015-05-25 13:33
    关注

    you have to do in this way

    step 1 : try to fetch the query like this as you are take the data in result

    so try to make like this

    $result1 = $mysqli->query( "SELECT * FROM $store where  productId= $result.productId ") ;
    

    same for the table two

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)