我的错误:Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in .../gallery.php on line 81
我敢肯定,这是我的代码。如果获得批准,它应该从每一行中获取图像等,并相应地显示它。
似乎不想玩得很好:(
有没有人遇到过这个问题?
<?php
$page = 'gallery';
include 'header.php';
$can_vote = TRUE; //expand
$query = "SELECT COUNT(`id`) as 'count' FROM `$db_name`.`gallerytable` WHERE `approve` = 1 LIMIT 1;";
$result = mysql_query($query);
$result = mysql_fetch_array($result);
$total_entry = $result['count'];
$current_page = (int) $_GET['page'];
$current_page = ($current_page == 0) ? 1 : $current_page;
?>
<header id="main-head" class="clearfix">
<div style="height:103px;overflow:hidden;"> </div>
<nav id="main-nav">
</nav><!-- #main-nav -->
</header><!-- #main-head -->
<div id="main-content" class="clearfix">
<?php if($total_entry > 20): ?>
<?php
$start_range = range(1, $total_entry, 20);
$end_range = ($total_entry < 40) ? array(20, $total_entry) : range(20, $total_entry, 20);
?>
<div id="paging-wrap" class="clearfix">
<ul id="paging-nav">
<?php
$output = '';
//prev link
$prev_page = $current_page - 20;
if($prev_page >= 1)
$output .= '<li><a href="?p=gallery&page='.$prev_page.'"><</a></li>';
//show page links
foreach($start_range as $key => $number) {
$output .= '<li><a href="?p=gallery&page='.$number.'">'.$number.'-'.$end_range[$key]."</a></li>\n";
$last_start_number = $number;
}
//hack last link
$output = str_replace('-</a></li>', '-'.$total_entry.'</a></li>', $output);
if($last_start_number == $total_entry) {
$output = str_replace('<li><a href="?p=gallery&page='.$last_start_number.'">'.$last_start_number.'-'.$last_start_number.'</a></li>','<li><a href="?p=gallery&page='.$last_start_number.'">'.$last_start_number.'</a></li>', $output );
}
//set active page
$output = str_replace('<a href="?p=gallery&page='.$current_page.'">', '<a href="?p=gallery&page='.$current_page.'" class="active">', $output);
$next_page = $current_page + 20;
if($next_page <= $last_start_number)
$output .= '<li><a href="?p=gallery&page='.$next_page.'">></a></li>';
echo $output;
?>
</ul><!-- #paging-nav -->
<span id="paging-title">Display</span>
</div><!-- #paging-wrap -->
<?php else: ?>
<div id="blank-paging"></div>
<?php endif; //total entry > 20 ?>
<div id="gallery-wrap">
<?php
if($total_entry > 0) :
//show entry
$ip_address = $_SERVER['REMOTE_ADDR'];
$limit_start = $current_page - 1;
$number = $current_page;
$url = ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' ) ? 'https://' : 'http://';
$url .= $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
?>
<?php while($row = mysql_fetch_object($result)): ?>
<div class="photo-wrap can-vote">
<img height="113px" style="height:113px;overflow:hidden;line-height:0;" src="<?php echo $url ?>/inc/timthumb.php?src=<?php echo $url ?>/photos/<?php echo $row->photo ?>&w=136&h=113&q=100&a=t" alt="photo-contest" />
</div>
<?php $number++; endwhile; ?>
<?php else: ?>
<h2>no-one here</h2>
<?php endif ?>
</div><!-- #gallery-wrap -->
</div><!-- #main-content -->
<footer id="footer-main">
</footer><!-- #footer-main -->
<?php
$form_key = $formKey->generateKey();
$_SESSION['form_key'] = $form_key;
?>
<script> var key_val = '<?php echo $form_key ?>';</script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/jquery-ui.min.js"></script>
<?php include 'footer.php'; ?>