douti9253 2018-04-19 15:25
浏览 53

显示基于URL的记录

I have a problem with getting the right records out of the database. look at the img. When I click on the left on a board it will put that in the url. Like this https://####/boards/stel-jezelf-voor. Now I want it to display only the records that have that url.

The question summary: I want to display the records based on the url. Example: When I press nieuws & events and it will only display the 'topics' with that url

the topic database

enter image description here

The database where the url's are stored

enter image description here

How it look now

enter image description here

<?php
  $toppic = $app->get_topics();
     foreach($toppic as $topic){
       echo '<a href="https://####/reactie"> <div id="topic">';
       echo '<div id="topicimg">';
        if(file_exists('assets/images/profielfotos/'.$topic['klant_id'])) { 
           echo '<img class="img-circle" src="/assets/images/profielfotos/'.$topic['klant_id'].'/'.$topic['foto'].'" />';
        } else {
           echo '<i class="fa fa-fw fa-user img-circle"></i>';
        }
     echo '</div><div id="topictekst">';
     echo '<b>'.$topic['topicnaam'].'</b>'; 
     echo ' - ' . $topic['voornaam'] . " " . $topic['achternaam'] ;
     echo '<span style="float:right; margin-top:15px; margin-left:5px;">'.implode($app->count_reactie($topic['id'])) .' reacties</span> <span style="float:right; color:lightgrey; margin-top:15px"class="fa fa-comment"></span>';
      echo '<hr><span class="badge bg-red">' . implode($app->boards($topic['board_id'])) . '</span>';
      echo ' laatste reactie: ' .$app->tijd_reactie($topic['id']) . ' door ' .$app->reactieDoor($topic['id']);
      echo '</div></div></a>';
    }
?>

The function:

public function get_topics(){
        $getTopic = $this->database->query("
        SELECT topics.*, klanten.foto, klanten.voornaam, boards.topic, ledenpagina.ledenpagina_id, klanten.achternaam FROM topics 
        LEFT JOIN ledenpagina ON ledenpagina.ledenpagina_id = topics.ledenpagina_id
        LEFT JOIN klanten ON topics.klant_id=klanten.id
        LEFT JOIN boards ON topics.board_id=boards.id
        WHERE ledenpagina.ledenpagina_id=:ledenpagina_id 
        ORDER BY id ASC");
        $this->database->bind(":ledenpagina_id", $_SESSION['ledenpagina_id']);

        $topics = $this->database->resultset();

        return $topics;

    }

I hope that this is enough information so someone can help me, This is my first question so don't be to hard on me and tell me if I am missing something.

  • 写回答

1条回答 默认 最新

  • dongshai2022 2018-04-19 20:34
    关注

    I would like to see where exactly you're assigning ledenpagina_id and if you're not making this too complex. You seem to be pulling a lot of data from the database, and i don't think you'd need this. wouldn't it be easier to write a function that just finds the id of the topic you need, and pull only the data you need on that topic, using the result of that? also, where is that session variable set? And what framework are you in? I think most entity frameworks have built in functionality that doesn't require you writing those SQL statements. My apologies that this is not a comment, i need more reputation points for that.

    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集