Detail Page using CodeIgniter - php

I want to create a detail page, but when I click button examp_title, I can't move to Tryout/soal.
Thank You
Controller (Tryout.php)
public function deskripsi($tryout_id)
{
$data['tryout'] = $this->M_tryout->deskripsi_to($tryout_id)->row();
$data['exam_tpa'] = $this->M_tryout->get_exam_tpa($tryout_id)->result();
$data['exam_tps'] = $this->M_tryout->get_exam_tps($tryout_id)->result();
$this->load->view('tryout/deskripsi', $data);
}
public function soal($exam_code)
{
$data['soal'] = $this->M_tryout->get_soal_tryout($exam_code)->result;
$this->load->view('tryout/soal', $data);
}
View (deskripsi.php)
<?php foreach ($exam_tps as $key => $value) { ?>
<h5 class="fw-bold" class="sub_to">
<a href="<?php base_url('tryout/soal/') ?>
<?php echo $exam->exam_code?>">
<?php echo $value->exam_title;?>
</a>
</h5>
<p>
<?php echo $value->exam_duration;?> Menit,
<?php echo $value->exam_count_question;?> soal <br> Pembahasan
</p>
<?php } ?>

It looks like your <a> tag is not outputting the link you want due to a missing echo.
I have simplified the href below...
<h5 class="fw-bold" class="sub_to">
<a href="<?php echo base_url('tryout/soal/') . $exam->exam_code ?>">
<?php echo $value->exam_title; ?>
</a>
</h5>

Related

My route somehow keep redirecting to wrong url

so
i try make a pos(point of sale) program using ci3
im trying add a feature where admin can make new menu and submenu
but something went wrong
when i goto controller "sistem"
my route show "sitename/sistem/sistem/menu" this route supposed to "sitename/sistem/menu". another controller also effected when i goto "dashboard" controller the route show
"sistem/dashboard"
this is sistem controller
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Sistem extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->model('M_menu');
$this->load->model('M_user');
if (!$this->session->userdata('email')) {
redirect('auth');
}
}
public function index()
{
$this->menu();
}
public function menu()
{
$data['judulpage'] = 'Manajemen Menu';
$data['datamenu'] = $this->M_menu->getmenus()->result_array();
$data['user'] = $this->M_user->getuserdata()->row_array();
$this->form_validation->set_rules('menutambah', 'Menu', 'required');
// $this->form_validation->set_message([
// 'required' => 'Field menu add harus diisi'
// ]);
if ($this->form_validation->run() == false) {
$this->load->view('template/header', $data);
$this->load->view('template/sidebar', $data);
$this->load->view('sistem/menu', $data);
$this->load->view('template/footer');
} else {
$menu['menu'] = $this->input->post('menutambah');
$this->M_menu->insertmenu($menu);
$this->session->set_flashdata('flash','Sukses');
redirect('sistem');
}
}
this is the sidebar.php i think this is the problem but i cant find the solution
<?php
$role_id = $this->session->userdata('role_id');
$queryMenu = "SELECT `user_menu`.`id`, `menu`, `icon_menu`
FROM `user_menu`
JOIN `user_access_menu` ON `user_menu`.`id` = `user_access_menu`.`menu_id`
WHERE `user_access_menu`.`role_id` = $role_id";
$menus = $this->db->query($queryMenu)->result_array();
?>
<!-- BEGIN: Main Menu-->
<div class="main-menu menu-fixed menu-dark menu-accordion menu-shadow" data-scroll-to-active="true">
<div class="main-menu-content">
<ul class="navigation navigation-main" id="main-menu-navigation" data-menu="menu-navigation">
<li class=" navigation-header"><span>MENU</span><i class=" feather icon-minus" data-toggle="tooltip" data-placement="right" data-original-title="Apps"></i>
</li>
<?php foreach($menus as $menu) : ?>
<?php
$menuid = $menu['id'];
$querysubmenu = "SELECT * FROM `user_sub_menu` WHERE `menu_id` = $menuid AND `is_active` = 1";
$submenus = $this->db->query($querysubmenu)->result_array();
?>
<li class=" nav-item"><i class="<?php echo $menu['icon_menu']; ?>"></i><span class="menu-title"><?php echo strtoupper($menu['menu']); ?></span>
<ul class="menu-content">
<?php foreach($submenus as $submenu) : ?>
<li>
<a class="menu-item" href="<?php echo $submenu['url']; ?>"><i class="<?php echo $submenu['icon']; ?>"></i><span><?php echo $submenu['title']; ?></span></a>
</li>
<?php endforeach; ?>
</ul>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
i take the url from database.
u can see from inspect mode, the href redirecting to sistem/menu which is coorect url but when i click it, it goto sistem/sistem/menu
You do not need to call double <?php ?> tag.
just do this
<?php echo base_url($submenu['url']); ?>
or simplify the echo syntax with
<?= base_url($submenu['url']); ?>
fixed href="<?php echo base_url(); ?> i add / this before php tag but somehow it worked but still directing to wrong url localhost/sistem/menu it supposed to localhost/site/sistem/menu, so i add base_url to add my sitename and it work, thx
<li>
<a class="menu-item" href="<?php echo base_url(); ?><?php echo $submenu['url']; ?>">
<i class="<?php echo $submenu['icon']; ?>"></i><span><?php echo $submenu['title']; ?></span></a>
</li>

