Jump to content

Use an image while querying news items.


Peosan

Recommended Posts

Okay, so, I hope this is the right forum to ask this.

 

Basically, I need a function to do this; whenever I add a new NewsPost on my website,

I want a image to it, like a background that also stretches with the text.

As for now I'm using tables, that's just ugly. Any ideas?

 

Here's the code for the index.php;

 

<?
ini_set("display_errors", "on"); 
error_reporting(E_ALL);
echo("<div align='center'>"); 
include ("include/config.php");
include("include/queries.php");
?>
<title><?php echo $web_name ?></title>
<?php
//include("include/header.php");

$t = mysql_query("SELECT * FROM `news` ORDER by `id` DESC"); 
  if(!$t) die(mysql_error()); 
    
$a                  = mysql_fetch_object($t); 
$total_items      = mysql_num_rows($t); 
$limit = (!isset($_GET['limit']))? $num_news_page : $_GET['limit']; 
$page = (!isset($_GET['page']))? 1 : $_GET['page']; 


//set default if: $limit is empty, non numerical, less than 10, greater than 50 
if((!$limit)  || (is_numeric($limit) == false) || ($limit < 2) || ($limit > 50)) { 
     $limit = $num_news_page; //default 
} 
//set default if: $page is empty, non numerical, less than zero, greater than total available 
if((!$page) || (is_numeric($page) == false) || ($page < 0) || ($page > $total_items)) { 
      $page = 1; //default 
} 

//calcuate total pages 
$total_pages     = ceil($total_items / $limit); 
$set_limit          = $page * $limit - ($limit); 

//query: **EDIT TO YOUR TABLE NAME, ECT. 

$q = mysql_query("SELECT * FROM `news` ORDER by id DESC LIMIT $set_limit, $limit"); 
  if(!$q) die(mysql_error()); 
     $err = mysql_num_rows($q); 
       if($err == 0) die("No matches met your criteria."); 

//Results per page: **EDIT LINK PATH** 
echo("   
<a href=?limit=10&page=1>10</a> | 
<a href=?limit=25&page=1>25</a> | 
<a href=?limit=50&page=1>50</a>"); 

//show data matching query: 
//while($code = mysql_fetch_object($q)) { 
while($code = mysql_fetch_assoc($q)) {

//Comments count
$count_comments = mysql_query("SELECT * FROM `comments` WHERE `id_news`={$code['id']}"); 
$num_rows = mysql_num_rows($count_comments); 

//news table
echo("<div align='center'>");
echo("<table border='1' width='440'>");
echo("<tr>");
	echo("<td width='500' colspan='2'><b>{$code['name']}</b></td>");
	echo("<td width='140'>{$code['datestamp']}</td>");
echo("</tr>");
echo("<tr><td width='640' colspan='3'>{$code['news_txt']}</td></tr><tr>");
	echo("<td width='250'><a href='full_txt.php?id={$code['id']}'>Read More</a></td>");
	echo("<td width='250'>$num_rows Comments</td>");
	echo("<td width='140'>{$code['reads']} reads</td>");
echo("</tr>");
echo("</table></div><p>");
} 

//$cat = urlencode($cat); //makes browser friendly 


$prev_page = $page - 1; 

if($prev_page >= 1) { 
  echo("<b><<</b> <a href=?limit=$limit&page=$prev_page><b>Prev.</b></a>"); 
}  

for($a = 1; $a <= $total_pages; $a++) 
{ 
   if($a == $page) { 
      echo("<b> $a</b> | "); //no link 
     } else { 
  echo("  <a href=?limit=$limit&page=$a> $a </a> | "); 
     } 
} 

$next_page = $page + 1; 
if($next_page <= $total_pages) { 
   echo("<a href=?limit=$limit&page=$next_page><b>Next</b></a> > >"); 
} 
include("include/footer.php");
//all done 
?> 

Link to comment
https://forums.phpfreaks.com/topic/170048-use-an-image-while-querying-news-items/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.