i need some help from you. i would probably solve it on my own..sometime. but, i am frustrated a little bit atm. and maybe you can save me some time and tears..
![Rolling Eyes :roll:](./images/smilies/icon_rolleyes.gif)
![Wink ;)](./images/smilies/icon_e_wink.gif)
so i managed to combine these two tutorials, where both using the same db-table and they are even showing up on the same page/s. but i cant get them both interact between each other correctly.
user_list.php:
[syntax=php]<?php
include('core/init.inc.php');
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
?>
<?php
$posts = get_posts();
foreach(fetch_titles($page, 5) as $post){
}
?>
<?php
foreach($posts as $post){
?>
<div id="titel">
<a class="titeltxt" href="blog_read.php?pid=<?php echo $post['id']; ?>"><?php echo $post['title']; ?></a>
</div>
<h6>By <?php echo $post['user']; ?> on <?php echo $post['date']; ?></h6>
<div id="news">
<br />
<!-- Video Player HERE -->
<?php
if(empty($post['video'])){
}
else{
if(isset($post['videoplayer'])){
$videoplayer = $post['videoplayer'];
if($videoplayer == '1'){
include('vid_player.php');
}
else{
include('vid_player2.php');
}
}
else{
}
}
?>
<!-- Video Player END -->
</div>
<p><h4><?php echo $post['preview']; ?></p>
<h5>(<a href="blog_read.php?pid=<?php echo $post['id']; ?>"><?php echo $post['total_comments']; ?> comments, last comment <?php echo $post['last_comment']; ?></a>)</h5>
<?php
}
?>
<?php
$total_pages = ceil(fetch_total_titles() / 5);
for ($i = 1; $i <= $total_pages; ++$i){
echo " <a href=\"?page={$i}\">{$i}</a> ";
}
?>
<br />
<!-- Prev/Next -->
<?php
if($page >= 2){
echo '<a href="?page=', ($page + -1), '">Previous </a>';
}
?>
<?php
if($page <= 1 AND $page != $total_pages){
echo '<a href="?page=', ($page + 1), '"> Next</a>';
}
?>
[/syntax]
the code is just pasted from "blog_list.php" -thats where my problem is..
init.inc.php:
[syntax=php]<?php
mysql_connect('127.0.0.1', 'example_user', 'test');
mysql_select_db('blog')
or die("Fehler im System");
include("pagination/inc/users.inc.php");
include('inc/posts.inc.php');
include('inc/comments.inc.php');
?>[/syntax]
posts.inc.php:
[syntax=php]<?php
//pagination
// fetches a list of posts from the database.
function fetch_titles($page, $per_page){
$start = (int)($page - 1) * $per_page;
$per_page = (int)$per_page;
$query = mysql_query("SELECT `post_title` FROM `posts` LIMIT {$start}, {$per_page}");
while (($row = mysql_fetch_assoc($query)) !== false){
$posts[] = $row['post_title'];
}
return $posts;
}
function fetch_total_titles(){
$result = mysql_query("SELECT COUNT(`post_id`) FROM `posts`");
return mysql_result($result, 0);
}
//checks if the given post id is in the table.
function valid_pid($pid){
$pid = (int)$pid;[/syntax]