如何使用MySql和PHP绘制图形条线?

时间:2015-06-09 17:02:08

标签: php mysql graph progress-bar

我正在尝试显示一个图形栏,以便在wordpress网站中使用MySql和PHP显示单个栏中特定日期的总座位数。

我的表格标记:

<strong>Check your desired date if it is available already in the system.</strong><br/><br/>
<form action="<?php echo get_permalink();?>" method="post" class="van_sharing_reference">
    <script type="text/javascript">
        jQuery(document).ready(function() {
            jQuery('.search_input_text_van').datepicker({
                dateFormat : 'yy-mm-dd'
            });
        });
    </script>
    <input type="text" placeholder="Select the date" required name="search_text" class="search_input_text_van">
    <span class="arrow">
        <input type="submit" value="CHECK" name="search" class="search_button">
    </span>
</form>

和行动:

<?PHP 
    if (isset($_POST['search'])){
    $serch_text = $_POST["search_text"]; 
    $con=mysqli_connect("localhost","db_name","db_username","db_password");
            // Check connection
            if (mysqli_connect_errno()) {
              die ("Failed to connect to MySQL: " . mysqli_connect_error());
            }       
        $booking_id_serch_text = $serch_text;
        $searchroute = "select * from van_sharing where date = '$booking_id_serch_text'";
        $result = $con->query($searchroute);
        $row = $result->fetch_assoc();
        if ($row == 0) { echo '<div style="color: red;">No one planned yet on the date <b>' . $serch_text . '</b>. to go</div>' ; 
        } else {
            // getting number of rows for a specific date
            $wpdb->get_results( $wpdb->prepare('select * from van_sharing where date = %s', $booking_id_serch_text));
            $total_seats = 10;
            $people_travel_on_the_date = $wpdb->num_rows;
            $available_seats = $total_seats - $people_travel_on_the_date;
            echo 'Total Seats ' . $total_seats . '<br/>';
            echo 'Number of people who are planning to share on the date '.$booking_id_serch_text .' : '.$wpdb->num_rows;

            echo '</br>Available seats : '.$available_seats;
            mysqli_close($con);
        }
    }
    ?>

现在,我正在向访问者展示我想要展示的所有细节。

  1. $ total_seats的总座位数
  2. 愿意分享日期的人数 $ people_travel_on_the_date
  3. 来自$ available_seats的余额/可用座位
  4. 但是我想在一个图形栏中显示这些内容,而不仅仅是在某些行中显示。 像:

    1. 如果没有任何人预订/不愿意在该日期分享。 这意味着$ people_travel_on_the_date == 0 Red
    2. 如果有两三个人预订/愿意分享 日期。这意味着$ people_travel_on_the_date == 2或3 Green + red
    3. 如果有5人预订/愿意分享日期。那 意味着$ people_travel_on_the_date == 5 Green + yellow
    4. 如果有10人预订/愿意分享日期。那 意味着$ people_travel_on_the_date == 10 enter image description here
    5. 我用谷歌搜索并引用了php.net但是所有的PHP drwaing即将创建图表,整个图表就像饼图或条形图,但不会在图形栏中显示这些结果。

      如何使用php创建一个条形码? 它是一个wordpress网站。因此,通过自定义PHP更好,但不使用库。 我也不愿意使用插件。

0 个答案:

没有答案