diff --git a/src/history.php b/src/history.php index 309d1b49bde2dec316d06b42407581ede44e99f8..632972cfbc01fe264552fa75f867307ac17edcf3 100644 --- a/src/history.php +++ b/src/history.php @@ -24,10 +24,32 @@ } //AMBIL DATA HISTORY ORDER - $query_order_history = 'SELECT * FROM orderhistory INNER JOIN userinfo ON orderhistory.u_customer=userinfo.username '; - $result_history=mysqli_query($sqlconn,$query_order_history); + $query_order_history = 'SELECT order_id, date, u_driver, source, destination, rating_given, comment_given, img_name FROM orderhistory INNER JOIN userinfo ON orderhistory.u_customer=userinfo.username AND userinfo.username=?'; + $order_history = mysqli_prepare($sqlconn, $query_order_history); + // Bind variables + mysqli_stmt_bind_param($order_history, "s", $username); + if(mysqli_stmt_execute($order_history)){ + // Simpan Hasil query + mysqli_stmt_store_result($order_history); + // username exist + mysqli_stmt_bind_result($order_history, $id, $date, $u_driver, $source, $destination, $rating_given, $comment_given, $img_name); + } + + //AMBIL DATA DRIVER HISTORY + $query_driver_history = 'SELECT order_id, date, u_driver, source, destination, rating_given, comment_given FROM orderhistory INNER JOIN userinfo ON orderhistory.u_driver=userinfo.username AND userinfo.username=?'; + $driver_history = mysqli_prepare($sqlconn, $query_driver_history); + + // Bind variables + mysqli_stmt_bind_param($driver_history, "s", $username); + + if(mysqli_stmt_execute($driver_history)){ + // Simpan Hasil query + mysqli_stmt_store_result($driver_history); + // username exist + mysqli_stmt_bind_result($driver_history, $id, $date, $u_customer, $source, $destination, $rating_given, $comment_given); + } ?> <html> <head> @@ -57,7 +79,7 @@ <nav class="mt10"> <ul> <li><a href="">Order</a></li> - <li><a href="">History</a></li> + <li><a href="#" class="active">History</a></li> <li><a href="">My Profile</a></li> </ul> </nav> @@ -76,8 +98,8 @@ <!-- Start Previous Order Content Tab --> <div id="order" class="tabcontent active"> <?php - while ($row = mysqli_fetch_array($result_history,MYSQLI_ASSOC)) { - switch ($row["rating_given"]) { + while (mysqli_stmt_fetch($order_history)) { + switch ($rating_given) { case 1: $rating='☆'; break; @@ -96,22 +118,23 @@ default: $rating=''; } - $date=strtotime($row["date"]); + $date=strtotime($date); + $id_hide="'order$id'"; $listhistory = ' <!-- Start List Item --> - <div class="row mt40"> + <div class="row mt40" id="order'.$id.'"> <div class="col-4 photo-container px15"> - <img src="img/'.$row["img_name"].'" class="border"> + <img src="img/'.$img_name.'" class="border"> </div> <div class="col-8 relative"> <div class="date">'.date("l, F j",$date).'th '.date("Y",$date).'</div> - <div class="driver-name">'.$row["u_driver"].'</div> - <div class="destination mt10">'.$row["source"].' → '.$row["destination"].'</div> + <div class="driver-name">'.$u_driver.'</div> + <div class="destination mt10">'.$source.' → '.$destination.'</div> <div class="rating mt10">You rated: <span class="orange">'.$rating.'</span></div> <div class="comment">You commented: - <p class="m0">'.$row["comment_given"].'</p></div> + <p class="m0">'.$comment_given.'</p></div> <div class="hide-btn r0 t0"> - <button class="uppercase btn red-bg">Hide</button> + <button class="uppercase btn red-bg" onclick="hide('.$id_hide.')">Hide</button> </div> </div> </div> @@ -120,47 +143,38 @@ echo $listhistory; } ?> - <!-- Start List Item --> - <!-- <div class="row mt40"> - <div class="col-4 photo-container px15"> - <img src="img/foto-profil.jpg" class="border"> - </div> - <div class="col-8 relative"> - <div class="date">Sunday, September 24th 2017</div> - <div class="driver-name">Bomba-rattata Ttatatatta</div> - <div class="destination mt10">Saffron City → Pewter City</div> - <div class="rating mt10">You rated: <span class="orange">☆</span></div> - <div class="comment">You commented: - <p class="m0">Ah. Driver payah! Ditungguin 5 jam ngga dateng- dateng. Pas dateng mesem-mesem doang ngga minta maaf. Payah sekali!!</p></div> - <div class="hide-btn r0 t0"> - <button class="uppercase btn red-bg">Hide</button> - </div> - </div> - </div> --> - <!-- End List Item --> </div> <!-- End Previous Order Content Tab --> <!-- Start Driver History Content Tab --> <div id="driver" class="tabcontent"> - <!-- Start List Item --> - <div class="row mt40"> - <div class="col-4 photo-container px15"> - <img src="img/foto-profil.jpg" class="border"> - </div> - <div class="col-8 relative"> - <div class="date">Sunday, September 24th 2017</div> - <div class="driver-name">Bomba-rattata Ttatatatta</div> - <div class="destination mt5">Saffron City → Pewter City</div> - <div class="rating mt5">gave <span class="orange">5</span> stars for this order</div> - <div class="comment mt5">and left comment: - <p class="m0">Ah. Driver payah! Ditungguin 5 jam ngga dateng- dateng. Pas dateng mesem-mesem doang ngga minta maaf. Payah sekali!!</p></div> - <div class="hide-btn r0 t0"> - <button class="uppercase btn red-bg">Hide</button> + <?php + while (mysqli_stmt_fetch($driver_history)) { + $date=strtotime($date); + $id_hide="'driver$id'"; + $listhistory = ' + <!-- Start List Item --> + <div class="row mt40" id="driver'.$id.'"> + <div class="col-4 photo-container px15"> + <img src="img/'.$img_name.'" class="border"> + </div> + <div class="col-8 relative"> + <div class="date">'.date("l, F j",$date).'th '.date("Y",$date).'</div> + <div class="driver-name">'.$u_customer.'</div> + <div class="destination mt5">'.$source.' → '.$destination.'</div> + <div class="rating mt5">gave <span class="orange">'.$rating_given.'</span> stars for this order</div> + <div class="comment mt5">and left comment: + <p class="m0">'.$comment_given.'</p></div> + <div class="hide-btn r0 t0"> + <button class="uppercase btn red-bg" onclick="hide('.$id_hide.')">Hide</button> + </div> + </div> </div> - </div> - </div> - <!-- End List Item --> + <!-- End List Item -->'; + + echo $listhistory; + } + ?> </div> <!-- End Driver History Content Tab --> <!-- End Tab History --> diff --git a/src/js/fan.js b/src/js/fan.js index bd032193de2f352a806813e06a59ae0616a4107d..277cae2b0167ea1d64d75ee64558936c40ef7fc5 100644 --- a/src/js/fan.js +++ b/src/js/fan.js @@ -20,4 +20,8 @@ function openTab(evt, tabName) { // Show the current tab, and add an "active" class to the button that opened the tab document.getElementById(tabName).style.display = "block"; evt.currentTarget.className += " active"; +} + +function hide(id) { + document.getElementById(id).style.display = "none"; } \ No newline at end of file