duanhuo7441 2019-02-22 21:09
浏览 55
已采纳

通过用户选择的随机ID显示无限行(由php创建)

I need to display row from different table with random id that what i make it php generate it when i add new car or new driver

For example :

In this image table record's for same driver and different Car

reports image and in this image the records for random id for the car

cars image

I need to show every records by date for same driver and Which car he use

Note: In this case its show like this

wrong view

and I need it show like this

right view

and sorry for arabic database records tell me if there anything not understood

my code:

<?php
require 'config.php';
$query = "SELECT * FROM `driversuser`";
$result1 = mysqli_query($con, $query);

?>
<div class="container">
    <div class="addingcar">
        <form dir="rtl" action="#" method="post">

            <div class="">
                <b>عرض وردية سائق</b>
            </div>

            <br/>
            <label>
                <b>اختر السائق</b>
                <select name="insdname" id="framework" class="align-right selectpicker" data-live-search="true">
                    <option style="text-align: right" value="">اختر السائق ...</option>
                    <?php while($row1 = mysqli_fetch_array($result1)):; ?>
                        <option style="text-align: right" value="<?php echo $row1[10]; ?>"><?php echo $row1[1]; ?></option>
                    <?php endwhile; ?>
                </select>
            </label>
            <br />
            <label>
                <b>من</b>
                <input type="date" name="datefrom">
            </label>
            <br />
            <label>
                <b>الي</b>
                <input type="date" name="dateto">
            </label>
            <br /><br />
            <input type="hidden" name="hidden_framework" id="hidden_framework" />
            <input type="submit" name="submit" class="btn btn-info" value="عــــرض" />

        </form>
        <?php
        if(isset($_POST['submit'])){
            $selected_val = $_POST['insdname'];
            $date_val = $_POST['datefrom'];
            $dateto_val = $_POST['dateto'];
            $report = mysqli_query($con, "SELECT * FROM `reports` WHERE Datefrom BETWEEN '$date_val' AND '$dateto_val' AND DriverCode = '$selected_val' ORDER BY Datefrom");
            while ($datareport = mysqli_fetch_array($report)) {
                echo $datareport['Datefrom']." ".$datareport['DateTo']." ".$datareport['Price']." ".$datareport['PriceTaken']." ";
                


            $report2 = mysqli_query($con, "SELECT * FROM `reports` WHERE DriverCode = '$selected_val' GROUP BY CarCode");
            while ($datareport2 = mysqli_fetch_array($report2)) {
                $carcode = $datareport2['CarCode'];

            }
            $report3 = mysqli_query($con, "SELECT * FROM `cars` WHERE Car_ID = '$carcode'");
            while ($datareport3 = mysqli_fetch_array($report3)) {
                echo $datareport3['CarName']." ".$datareport3['CarModel']." ".$datareport3['CarNumber']." ".$datareport3['CarColor']." ";
                echo '<br/>';
            }};
        }
        ?>

    </div>
</div>

</div>

展开全部

  • 写回答

1条回答 默认 最新

  • dqcd84732 2019-02-23 12:20
    关注

    I don't have your database schema, but I tried to create one for testing. So, try this:

    SELECT * FROM reports r1 INNER JOIN cars c1 ON r1.carcode = c1.car_id ORDER BY r1.date
    

    r1 is a shortcut for reports table ( change it to whatever you like ).

    c1 is a shortcut for cars table ( also, you can change it ).

    You can read more about INNER JOIN.

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

报告相同问题?

悬赏问题

  • ¥15 各位专家求此答案解析
  • ¥15 llama-factory训练日志epoch为什么是浮点数?
  • ¥500 我想做一个股票策略的回测AI工具(网页版)python语言、Pine Script
  • ¥15 生信空转NICHES分析中runNICHES函数报错
  • ¥30 地学数据三维可视化基于克里金插值的三维可视化
  • ¥15 stc8g1k08a-sop8控制led代码问题。
  • ¥50 让画布在弹出的新的浏览器页面上运行绘画
  • ¥15 mbed库rsa算法段错误
  • ¥15 SG-cyclic模式Axi-Dma,如何实时更新缓存区内数据
  • ¥15 Mysql 一张表同时多人查询和插入怎么防止死锁
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部