PHP Posting System (Blog)

Asked

Viewed 3,923 times

1

I’m developing the following website I have knowledge in web designers but nothing in php, and need to create a posting system for the site, I’m doing tests here on my server and I’m having progress except for a problem follows the code on php:

<article>
  <?php 
    $limitePag = 5;
    if(isset($_GET['pg'])){
        $pg = $_GET['pg'];
        $inicio = ($pg * $limitePag)-$limitePag;
        $sql = mysql_query("select * from postagem order by datapost asc LIMIT $inicio,$limitePag");
        while($linha = mysql_fetch_array($sql)){
        $id = $linha['id'];
            $Titulo = $linha['titulopost'];
            $bloco1 = $linha['bloco1'];
            $bloco2 = $linha['bloco2'];
            $datapost = $linha['datapost'];
    ?>
        <div class="article_date luck grid_2 alpha omega"><span class="month"><?php echo date('M',strtotime($datapost)) ?><br/><?php echo date('d',strtotime($datapost)) ?></br/></span><span class="year"><?php echo date('Y',strtotime($datapost)) ?></span></div>
        <div class="grid_9 alpha">
        <h1 class="luck"><?php echo $Titulo ?></h1>
        <p><?php echo $bloco1 ?></p>
    <?php
        $sql = mysql_query("select * from anexo where fk = $id");
        while($linha = mysql_fetch_array($sql)){
        $anexo = $linha['foto'];
        $descricao = $linha['descricao'];
        $link = $linha['link'];
    ?>
        <img src="./foto/<?php echo $anexo ?>" alt="" width="529" height="240"/>
        <span class="caption osans-i"><?php echo $descricao ?> - <a href=<?php echo $link ?>><?php echo $link ?></a></span>
    <?php 
        }
    ?>
     <p><?php echo $bloco2 ?></p>
    <div class="small_sep"></div>
    </div>
    <?php           
    }}else{
        $pg = 1;
        $inicio = ($pg * $limitePag)-$limitePag;
        $sql = mysql_query("select * from postagem order by datapost asc LIMIT $inicio,$limitePag");
        while($linha = mysql_fetch_array($sql)){
            $id = $linha['id'];
            $Titulo = $linha['titulopost'];
            $bloco1 = $linha['bloco1'];
            $bloco2 = $linha['bloco2'];
            $datapost = $linha['datapost'];
    ?>    
    <article>
        <div class="article_date luck grid_2 alpha omega"><span class="month"><?php echo date('M',strtotime($datapost)) ?><br/><?php echo date('d',strtotime($datapost)) ?></br/></span><span class="year"><?php echo date('Y',strtotime($datapost)) ?></span></div>
        <div class="grid_9 alpha">
        <h1 class="luck"><?php echo $Titulo ?></h1>
        <p><?php echo $bloco1 ?></p>
        <?php
            $sql = mysql_query("select * from anexo where fk = $id");
            while($linha = mysql_fetch_array($sql)){
            $anexo = $linha['foto'];
            $descricao = $linha['descricao'];
            $link = $linha['link'];
        ?>
            <img src="./foto/<?php echo $anexo ?>" alt="" width="529" height="240"/>
            <span class="caption osans-i"><?php echo $descricao ?> - <a href=<?php echo $link ?>><?php echo $link ?></a></span>
        <?php 
            }
        ?>
        <p><?php echo $bloco2 ?></p>
        <div class="small_sep"></div>
        </div>
    </article>  
    <?php
        }}
    ?>

  <a href="#" class="luck previous">&lt; Prev</a>
  <a href="#" class="luck next">Next &gt;</a>


</div><!--/grid_11 - articles-->

database structure on my server:

inserir a descrição da imagem aqui

is something very simple (for now) just posting with possibility to include photos, I have created a default directory for the photos that are posted ./fotos, my problem is the following I did the insertion of values with Mysql both in posting and attachment when I try to recover this information only the first posting appears on the page, however when I remove the loop that checks how many images were attached it brings all the posts, however no images, when I put it again it loads only the first post and with images, the excerpt is this:

<?php
 $sql = mysql_query("select * from anexo where fk = $id");
 while($linha = mysql_fetch_array($sql)){
 $anexo = $linha['foto'];
 $descricao = $linha['descricao'];
 $link = $linha['link'];
?>
  <img src="./foto/<?php echo $anexo ?>" alt="" width="529" height="240"/>
  <span class="caption osans-i"><?php echo $descricao ?> - <a href=<?php echo $link ?>><?php echo $link ?></a></span>
 <?php 
  }
 ?>

with attachment loop:

com o codigo

no attachment loop:

sem o loop de anexo

1 answer

1


You are overwriting the variables at the time of picking up the "attachment". Change variable name, example:

$sql2 = mysql_query("select * from anexo where fk = $id");
while($linha2 = mysql_fetch_array($sql2)){
$anexo = $linha2['foto'];
...
  • truth worked, thank you beast!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.