I need help on this PHP code

Discussion in 'PHP' started by alllyc, Oct 30, 2009.

  1. #1
    Hi everybody, I made some kind of mistake while editing the code below. As you see, at the 3 row my news are repetition of raw 2.
    http://www.demirtepe.net/haber/index17.php

    As a matter of fact, I had only 2 rows, but I needed to have more than 2 rows and tried to edit the code by myself. I finally managed to have 3 rows but it turned out as the repetition of raw 2. The original appearance of it was like this:
    http://demirtepe.net/haber/index34.php

    Below is the code:
    <?php 
    include("ayar.php");
      $sqllist="select * from demirtepe where durum=0 order by id desc ";
    	 mysql_query("SET NAMES 'utf8'");
    	 $execute=mysql_query($sqllist);
    	$list =@ mysql_fetch_array($execute); 
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    <!--
    body {
    	margin-left: 0px;
    	margin-top: 0px;
    	margin-right: 0px;
    	margin-bottom: 0px;
    }
    a:link {
    	text-decoration: none;
    	color: #E05400;
    }
    a:visited {
    	text-decoration: none;
    	color: #E05400;
    }
    a:hover {
    	text-decoration: none;
    	color: #E05400;
    }
    a:active {
    	text-decoration: none;
    	color: #E05400;
    }
    img{border:none;}
    -->
    </style></head>
    
    <body>
       
    <table width="706" border="0" align="center">
      <tr align="left" valign="top">
        <td width="368" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;">
        <h3 style="color:#E05400;"><strong><?php echo"$list[baslik]";?></strong></h3>
        
        <?php
    
    $metin = $list['ozet'];
    
    $uzunluk = strlen($metin);
    
    $sinir = 685;
    if ($uzunluk> $sinir) {
    $icerik = substr($metin,0,$sinir) . "&nbsp; <a href='haberdetay.php?id=$list[id]'><u>haberin devamı</u> >></a>";
    echo $icerik;
    }
    
    else
    {
    echo "$list[ozet]<br />&nbsp; <a href='haberdetay.php?id=$list[id]'><u>haberin devamı</u> >></a>";
    }
    ?>
    <br />
    
      
        &nbsp;</td>
        <td width="328" align="right" valign="middle"><img src="<?php echo"$list[resim]";?>" width="315" height="238" /></td>
      </tr>
    </table>
    
    <table width="704" border="0" align="center">
      <tr>
      
         
      <p> </p>  
      <?php
    
      				
         $sqllist="select * from demirtepe where id < $list[id] and durum=0 order by id desc limit 2 ";
    	 $execute=mysql_query($sqllist);
    	 mysql_query("SET NAMES 'utf8'");
    	 while ($list2 =@ mysql_fetch_array($execute))
    	 {
    	 
    
    $metin = $list2['ozet'];
    
    $uzunluk = strlen($metin);
    
    $sinir = 80;
    if ($uzunluk> $sinir) {
    $icerik = substr($metin,0,$sinir) . "";
    }
     
    
    	 
     echo "	<td width='154' height='115' valign='top'>
    	<a href='haberdetay.php?id=$list2[id]'> <img src='$list2[resim]' width='154' height='113' align='top' />  </a> </td>
    	 
    	 <td width='214' valign='top'><span style='color:#E05400; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'><b><a href='haberdetay.php?id=$list2[id]'>$list2[baslik]</a> </b></span><br /><a href='haberdetay.php?id=$list2[id]'><span style='color:#000000; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'>$icerik</span></a>  <span style='text-align:right; color:#E05400;'> <a href='haberdetay.php?id=$list2[id]'>>></a> </span></td>
    	<td></td>
    	 ";
    	 } 
    
    	 ?>
     
      </tr>
      
      
       
    
    <tr>
      
         
      <p> </p>  
      <?php
    
      				
         $sqllist="select * from demirtepe where id < $list[id] and durum=0 order by id desc limit 2 ";
    	 $execute=mysql_query($sqllist);
    	 mysql_query("SET NAMES 'utf8'");
    	 while ($list3 =@ mysql_fetch_array($execute))
    	 {
    	 
    
    $metin = $list3['ozet'];
    
    $uzunluk = strlen($metin);
    
    $sinir = 80;
    if ($uzunluk> $sinir) {
    $icerik = substr($metin,0,$sinir) . "";
    }
     
    
    	 
     echo "	<td width='154' height='115' valign='top'>
    	<a href='haberdetay.php?id=$list3[id]'> <img src='$list3[resim]' width='154' height='113' align='top' />  </a> </td>
    	 
    	 <td width='214' valign='top'><span style='color:#E05400; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'><b><a href='haberdetay.php?id=$list3[id]'>$list3[baslik]</a> </b></span><br /><a href='haberdetay.php?id=$list3[id]'><span style='color:#000000; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'>$icerik</span></a>  <span style='text-align:right; color:#E05400;'> <a href='haberdetay.php?id=$list3[id]'>>></a> </span></td>
    	<td></td>
    	 ";
    	 } 
    
    	 ?>
     
      </tr>
    
    
    
    
    
    
    
    
    
    
    
    
    </table>
    <table width="712" border="0" align="center">
      <tr>
        <td width="702" align="right"><a href="tumhaberler.php"><u>tüm haberleri görmek için tıklayın...</u></a></td>
      </tr>
    </table>
    
    
    </body>
    </html>
    Code (markup):
    Thanks a lot for your help, I highly appreciate your helping on this.
     
    alllyc, Oct 30, 2009 IP
  2. emed

    emed Peon

    Messages:
    70
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    the second time you use this:
    $sqllist="select * from demirtepe where id < $list[id] and durum=0 order by id desc limit 2 ";

    change it to:
    $sqllist="select * from demirtepe where id < $list[id] and durum=0 order by id desc limit 2,2 ";

    this way it will take 2 items, but skipping the first 2
     
    emed, Oct 31, 2009 IP
  3. alllyc

    alllyc Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks a lot for this code. It worked.
     
    alllyc, Nov 1, 2009 IP