how to get radio button with the same id - php

I have a radio button. I have 2 radio button for different use, one is for displaying the ukuran and the other is for displaying the jenis. The radio button value is generated from database. I want to get the radio button value then when both of them is click I want to search to database with that certain value. Can anyone help me?
I try this
<ul class="list">
<li>
<a class="active" href="#">
<span>Jenis Produk </span>
</a>
</li>
<?php
foreach($jenis as $jns){
?>
<input type="radio" id="jenis_produk" name="jenis_produk" value="<?php echo $jns['jenis_id'];?>">
<label><?php echo $jns['jenis_produk'];?></label><br>
<?php
}
?>
<li>
<span>Ukuran</span>
</li>
<?php
foreach($ukuran as $size){
?>
<input type="radio" id="ukuran_produk" name="ukuran_produk" value="<?php echo $size['ukuran_id'];?>">
<label><?php echo $size['size'];?></label><br>
<?php
}
?>
</ul>
Thank You :)

You can simply use following in the controller to get values
$jenis = $this->input->post("jenis_produk");
$ukuran = $this->input->post("ukuran_produk");
Then pass it to a model and
$sets = array("jenis" => $jenis,
"ukuran" => $ukuran);
$result = $this->db->where($sets)->get("table_name")->result_array();

Related

how to get the HREF value using POST

I'm making a dynamic menu where each link in my dropdown menu will be directed to a page base on the ID in the HREF link. How can I POST the ID from my link?
Here's my code:
<?php
$lesson_sql = "SELECT * FROM lesson WHERE lessonID = 1";
$lesson_query = mysqli_query($db, $lesson_sql);
$lesson = mysqli_fetch_assoc($lesson_query);
?>
<nav id="navbar">
<ul id="navmenu">
<div class="navmenu">
<li><strong>Catalog</strong><span class="darrow"></span>
<ul class="sub1">
<li>Topic 1
<ul class="sub1_1">
<?php
do {
?>
<li>
<a href="lesson1.1.php?lessonID=<?php echo $lesson['lessonID'];?>">
<?php echo $lesson['lessonName']; ?>
</a>
</li>
<?php
}while ($lesson = mysqli_fetch_assoc($lesson_query));
?>
</ul>
</li>
</ul>
</li>
</div>
</ul>
</nav>
And here is the code from the code above I wanted to get the ID, its beside the href value.
<li><?php echo $lesson['lessonName']; ?></li>
Sorry for my english, I hope you understand me!
in your lesson1.1.php file you can use $_GET to access the id as below.
$id = $_GET["lessonID"];
If you have query string then you use
$_GET['name of control']

How not to print empty string from database while editing record

