Getting same post on every user id


#1

Hello so i have somehow stuffed up my code today
now when i click on a title for an post it will show me that
post but then when i click on the same user with other title
it shows me the same thing for that id
what am i doing wrong? :frowning:

<?php
     $page = $_GET['page'];
     $sql = "SELECT * FROM `news` LEFT JOIN `admin` ON admin.id = news.username WHERE admin.id = '$page' LIMIT 1 ";
     $result = mysqli_query($link, $sql);
     if( $result )    
     while($blog = mysqli_fetch_assoc($result)) {
    ?>       
        
        
        
      
     
          <div class="card mb-4">
            <div class="card-body">           
            <div class="dropdown-divider"></div>
              <h2 class="card-title"><?php echo $blog["title"]; ?></h2><?php  
              echo '</br>';
            if ($blog['sponored'] === "SPONSORED") {
echo '<span class="badge badge-pill badge-success  pull-right"><sponored>'. $blog['sponored'] .'</sponored></span>';  
      } else {
echo '<span class="badge badge-pill badge-info pull-right"><post>' . $blog['sponored'] . '</post></span>';
 } 

?>                               
<div class="dropdown-divider"></div> </br>

<?php echo $blog["content"]; ?>
              <p class="card-text">
              </p>                       
            </div>            
            <div class="card-footer text-muted">
            <div class="dropdown-divider"></div>

<span class="badge badge-pill badge pull-left"><light-css>author </light-css>

    <a href='/<?php echo $blog["id"]; ?>/<?php echo $blog["username"]; ?>.php'><user-css><?php echo $blog["username"]; ?></user-css></a>   
           
</span>

<span class="badge badge-pill badge pull-right"><light-css>Time</light-css><admin-css><?php echo date('h:i A' , strtotime($blog['Published']));?></admin-css></span>                          
 <span class="badge badge-pill badge pull-right"><light-css>on</light-css><admin-css><?php echo date('l jS F Y' , strtotime($blog['Published']));?></admin-css></span>                          
                        
 <div id='disqus_thread'></div>
        <script type='text/javascript'>
          /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
          var disqus_shortname = '<?php echo $row["disqus"]; ?>'; // required: replace example with your forum shortname
              (function() {
              var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
              dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
              (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
          })();
        </script>
            </div>
            <div class="dropdown-divider"></div>           
            <a href="<?php echo $row['siteurl']; ?>">home</a>
            </br>
        </div>       
       <?php } ?>

#2

Can you describe in more detail exactly where you are clicking? I only see one a href link, but that’s around the username, not the title. There’s no link tags around the blog title, so I’m not sure why clicking on it does anything else. When you click on the username, it should open a file in the id folder called username.php - is that correct?


#3

Hi droopsnoot No this is a view Post page and i cant get the view post Page to display the other title and the other post in the page as it displays the same one for the same user every time
when i click other title it will show me the same post for the same user again


#4

Sorry, that doesn’t really clarify what’s happening, and what you wanted it to do. You talk again about “click other title”, but I can’t see how clicking the title does anything at all. Perhaps you could add a screen shot, and point out where you are clicking and what isn’t correct about the action.

This line

     if( $result )    
        

should probably have an opening { at the end, with a corresponding close after the while() loop is closed. I’m not sure of the effect on missing it out.


#5

this is what i am talking about the other post

i got it to work before i added the join now i cant remember how or what i touch to make it not work now before it was displaying all post from all users now it only displays 1 post off each user


#7

I’m sorry, I can’t figure out what the problem is either from your code or the screen shot. I don’t understand how anything happens when you click on a title, or what should be appearing but is not.

Oh, that might be a clue. You haven’t mentioned before that you only just added the join into the query. Is it possible that it’s only displaying one entry because the data is making it? For example, I think with a left join you’ll only get a row from the main table if the joined table contains a suitable row.


#8

i dont really know


#10

Hi @noshoe.

Maybe it is an idea when you show us the query? You state that something was working before but after you have changed the query it isn’t any longer. It is very hard to solve a problem when you don’t know what the underlying idea is.

I am not sure offcource but in the anchor you have:

/<?php echo $blog["id"]; ?>/<?php echo $blog["username"]; ?>

When I see that I would presume you want to show a certain post from a certain user? You need to be a bit more clear!

Edit: Why do you need a link, like the above to show all posts from all users? Maybe it’s a good idea to show the tables as well


#11

thats the user username so when you click that it will take them to their profile

and i had the query code before working fine as it should now i mess it all up i cant think what was there before hand :frowning:


#12

So let me rephrase. You have a page with all blog posts. When someone click on a title of one of the posts you should go to that specific post?


#13

Yes you are right


#14

So what is the anchor to go to a specific post if:

/<?php echo $blog["id"]; ?>/<?php echo $blog["username"]; ?>

is not?


#15

this is the front page and this one even with join works just fine as it shows all blog post normal its just getting the post with what the user created
i am sure i stuffed up some where i just dont know it

and this is a part off a pagination code just so you know

<?php 
     $limit = 50;
     if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; };
     $start_from = ($page-1) * $limit;
     $sql = "SELECT * FROM news LEFT JOIN admin ON admin.id = news.username WHERE approved='1' ORDER BY news.id DESC LIMIT $start_from, $limit";    
     $result = mysqli_query($link, $sql);
     while($blog = mysqli_fetch_assoc($result)) {
     ?>

#16

Sorry to say so, but I find it all very confusing. So it’s not about all blog posts, but the blok posts when using the pagination? Do you have a link to a working version?


#17

the main reason i posted here was coz my view post is not working as it should now where it does not get the post that the user created every time yes i got an working version go have a look at
http://wecodedaily.com/
and i try error reporting nope it does not display any errors either


#18

@noshoe

Maybe it’s just me, but I understand less and less about what you are asking by the minute. Please try to formulate what you have and what is needed. I visited your demo and when I clicked a link I was going to that particular post.

Edit: Maybe its a good idea for the future, to make versions (v1, v2, etc). That way you can always fall back on a working version


#19

yes i know i should off have a back up :frowning:

this is where i went wrong