PDO with update

PDO with update

luma64luma64 Posts: 4Questions: 1Answers: 0

Hi all ! I m working with datatables FixedHeader. In pdo statement is used Order by. Sample:

$date_reserv_tmp = '2020-04-23';
$room = "Room01";

$stmt = $pdo->prepare("Select Id, name, room, date_reserv, country FROM table where room =:room and left(date_reserv,10) = :$date_reserv_tmp Order by :country");
$stmt->bindValue(':room', $room);
$stmt->bindValue(':date_reserv', $date_reserv_tmp);
$stmt->bindValue(':country', $country);
$stmt->execute();

After execute rows are not order as I want but they are order by Id.
What is wrong ? Thank you !

Replies

  • rf1234rf1234 Posts: 2,947Questions: 87Answers: 416
    $date_reserv_tmp = '2020-04-23';
    $room = "Room01";
    
    $stmt = $pdo->prepare("
     Select Id, name, room, date_reserv, country 
       FROM table 
       where room =                  :room 
         and left(date_reserv, 10) = :date_reserv  
    Order by country");
    $stmt->bindValue(':room', $room);
    $stmt->bindValue(':date_reserv', $date_reserv_tmp);
    $stmt->execute();
    
  • luma64luma64 Posts: 4Questions: 1Answers: 0

    Your advice is the same problem..When I dont use funcionality with datatables order by is good. But when I use funcionality with datatables then order by is wrong; selected records are order by Id again.

  • rf1234rf1234 Posts: 2,947Questions: 87Answers: 416

    You must order your records on the client using data tables. The order by in your SQL is redundant.

This discussion has been closed.