I have a record in database where are two fields 'leader' and 'checker' are empty. I set it to NULL inside sql statement. Then when I want to edit record and press edit record button I got empty string as it is the name. here is the code:
<div class="projLeader">
<label>Captain:</label>
<ol>
<li class="placeholder" name="projLeader"><div class="adding">Drop Here</div></li>
<li class="dropClass" name="projLeader" <?php if (isset($projLeader)) echo 'value="'.$projLeader.'"' ?>><?php echo "<span class='closer'>x</span>".$projLeader.""?></li>
<input type="hidden" name="projLeader" class="hiddenListInput1" />
</ol>
</div>
<div class="projChecker">
<label>Coordinator:</label>
<ol>
<li class="placeholder" name="projChecker"><div class="adding">Drop Here</div></li>
<li class="dropClass" name="projChecker" <?php if (isset($projChecker)) echo 'value="'.$projChecker.'"' ?>><?php echo "<span class='closer'>x</span>".$projChecker."" ?></li>
<input type="hidden" name="projChecker" class="hiddenListInput2" />
</ol>
</div>
I want to print it only if there is name not just empty string. But even the fields are empty I got How can I not to print empty fields?
You can use IF Else in Php block for Empty or Null value in variable which would set by select query result values. If variable is empty or null then it will not add the list item code. For ex-
<div class="projLeader">
<label>Captain:</label>
<ol>
<li class="placeholder" name="projLeader"><div class="adding">Drop Here</div></li>
<?php
if (($projLeader != "") && (!is_null($projLeader)) { ?>
<li class="dropClass" name="projLeader" <?php if (isset($projLeader)) echo 'value="'.$projLeader.'"' ?>><?php echo "<span class='closer'>x</span>".$projLeader.""?></li>
<?php } ?>
<input type="hidden" name="projLeader" class="hiddenListInput1" />
</ol>
</div>

Storing HTML tags including PHP script in the database using Codeigniter

i'm trying to store html tag that includes php script.
This is for the navigation menu, i'm trying to display only the menu for a particular user role.
I'm storing it this way
public function edit_module(){
$id = $this->input->post('Module_ID', TRUE);
$update = $this->db->update('ref_modules', array('Module_Name'=>$this->input->post('Module_Name', TRUE),
'Module_Menu'=> htmlspecialchars($this->input->post('Module_Menu')),
'UpdatedBy'=>$this->session->userdata('user_id')), "Module_ID = '$id'");
if($update){
return TRUE;
}
}
For display
<!--Menu-->
<!--================================-->
<div id="mainnav-menu-wrap">
<div class="nano">
<div class="nano-content">
<ul id="mainnav-menu" class="list-group">
<!--Category name-->
<li class="list-header">Navigation</li>
<?php if($this->data['menu']): ?>
<?php foreach($this->data['menu'] as $row): ?>
<?php echo htmlspecialchars_decode($row->Module_Menu); ?>
<?php endforeach; ?>
<?php endif; ?>
</ul>
</div>
</div> <!-- nano -->
</div><!-- mainnav-menu-wrap -->
<!--================================-->
<!--End menu-->
When i view the source, its fine but when i click the link, special characters are showing.
http://localhost/folderName/%3C?php%20echo%20base_url(%27citizens%27);%20?%3E
Here's a sample value that i am inserting
<li class="<?php echo ($title == 'Citizens' ? 'active-link' : '');?>">
<a href="<?php echo base_url('citizens'); ?>">
<i class="fa fa-user"></i>
<span class="menu-title">
<strong>Citizens</strong>
</span>
</a>
</li>
Any idea guys? Thanks in advance!
Inserting Html into database For Different user role is not the right way. You can use if Conditions To show your Menu for different User roles.

php code to display icon on active button

I am working on cakephp 1.3..
i have button and value displaying inside button coming from database.
I want to show arrow icon on my active button only..
now the active arrow icon is displaying in all button...inside forloop.
plz help me to do this..
below is my code
<?php
foreach($modes as &$mo)
{
$temp = "Road Vs "; $mo = strtolower($mo);
?>
<li class="active">
<input name="data[Customer][mode]" class="railbtn" type="submit" id="mode" value="<?php echo $temp.$mo; ?>">
<span class="arrow">
<?php echo $this->Html->image('red_arrow.png', array('alt' => '')); ?>
</span>
</li>
<?php } ?>
You should add a condition in your for loop
Like this
<?php
// you need to send button unique name to controller
foreach($modes as &$mo)
{
$temp = "Road Vs "; $mo = strtolower($mo); ?>
<li class="<?php echo ($mo == $selectedUniqueButtonID) ? 'active' : '' ?>">
<input name="data[Customer][mode]" class="railbtn" type="submit" id="mode" value="<?php echo $temp.$mo; ?>">
<?php if($mo == $selectedUniqueButtonID){ ?>
<span class="arrow">
<?php echo $this->Html->image('red_arrow.png', array('alt' => '')); ?>
</span>
<?php } ?>
</li>
<?php
} ?>
Controller code
$selectedUniqueButtonID = $this->data['Customer']['mode'];
$this->set('selectedUniqueButtonID',$selectedUniqueButtonID);

hidden div not working correctly in for loop using a modal box

I have a mysql select and it spits out all the results in a <ul> that I have setup in a for loop. This works great. However, I wanted to have a "click more" type link at the bottom of each result that opens in a modal box when clicked. I also got this working just fine. What doesn't work, however, is the data inside what is displayed inside the modal box. It displays the data correctly but it is from the first result no matter what result you click. I thought I just didn't have my for loop setup correctly but it works when I change the id of the div the content is in for the modal box (but then the modal box doesn't work obviously).
Is there some reason why hiding a div would mess a for loop up as far as which row to display?
Below is the for loop
for($i=0; $i<$num_results; $i++)
{
$row = mysql_fetch_array($result);
?>
<div id='basic-modal'>
<ul style="background-color:#F5F5F5; padding:2px;">
<li class="program" style="font-size:18px;"><strong><?php echo trim ($row["program"]); ?></strong></li>
<li><strong>Sponsored by:</strong> <i><?php echo trim ($row["organization"]); ?></i></li>
<li><strong>Discipline:</strong> <?php echo trim ($row["discipline"]); ?></li>
<li><strong>Mission:</strong> <?php echo trim ($row["mission"]); ?></li>
<li><strong>Description:</strong> <?php echo trim ($row["content"]); ?></li>
<li><strong>Grade(s):</strong> <?php echo trim ($row["grade"]); ?></li>
<li><strong>Cost:</strong> <?php echo trim ($row["cost"]); ?></li>
<li> </li>
<li>Contact Info</li>
</ul>
<br />
<br />
</div>
<!-- pop up contact info -->
<div id="basic-modal-content">
<ul style="font-size:12px">
<li class="program" style="font-size:18px;"><strong><?php echo trim ($row["program"]); ?></strong></li>
<li><strong>Sponsored by:</strong> <i><?php echo trim ($row["organization"]); ?></i></li>
<li><strong>Contact Person:</strong> <?php echo trim ($row["contact"]); ?></li>
<li><strong>Contact Email:</strong> <?php echo trim ($row["email"]); ?></li>
<li><strong>Contact Phone:</strong> <?php echo trim ($row["phone"]); ?></li>
<li><strong>Contact Hours:</strong> <?php echo trim ($row["contactHours"]); ?></li>
</ul>
</div>
<!-- preload the images -->
<div style='display:none'>
<img src='images/x.png' alt='' />
</div>
<?php
}
?>
I'm using Eric Martin's SimpleModal if that makes a difference.
Thanks for the help.
You have same id of each div it is wrong

Categories