I have a page where i listed a posts from a database and I want to do that when i clicked a specific post it redirect me to another page with blank area where is more details with ID of this post. I don't know how to do that the blank area will which post were clicked. (Sorry for my english)
<div class="row">
<?php
foreach ($viewmodel as $item) : ?>
<div class="col-sm-4">
<div class="card shadow">
<div class="card-header border-dark shadow"><?php echo $item['TITLE']; ?></div>
<div class="card-body">
<p class="card-text"><?php echo $item['DESCRITIONS']; ?></p>
<a class="btn badge-secondary btn-sm" type="submit"
href="<?php echo ROOT_PATH; ?>shares/zobaczZadanie">More</a>
</div>
<div class="card-footer">
<small class="text-muted"><?php echo $item['DATE']; ?></small>
</div>
</div>
</div>
<?php endforeach; ?>
But I don't have acces to specific post
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 months ago.
Improve this question
I have a feature to show about agenda of my office on my site. The agenda feature has some columns such as : title, description, date-start, date-end, place, time, notes. If I add too short description, the CSS messed up. Here's the screenshot :
https://i.ibb.co/FsWX9hC/error1.png
but if I add long texts on the description, it looks completely normal
https://i.ibb.co/7SyyyB5/normal.png
here's the code :
<div class="row">
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane active" id="upcoming-events" role="tabpanel">
<?php foreach($data->result() as $row):?>
<div class="col-md-12">
<div class="row">
<div class="col-md-2">
<div class="event-date">
<h4><?php echo date("d", strtotime($row->agenda_tanggal));?></h4> <span><?php echo date("M Y", strtotime($row->agenda_tanggal));?></span>
</div>
<span class="event-time"><?php echo $row->agenda_waktu;?></span>
</div>
<div class="col-md-10">
<div class="event-heading">
<h3><?php echo $row->agenda_nama;?></h3>
<p><?php echo $row->agenda_deskripsi;?></p>
</div>
</div>
</div>
<hr class="event-underline">
</div>
<?php endforeach;?>
<div class="col-md-12 text-center">
<?php echo $page;?>
</div>
</div>
</div>
</div>
A row may only have cols as it's direct children, but your outer row has a tab-content as a child.
You could move up the col-md-12 from the foreach loop, so that's directly beneath the outer row:
<div class="row">
<div class="col-md-12">
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane active" id="upcoming-events" role="tabpanel">
<?php foreach($data->result() as $row):?>
<div class="row">
<div class="col-md-2">
<div class="event-date">
<h4><?php echo date("d", strtotime($row->agenda_tanggal));?></h4> <span><?php echo date("M Y", strtotime($row->agenda_tanggal));?></span>
</div>
<span class="event-time"><?php echo $row->agenda_waktu;?></span>
</div>
<div class="col-md-10">
<div class="event-heading">
<h3><?php echo $row->agenda_nama;?></h3>
<p><?php echo $row->agenda_deskripsi;?></p>
</div>
</div>
</div>
<hr class="event-underline">
<?php endforeach;?>
<div class="col-md-12 text-center">
<?php echo $page;?>
</div>
</div>
</div>
</div>
</div>
I have a display_all_groups.php page that display a bootstrap card of all groups created by user. When users click on "View Group" hyperlink it will direct them to view_group.php
Here are my code
session_start();
require_once $_SERVER["DOCUMENT_ROOT"].'/mindspace/Business Services Layer/ManageGroupsController/GroupsController.php';
$std_id = $_SESSION['std_id'];
$group = new ManageGroupsController();
$data = $group->viewGroups($std_id);
?>
<div class="main-panel">
<div class="content-wrapper">
<div class="row">
<div class="col-12 grid-margin stretch-card">
<form method="post">
<?php
foreach($data as $row){
?>
<div class="card-body">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="../../template/images/banner.png" alt="Card image cap">
<div class="card-body">
<h5 class="card-title"><?=$row['group_name']?></h5>
<p class="card-text"></p>
<a class="btn btn-primary" href="view_group.php?group_id=<?=$row['group_id']?>">View Group</a>
</div>
</div>
</div>
</form>
<?php } ?>
</div>
</div>
</div>
</div>
When I try to click on the View Group button, it did not bring me to other page that I want it to. Please help, Im very new to PHP
It's hard to say exactly what the problem could be. First I would always check that $data is not empty. Then the keys are named correctly. I don't know the data object.
If everything is correct, then it should work. A small note: In the link there is still a simple quotation mark. You should delete that too.
<?= $row['group_id']?> >>>>**'**<<<< "
<?php session_start();
require_once $_SERVER["DOCUMENT_ROOT"] . '/mindspace/Business Services Layer/ManageGroupsController/GroupsController.php';
$std_id = $_SESSION['std_id'];
$group = new ManageGroupsController();
$data = $group->viewGroups($std_id);
?>
<div class="main-panel">
<div class="content-wrapper">
<div class="row">
<div class="col-12 grid-margin stretch-card">
<form method="post">
<?php
foreach ($data as $row) {
?>
<div class="card-body">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="../../template/images/banner.png" alt="Card image cap">
<div class="card-body">
<h5 class="card-title"><? echo $row['group_name']; ?></h5> <!-- Used echo -->
<p class="card-text"></p>
<a class="btn btn-primary" href="view_group.php?group_id=<? echo $row['group_id']; ?>">View Group</a> <!-- used echo, removed extra single quote -->
</div>
</div>
</div>
</form>
<?php } ?>
</div>
</div>
</div>
</div>
I had done a few changes in the code,
Used echo
Removed an additional single quote
Can you please advise which is the most appropriate way to append classes dynamically to the 's below based on the ID of the post?
The goal is to add a class to some of the div's depending on the ID of the post being even or odd.
<div class="service__preview">
<div class="row mb-5">
<div class="col-4">
<div class="row">
<div class="col-5 // here I want to dynamically add order-2 if get_the_ID() is even">
<div class="service__preview service__preview-id">
<?php echo get_the_ID() + 1;?>
</div>
</div>
<div class="col-7 // here I want to dynamically add order-1 if get_the_ID() is even">
<div class="service__preview service__preview-icon">
<div class="icon__container icon__container-3x">
<div class="icon__container icon__container-2x">
<div class="icon__container icon__container-1x">
<i class="<?php echo get_post_meta($post->ID, 'service_icon', true); ?> fa-2x"></i>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-1">
</div>
<div class="col-6">
<a class="service__preview service__preview-title" href="<?php the_permalink(); ?>"><h3><?php the_title(); ?></h3></a>
<p class="service__preview service__preview-description"><?php the_content(); ?></p>
<a class="service__preview service__preview-link" href=" <?php the_permalink(); ?>"><p>Learn more</p></a>
</div>
</div>
Looking forward to your suggestions.
FYI: the project is a WordPress template.
how to retrieve data from mysql by id to another page?
Example:
<div class="col-md-12">
<div class="row">
<?php while($posts = mysqli_fetch_assoc($featured)): ?>
<div class="col-xs-12 col-md-6">
<div class="thumbnail">
<img src="<?=$posts['image']; ?>" alt="<?=$posts['title']; ?>">
<span class="pull-right"><?=$posts['date_info'];?></span>
<div class="caption">
<h3><?=$posts['title']; ?></h3>
<p><?php echo substr($posts['description'],0,300); ?></p>
<p>More..</p>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
</div>
When i click More button, it would be display more information in another page.
Upon doing this I am gating the data in an un alligned manner. I am getting 2 datas but the third data is coming under second data and 4th below first data but 3rd and forth are not in a single row there placed one after the other.
My View
<div class="container col-md-9">
<?php
foreach($unidet as $tempuni)
{
?>
<div class="service-items col-md-6">
<h4 class="title-normal"><img class="img-responsive thumb" src="images/service/service-icon1.png" alt=""><strong><?php echo $tempuni['name'] ?></strong></h4>
<div class="row">
<div class="col-sm-6 service-item-img">
<img class="img-responsive thumbnail" src="admin/<?php echo $tempuni['image'];?>" alt="">
</div>
<div class="col-sm-6 service-item-content">
<p><?php echo $tempuni['description'];?></p>
<button type="button" class="btn btn-warning btn-sm" onclick="more(<?php echo $tempuni['id'];?>)">Read More</button>
</div>
</div>
</div>
<?php
}
?>
</div>
This is what I am getting
Nice solution would be to use array_chunk()
<?php foreach (array_chunk($unidet, 2) as $row): ?>
<div class="row">
<?php foreach ($row as $tempuni): ?>
<div class="service-items col-md-6">
<h4 class="title-normal"><img class="img-responsive thumb" src="images/service/service-icon1.png" alt=""><strong><?php echo $tempuni['name'] ?></strong></h4>
<div class="row">
<div class="col-sm-6 service-item-img">
<img class="img-responsive thumbnail" src="admin/<?php echo $tempuni['image'];?>" alt="">
</div>
<div class="col-sm-6 service-item-content">
<p><?php echo $tempuni['description'];?></p>
<button type="button" class="btn btn-warning btn-sm" onclick="more(<?php echo $tempuni['id'];?>)">Read More</button>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endforeach; ?>