i'm still new to PDO stuff
i'm writing a pdo pagination but my problem is, its not outputting the data
it just output blank white page
PHP CODE
include "config.php";
if(isset($_POST['checkin'])){
$country = $_POST['country'];
$city = $_POST['city'];
$checkin = $_POST['checkin'];
$checkout = $_POST['checkout'];
$sql = $dbo->prepare("SELECT COUNT(id) FROM hotels");
if(!$sql->execute()){
echo "No Count";
}else {
$fetchrows = $sql->fetch();
$rows = $fetchrows[0];
$page_rows = 5;
$last = ceil($rows/$page_rows);
if($last < 1){
$last = 1;
}
$page_num = 1;
if(isset($_GET['pn'])){
$page_num = preg_replace('#[^0-9]#', '', $_GET['pn']);
}
$limit = ($page_num - 1) * $page_rows;
$sql = $dbo->prepare("SELECT * FROM hotels DESC WHERE h_country='$country' LIMIT $limit");
echo "<h3>Total hotels found: $rows</h3>";
echo "Page <b>$page_num</b> of <b>$last</b>";
$hotels = $sql->fetchAll(PDO::FETCH_OBJ);
foreach($hotels as $hotel){
echo $hotel->h_title;
}
}
}
i normally do while statement for pagination in a normal query, so i tried doing the same thing but in PDO, but it didn't work.
i dunno what's the problem.
It would be great if you can point out my mistake.
Thanks
Here's my PDO Connection & Mysql, i copied the PDO connection code from a website.
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "test";
$dbserver = mysql_connect($dbhost,$dbuser,$dbpass);
if(!$dbserver) die ("Failed to Connect:" . mysql_error());
mysql_select_db($dbname) or die ("Unable to select the database");
try {
$dbo = new PDO('mysql:host=localhost;dbname='.$dbname, $dbuser, $dbpass);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
I'm not sure how the errors work