sending data view to controller in codeigniter

my view
<div class="dropdown1">
<button class="dropbtn1">Asia</button>
<div class="dropdown1-content">
<li>
<ul style="height:520px; overflow: auto">
<?php foreach ($result as $row) {?>
<li>
<a href="<?php echo base_url(); ?>index.php/MyWeb_Controller/countriesView/<?php echo $row['count_name']?>">
<?php echo $row['count_name'];?>
</a>
</li>
<?php } ?>
</ul>
</li>
</div>
</div>
my controller
public function countriesView($a){
$this->load->helper('url');
$this->load->view('Country_View');
var_dump($a);die();
}
the result is show like this
string(12) "%20%20BRUNEI"
i want to show only the country name 'BRUNEI'
You can use - (dash) instant of space because space value change in url like %20%. Try the following code i have replace space to - in view and revert it on controller
View :
<div class="dropdown1">
<button class="dropbtn1">Asia</button>
<div class="dropdown1-content">
<li>
<ul style="height:520px; overflow: auto">
<?php foreach ($result as $row) {?>
<li>
<?php $county_name = str_replace(' ','-',$row['count_name']); ?>
<a href="<?php echo base_url(); ?>index.php/MyWeb_Controller/countriesView/<?php echo $county_name; ?>">
<?php echo $row['count_name'];?>
</a>
</li>
<?php } ?>
</ul>
</li>
</div>
</div>
Controller :
public function countriesView($a){
$this->load->helper('url');
$this->load->view('Country_View');
$a = str_replace('-',' ',$a);
var_dump($a);die():
}

how to skip part of HTML code

I have the following code.
while ($slideNews = mysqli_fetch_array($slideImage )) {
$cutNews = LimitarCaracteres($slideNews['textNews'], $maxCaracteres = 300);
?>
<li>
<a href="<?php echo ROOT;?>/News/<?php print $slideNews["id"].'/'.$slideNews["friendlyURL"];?>">
<span>
<?php echo $cutNews; ?>
</span>
<h2 class="nomeGame"><?php print $slideNews["game"];?></h2>
<img src=" <?php echo $slideNews['secondImage']; ?> ">
</a>
</li
<?php } ?>
I need to do that in this part of the code:
<h2 class="nomeGame"><?php print $slideNews["game"];?></h2>
html does not run, I just need the part of the text

PHP foreach - Creating multple searchs in the same page

