News system

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
stipe
Forum Newbie
Posts: 11
Joined: Sun Sep 25, 2005 6:09 pm

News system

Post by stipe »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


I got a news system, and i want to display first news with picture and short text , and below first news i want only title from other news,
is there some function that can do that. Here's the code, please help

Code: Select all

<?php

include("./admin/connect.php");

$sql= "SELECT * FROM vijesti ORDER BY id desc  LIMIT 5";



$result= mysql_query($sql,$connect);

while ($newArray = mysql_fetch_array($result)) {

$id = $newArray['id'];
$dan = $newArray['dan'];
$mjesec = $newArray['mjesec'];
$godina = $newArray['godina'];
$sat = $newArray['sat'];
$minute=$newArray['minute'];
$danob = $newArray['danob'] ;
$naslov = $newArray['naslov'];
$vijest = $newArray['vijest'];
$dslika=$newArray['dslika'];
$slikad=$newArray['slikad'];
$slika=$newArray['slika'];
$slikav=$newArray['slikav'];
?>

<table width="300" border="0" align="center" cellpadding="0" cellspacing="5">
  <tr>
    <th align="left">  <?php echo "$naslov"?></th>
    
  </tr>
  <tr>
    <td colspan="2" align="center" valign="top"><div align="left">
<table width="85" border="0" align="left" cellpadding="0">
  <tr>
    <td align="left" valign="top" > 
	
	
       <?php 
	     If( $slika AND $slikav){ 
		   
	   ?>
	  <?php  echo "<a href=\"./opsirnije.php?id=$newArray[id]\">  <img src=\"./images/vijesti/male/$slika\" border='1'  width='80' height='60' ></a>";?>
     
 
	  <?php }
		 If(  $slika AND ! $slikav){ 
	  ?>
	  
      <?php echo" <a href=\"./opsirnije.php?id=$newArray[id]\"><img src=\"./images/vijesti/male/$slika\" border='1' width='80' height='60'></a>";?>
      
	  <?php }								   

	     If( ! $slika AND  $slikad){ 
	 ?>
      <?php echo"<a href=\"./opsirnije.php?id=$newArray[id]\"><img src=\"./images/vijesti/default/$slikad\" border='1' width='80' height='60' ></a>";?>
     
	  <?php }

	     If($dslika AND ! $slikad AND ! $slika){ 
	 ?>
	 <?php echo"<a href=\"./opsirnije.php?id=$newArray[id]\"><img src=\"./images/vijesti/gifs/$dslika\" border='1' width='80' height='60' ></a>";?>
   
	 <?php }	?>
	</td>
  </tr>
</table>

     <?php echo ("$vijest");?> <?php  echo "<a href=\"./opsirnije.php?id=$newArray[id]\"><img src=\"/gifs/opsirnije_54.gif\" border='0' ></a>";?>
  
	</td>
  </tr>
  <tr>
    <td>
	</td>
  </tr>
  <td>
 </td>
 
 


 <?php 
  $sql = "UPDATE vijesti SET brojac=brojac+1".
"where id=$id";
If (mysql_query(sql)) {}
?>
  <?php







$dan2 = date("d");

$mjesec2 = date("m");

$godina2 = date("Y");

$sat2 = date("H");

$minute2 = date("i");



	$result = mysql_query(



	 "SELECT id, naslov, danob, mjesecob, godob, satob, minob, obodma from vijesti ORDER BY id DESC LIMIT 10");



	If ($result) {



		while ( $row = mysql_fetch_array($result) ) {



		$naslov = ($row["naslov"]) ;

		$id = ($row["id"]) ;

		$danob = ($row["danob"]) ;

		$mjesecob = ($row["mjesecob"]) ;

		$godob = ($row["godob"]) ;		

		$satob = ($row["satob"]) ;

		$minob = ($row["minob"]) ;

		$obodma = ($row["obodma"]) ;



		$brojob = $godob . $mjesecob . $danob . $satob . $minob;

		$brojsad = $godina2 . $mjesec2 . $dan2 . $sat2 . $minute2;





If($brojob <= $brojsad OR $obodma == '1'){ ?>
              <tr> 
                <td  class="txtnaslov2"><?php echo"<a href='opsirnije.php?id=$row[id]'>";?> 
                  <?php echo($naslov); ?>
                  </a></td>
              </tr>
              <?php }}}?>
              <tr> 
                <td></td>
              </tr>
              <tr> 
                <td class="header" height="25" valign="bottom"></td>
              </tr>
            </table>
          </td>
        </tr>
      </table>

  <?php } ?>	






<?php


@mysql_close($connect);
?>

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

when wanting to display differing things for the first and other records returned, it may be better to process the first outside the loop since you don't want to loop over that code for the rest of the records.. i.e. fetch the first record, do your first record code. Start the loop and do the rest of the records.
Post Reply