I have a table where all we have all of the packages. I want to select all of packages id. on page refresh I want to show a different package. I tried to do this with rand()
but it doesn't if we don't have 1 id in package table. any suggestions?
function get_packages_id() {
$pkg_count = count_all('ph_packages');
$pkg_id = rand(1, $pkg_count);
return $pkg_id;
}
$package = find_by_id($pkg_id, 'id', 'ph_packages');
<div class="card m-b-30">
<div class="card-body text-center">
<h4 class="mt-0 mb-3 header-title"><?php echo h($package['title']); ?> Only $<?php echo h($package['price']); ?></h4>
<p><?php echo h($package['description']); ?></p>
<?php if ($package['payment_method'] === 'default') { ?>
<a href="pricing.php" class="btn btn-primary waves-effect waves-light"><?php echo h($package['button_text']); ?></a>
<?php } else { ?>
<a href="<?php echo $package['payment_method']; ?>" class="btn btn-primary waves-effect waves-light"><?php echo h($package['button_text']); ?></a>
<?php } ?>
</div>
</div>