Jump to content

MySQLi Query


stardar

Recommended Posts

Hello,

Got a code, need to insert a query for displaying links of posts in section. Category is 'blog', each post has it's 'id', and 'subject', which should be a name for link, such as "blog.php?p='id'". 

Looking for help. Thank you in advance!

Stardar

 

<!doctype html>
<html lang="en">
<head>
</head>

<body class="base">

<div class="container">

<!-- PRZETWARZANIE WYNIKÓW Z BAZY -->

	<?php
	$total_pages = $link->query('SELECT * FROM news WHERE category="blog"')->num_rows;
	$page = isset($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1;
	$num_results_on_page = 1;

	if ($stmt = $link->prepare('SELECT * FROM news WHERE category="blog" ORDER BY date DESC LIMIT ?,?')) {
	$calc_page = ($page - 1) * $num_results_on_page;
	$stmt->bind_param('ii', $calc_page, $num_results_on_page);
	$stmt->execute(); 
	$result = $stmt->get_result();
	}

	while ($row = $result->fetch_assoc()):
	$text = $row['news'];
	$text = str_replace('[video]','<div class="video-container">',$text);
	$text = str_replace('[/video]','</div>',$text);
	$text = str_replace('[media]','',$text);
	$text = str_replace('[/media]','',$text);
	$embera = new \Embera\Embera();
	echo '<div class="container">
    <div class="row">';
	?>
	<div class="col-sm-4">



/* here is a place for links to published posts */




</div>
	
	<?php
	echo '<div class="col-sm-8"><h3>'.$row['subject'].'</h3>';
	echo '<div class="tresc embed-responsive">';
	echo $embera->autoEmbed($text);
	echo '</div></div>
    </div>
</div>';
	endwhile;
	?>
	
	
<!-- KONIEC PRZETWARZANIA WYNIKÓW Z BAZY -->

<hr class="pagination_divider">
<center>
<!-- PAGINATION -->

	<?php
	if (ceil($total_pages / $num_results_on_page) > 0):
	?>
	<div class="sect_paginate"><ul class="pagination">
	<?php
	if ($page > 1):
	?>
	<li class="prev"><a href="blog.php?page=<?php echo $page-1 ?>">&#9666; WSTECZ</a></li>
	<?php
	endif;
	?>
	<li class="currentpage"><a href="blog.php?page=<?php echo $page ?>"><?php echo $page ?></a></li>
	<?php
	if ($page < ceil($total_pages / $num_results_on_page)):
	?>
	<li class="next"><a href="blog.php?page=<?php echo $page+1 ?>">DALEJ &#9656;</a></li>
	<?php
	endif;
	?>
	</ul></div>
	<?php
	endif;
	$stmt->close();
	?>
</center>
<!-- END OF PAGINATION -->	
	
</div>
</body>
</html>

 

Link to comment
Share on other sites

WIt a part for this section my dear Requinix:

/* here is a place for links to published posts */

The problem is, that I have pagination section, and I'm lost in it. I know ofcourse how to querydb, but dunno, how to build the result for displaying as a link, when href is something like "blog.php?p=id (when id is an id of post placed in base". I am so sorry, maybe my explanation is in the same way as my code :)

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.