最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

sql - Why is my insert row only inserting the final row from the loop into the database rather than just inserting one

programmeradmin2浏览0评论
    <?php
session_start();

if(is_user_logged_in()) {
    global $wpdb;
    $id = get_current_user_id();
    $recoveryID = null;
//     $results = $wpdb->get_results('SELECT * FROM wp_recovery_details where not exists (select driverID ,recoveryID from wp_recovery_bids where driverID='$id')');
//     
$results = $wpdb->get_results('SELECT * FROM wp_recovery_details');
    
//     
//  EXISTS (select driverID ,bidAmount from wp_recovery_bids)

  // output data of each row
  foreach ($results as $row) {
    //  $recoveryID = $row->recoveryID;
      
//  $result = $wpdb->get_results('select * from wp_recovery_details where not exists(select driverID from wp_recovery_details where recoveryID ='$recoveryID' ');
      
//    if(count($result) > 0){
          
      

//    $numberPlate = str_replace(' ', '', $row -> custNoPlate);
//    
        $_SESSION['recoveryID'] = $row -> recoveryID;
      $image = $row -> imageURL;
      echo 
        "<table role='table'>
    <thead>
    <tr>
    <th>Vehicle</th>
    <th>Location</th>
    <th>Destination</th>
    <th>Estimated Time of Arrival</th>
    <th>Your price</th>
    </tr>
    </thead>
    <tr>
    <th> 
    <form method='post' action =''>
     <h1> ".$row -> recoveryID."  </h1>
    <img src='/{$image}'
      width='150' height='70'/>
        ". $row -> custNoPlate."
    
    <th>" .$row -> pickUp. "</th>
    <th>" .$row -> destination. "</th>
    <th><input type='time' name='eta'/></th>
    <th><input type='text' name='price'/></th>
    <th><input type='submit' name='submit'/></th>
    </form>
</table>"; 
             
//   }
   
      };
     
     if(isset($_POST['submit'])){
        
            $table_name = $wpdb->prefix.'recovery_bids';
                 
            $bidAmount = $_POST['price'];
            $estimatedTime = $_POST['eta'];
         
                 
                $bidID = rand(10,10000);
                
                $driverID = get_current_user_id();
         
                $recoveryID = $_SESSION['recoveryID'];
                 
                 $wpdb->insert($table_name, array(
                    'bidID' => $bidID,
                    'bidAmount' => $bidAmount,
                    'estimatedTime'=> $estimatedTime,
                    'driverID' => $driverID,
                    'recoveryID' => $recoveryID ,
                     ),
                        array(
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                ));
        }   
} else{
    echo "Login to view this page";
}
        
?>

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论