Firstly, I am a total php newby.
Secondly, below is the php header plus corresponding recursive commands for 2 photo lightboxes that are in the same html page.
Without the lines
getRecords() as $Title_row){ ?>
The page shows shows the first picture that is held in the external db table in the lightbox correctly.
Yet when I add the line below to add all the other entries in each table
getRecords() as $Title_row){ ?>
the page goes white and the browser html return is empty.
As I do not really understand what I am doing, I am stuck. Any suggestions would be very welcome.
<?php
$Title_find = $Lowdenphotoweb->newFindCommand('MASTER_photo');
$Title_findCriterions = array('Order_web'=>'*',);
foreach($Title_findCriterions as $key=>$value) {
$Title_find->AddFindCriterion($key,$value);
}
fmsSetPage($Title_find,'Title',50);
$Title_find->addSortRule('Order_web',1,FILEMAKER_SORT_ASCEND);
$Title_result = $Title_find->execute();
if(FileMaker::isError($Title_result)) fmsTrapError($Title_result,"error.php");
fmsSetLastPage($Title_result,'Title',50);
$Title_row = current($Title_result->getRecords());
?>
<?php
$Title1_find = $Lowdenphotoweb->newFindCommand('MASTER_photo');
$Title1_findCriterions = array('Order_web'=>'*',);
foreach($Title1_findCriterions as $key=>$value) {
$Title1_find->AddFindCriterion($key,$value);
}
fmsSetPage($Title1_find,'Title',50);
$Title1_find->addSortRule('Order_web',1,FILEMAKER_SORT_ASCEND);
$Title1_result = $Title1_find->execute();
if(FileMaker::isError($Title1_result)) fmsTrapError($Title1_result,"error.php");
fmsSetLastPage($Title1_result,'Title',50);
$Title1_row = current($Title1_result->getRecords());
?>
<!DOCTYPE html>
<!-- Lightbox Gallery -->
<?php foreach($Title_result->getRecords() as $Title_row){ ?>
<div class="hide">
<a data-group="gallery-1" data-caption="<?php echo $Title_row->getField('Title'); ?>" href="<?php echo $Title_row->getField('Pic_location'); ?>"></a>
</div>
<?php foreach($Title2_result->getRecords() as $Title2_row){ ?>
<div class="hide">
<a data-group="gallery-2" data-caption="<?php echo $Title2_row->getField('Title'); ?>" href="<?php echo $Title2_row->getField('Pic_location'); ?>"></a>
</div>
<!-- Lightbox Gallery End-->
You just missed out the closing brackets :
<?php foreach($Title_result->getRecords() as $Title_row){ ?>
<div class="hide">
<a data-group="gallery-1" data-caption="<?php echo $Title_row->getField('Title'); ?>" href="<?php echo $Title_row->getField('Pic_location'); ?>"></a>
</div>
<?php }?>
<?php foreach($Title2_result->getRecords() as $Title2_row){ ?>
<div class="hide">
<a data-group="gallery-2" data-caption="<?php echo $Title2_row->getField('Title'); ?>" href="<?php echo $Title2_row->getField('Pic_location'); ?>"></a>
</div>
<?php }?>

Page goes blank after adding to PHP foreach

Hello after I add some code to this PHP foreach the page goes blank and all I can see is a round black dot at the top left of screen.
My website is in Joomla3 and I am trying to customize a module. my site is http://get2gethersports.com
I have a recent post module that only shows the articles title.
that code is posted below
<?php if ($items) { ?>
<ul class="rsblog-recent-module unstyled<?php echo $params->get('moduleclass_sfx',''); ?>">
<?php foreach ($items as $item) { ?>
<li>
<a <?php echo $opener; ?> href="<?php echo JRoute::_('index.php?option=com_rsblog&view=post&id='.RSBlogHelper::sef($item->id,$item->alias).$Itemid,false); ?>">
<?php echo $item->title; ?>
</a>
</li>
<?php } ?>
</ul>
<?php } ?>
I would like to add an image abocve like the blog feed on http://vape-co.com
So I navigated to the component and saw the call for the image. which is posted below:
<div class="rsblog-entry-content">
<?php if ($this->item->image) { ?>
<div class="rsblog-entry-image">
<img class="rsblog-entry-thumb img-polaroid" src="<?php echo JURI::root().'components/com_rsblog/assets/images/blog/'.$this->item->image; ?>?nocache=<?php echo uniqid(''); ?>" alt="<?php echo $this->escape($this->item->title); ?>">
</div>
<?php } ?>
but whenever i add it or a snippet of it to the previous code it breaks....
Any ideas why it is breaking the page and how to fix it?
I tried adding in new li tags. Just adding the PHP part above the a link etc...
CODE UPDATE----
<?php if ($items) { ?>
<ul class="rsblog-recent-module unstyled<?php echo $params->get('moduleclass_sfx',''); ?>">
<?php foreach ($items as $item) { var_dump($item);?>
<li>
<div class="rsblog-entry-content">
<?php if ($this->item->image) { ?>
<div class="rsblog-entry-image">
<img class="rsblog-entry-thumb img-polaroid" src="<?php echo JURI::root().'components/com_rsblog/assets/images/blog/'.$this->item->image; ?>?nocache=<?php echo uniqid(''); ?>" alt="<?php echo $this->escape($this->item->title); ?>">
</div>
</div>
<?php } ?>
<a <?php echo $opener; ?> href="<?php echo JRoute::_('index.php?option=com_rsblog&view=post&id='.RSBlogHelper::sef($item->id,$item->alias).$Itemid,false); ?>">
<?php echo $item->title; ?>
</a>
</li>
<?php } ?>
</ul>
<?php } ?>
Try $item->image instead of $this->item->image
Correct code. Looks like it just needed some reduction.
<?php if ($items) { ?>
<ul class="rsblog-recent-module unstyled<?php echo $params -> get('moduleclass_sfx',''); ?>">
<?php foreach ($items as $item) { ?>
<li>
<?php if($item->image != '') ?>
<img src="components/com_rsblog/assets/images/blog/<?php echo $item->image;?>" alt="<?php echo $item->title. "logo";?>" width="100px"/>
<br/>
<a <?php echo $opener; ?> href="<?php echo JRoute::_('index.php?option=com_rsblog&view=post&id='.RSBlogHelper::sef($item->id,$item->alias).$Itemid,false); ?>">
<?php echo $item->title; ?>
</a>
</li>
<?php } ?>
</ul>
<?php } ?>

Categories