Only first row is printing. Others are not printing.
Only getting a submit button in other rows
no errors or warnings found in code.
$v and $u array is same. When $v is used in both foreach nothing is printing.
<?php
foreach ($v->result() as $row)
{
?>
<tr>
<?php echo form_open('add_exam', array('role' => 'form', 'class' => 'form-horizontal')); ?>
<?php
foreach ($u->list_fields() as $field)
{
?>
<td class='hidden-1024'>
<div class="form-group">
<div class="col-sm-9">
<input class="form-control" type="text" placeholder="<?php echo $field; ?>" name="<?php echo $field; ?>" value="<?php echo $row->$field;?>">
</div>
</div>
</td>
<?php
}
?>
<td class='hidden-1024'>
<?php echo form_submit(array('name' => 'score_submit', 'id' => 'score_submit', 'value' => 'Save', 'class' => 'btn btn-embossed btn-primary m-r-20'));?>
</td>
<?php echo form_close(); ?>
</tr>
<?php
}
?>
It should be like this:
value="<?php echo $row->field;?>"
Related
I am trying to create a Favourites Pages where the user selects items from the "menu" and then the item is placed in the Favourites Page. I am making use of a session variable
$_SESSION['favourites']
I am starting the session by using the
session_start('session.php');
In the session_start it includes
<?php
session_start();
?>
The favourite feature works when I combine the two files together, but it does not work when I display the favourites on a different page.
This is the menu page
$conn = mysqli_connect("localhost", "root", "", "restaurant");
$sql= "SELECT * FROM menu ORDER BY id ASC";
$result=mysqli_query($conn, $sql);
$resultcheck=mysqli_num_rows($result);
if(isset($_POST["add_to_favourite"]))
{
if(isset($_POST["favourites"]))
{
$food_item_id = array_column($_SESSION["favourites"], "item_id");
if(!in_array($_GET["id"], $food_item_id))
{
$count = count($_SESSION["favourites"]);
$item_array = array(
'item_id' => $_GET["id"],
'item_name' => $_POST["hidden_name"],
'item_price' => $_POST["hidden_price"],
'item_desc' => $_POST["hidden_desc"]
);
$_SESSION["favourites"][$count] = $item_array;
}else{
echo '<script>alert(You have already added this item to Favourites")</script>';
}
}
else{
$food_array = array(
'item_id' => $_GET["id"],
'item_name' => $_POST["hidden_name"],
'item_price' => $_POST["hidden_price"],
'item_desc' => $_POST["hidden_desc"]
);
$_SESSION["favourites"][0] = $food_array;
}
}
?>
<!-- Start of HTML -->
<section id="intro">
<div class="hero-global container">
<h1 class="global-header">Detailed Menu</h1>
</div>
</section>
<div class="container">
<ul class="food-cards">
<?php
if($resultcheck>0)
{
while($row=mysqli_fetch_assoc($result))
{
?>
<li class="card-info">
<form method="post" action="favourites.php?action=add&id=<?php echo $row["id"]; ?>">
<div class="food-card">
<div class="food-pic">
<img src="./assets/english-breakfast.png" alt="">
</div>
<div class="food-cont">
<h2 class="food-title">
<?php
echo $row['name']
?>
</h2>
<p class="food-desc">
<?php echo $row["description"]; ?>
</p>
<div class="price-fav-btn">
<div class="price">
<?php
echo "€".$row['price']
?>
</div>
<div class="atf-btn">
<input class="fav-btn" type="submit" name="add_to_favourite" value="Add to Favourites"/>
</div>
<input type="hidden" name="hidden_name" value="<?php echo $row["name"]; ?>" />
<input type="hidden" name="hidden_price" value="<?php echo $row["price"]; ?>" />
<input type="hidden" name="hidden_desc" value="<?php echo $row["description"]; ?>" />
</div>
</div>
</div>
</form>
</li>
<?php
}
}
?>
</ul> <!-- end of ul list -->
</div>
This is the favourites page, where the items are displayed.
<?php
if(isset($_GET["action"]))
{
if($_GET["action"] == "delete")
{
foreach($_SESSION["favourites"] as $keys => $values)
{
if($values["item_id"] == $_GET["id"])
{
unset($_SESSION["favourites"][$keys]);
echo '<script>alert("Item Removed")</script>';
echo '<script>window.location="menudetails.php"</script>';
}
}
}
}
?>
<div><h1>Favourites</h1></div>
<table>
<tr style="text-align: left">
<th width="30%">Name</th>
<th width="60%">Description</th>
<th width="5%">Price</th>
<th width="5%">Remove</th>
</tr>
<?php
if(!empty($_SESSION["favourites"]))
{
foreach($_SESSION["favourites"] as $key => $value)
{
?>
<tr>
<td width: 20%><?php echo $value["item_name"] ?></td>
<td style="text-align: left"><?php echo $value["item_desc"]?></td>
<td><?php echo '€'.$value["item_price"]?></td>
<td><span class="fav-btn">Remove</span></td>
</tr>
<tr>
</table>
<?php
}
}
?>
EDIT:
I am starting the session on both pages.
Also, the part that is not working is when it comes to seeing whats in the favourites page. There is not output, only the link (in search bar) with the respective id.
Output
I'm trying to create a simple inline form that displays an entry field followed by a submit button - how can I alter this existing code so that these elements display horizontally in one row? ...I've tried altering the form class but no success. Thank you in advance.
PHP
<div class="d3-mailchimp" data-block-id="<?php echo $bID; ?>">
<?php
if (isset($errors)) {
$errors->output();
}
if (isset($message)) {
echo '<p class="message">'.$message.'</p>';
} else {
?>
<form method="post" action="<?php echo $this->action('submit') ?>" onsubmit="d3_mailchimp_submit(this); return false;">
<?php $token->output('d3_mailchimp.subscribe'); ?>
<div class="form-group field">
<?php
echo $form->email('email_address', '', [
'required' => 'required',
'placeholder' => t(''),
]);
?>
</div>
<?php
if ($showTermsCheckbox) {
?>
<div class="accept-terms">
<label for="accept_terms">
<?php
echo $form->checkbox('accept_terms', 1, 0, [
'required' => 'required',
]);
?>
<?php echo $acceptTermsText; ?>
</label>
</div>
<?php
}
?>
<div class="submit-button">
<?php
echo $form->submit('submit', t('Subscribe'), [
'class' => 'button',
]);
?>
</div>
</form>
<?php
}
?>
I have built an OpenCart module and tested it on a few shops and it works well. One client just reported to me a problem and after inspecting the html I saw this:
My code in the .tpl template file:
<table class="table table-bordered table-hover" >
<tbody>
<?php foreach($row['strings'] as $row_string){
$key = $row_string['key'];
$id = $row['simpleFilePathEscaped'].$key; ?>
<tr>
<td class="text-center">
<label><?php echo $key; ?> </label>
</td>
<td class="text-center">
<div>
<input id="text_value_<?php echo $id; ?>" type="text" value="<?php echo $row_string['value']; ?>" placeholder="<?php echo $key; ?>" class="form-control" />
</div>
</td>
<td class="text-center" >
<button id="save_icon_<?php echo $id; ?>" onclick="addLiteralToFile('<?php echo $row['secondary_file_path_escaped'] ?>', '<?php echo $key; ?>', '<?php echo $id;?>');" class="btn btn-primary"><i id="save_inner_icon_<?php echo $id; ?>" class="fa fa-save"></i></button>
<div id="loading_icon_<?php echo $id; ?>" <div class="loader"></div> </div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
The result for an example row in this client's shop is this:
<tr>
<td class="text-center" >
<label>direction</label>
</td>
<td class="text-center">
<div>
<input id="text_value_" type="text" value="ltr" placeholder="direction" class="form-control">
</div>
</td>
<td class="text-center">
<button id="save_icon_" onclick="addLiteralToFile('----home----admin----domains----itrend.si----public_html----test----admin----language----english----en-gb.php', 'direction', '');" class="btn btn-primary"><i id="save_inner_icon_" class="fa fa-save"></i></button>
<div id="loading_icon_" <div="" class="loader"></div>
</td>
</tr>
If you notice you will see that all instances of <?php echo $id; ?> give an empty string. so id="save_icon_<?php echo $id; ?>" becomes id="save_icon_"
That is extremely strange because $id is a concat of $row['simpleFilePathEscaped'] and $key. Even if $row['simpleFilePathEscaped'] is empty I know for sure that $key has a value...Because it is echoed and in this example it is "direction" (in the label tag)
Need some help finding out why this is happening...
$row = { "strings" => array of { "key"=> string, "value"=> string },
"simpleFilePathEscaped" => string,
"secondary_file_path_escaped" => string,
"primary_file_path"=> string
}
Sorry if i misunderstood the way your $row is build.
if you make an example like
$row['strings'] = ['key' => 10];
$row['strings'] = ['key' => 110];
foreach($row['strings'] as $row_string)
$key = $row_string['key'];
print_r($key); //will give you an empty value
but print_r($row); // will give Array ( [strings] => Array ( ['key'] => 110 ) )`
you need to change your foreach.
foreach($row['strings'] as $row_key => $row_string)
$key = $row_key;
then it will give the 'key' on echo.
or you can do
foreach($row['strings'] as $row_string)
$key = key($row_string);
There is a bug in your code:
Given your array looks like this (as written in your question):
$row = [ "strings" => array of { "key"=> string, "value"=> string },
"simpleFilePathEscaped" => string,
"secondary_file_path_escaped" => string,
"primary_file_path"=> string
]
It is not possible for this code:
<?php foreach($row['strings'] as $row_string){
$key = $row_string['key']; // <--- THIS is not possible with the array structure you presented
$id = $row['simpleFilePathEscaped'].$key; ?>
<tr>
<td class="text-center">
<label><?php echo $key; ?> </label>
</td>
to print this as you suggested in your question:
<tr>
<td class="text-center" >
<label>direction</label>
</td>
Because during the foreach loop, the $row_string variable will hold a string value but you are trying to access it as an array with an associative key.
I don't know why the form teste only appear on the first result of the foreach.
Note:
<?php echo $this->Form->create(null, array(
'url' => array('controller' => 'menus', 'action' => 'reprovar', $procuracao['Attorney']['id'])
)); ?>`
This appears in every result of the foreach.
The tag <FORM> of the <?php echo $this->Form->create('teste'); ?> only appears in the first result.
In every element, the textarea and the button appears.
The full code:
<?php foreach ($procuracoes as $procuracao): ?>
<td><?php echo $procuracao['Attorney']['nome']; ?></td>
<td><?php echo $procuracao['Attorney']['estadocivil']; ?></td>
<td><?php echo $procuracao['Attorney']['identidade'].'/'.$procuracao['Attorney']['expedidor']; ?></td>
<td><?php echo $procuracao['Attorney']['cpf']; ?></td>
<td><?php echo $procuracao['Attorney']['status']; ?></td>
<td><ul>
<?php foreach ($procuracao['Power'] as $power): ?>
<li> <?php echo $power['resumo'] ?> </li>
<?php endforeach ?>
</ul></td>
<td>
<?php if($this->Session->read('Auth.User.id') == $procuracao['Attorney']['aprovador'] AND $procuracao['Attorney']['fluxo'] == 0 OR $this->Session->read('Auth.User.nivel') == 'administrador') : ?>
<div id="botoes-small">
<ul>
<input type="button" value="Aprovar" class="btn btn-success aprovar">
<div class="formaprovar">
<?php echo $this->Form->create('teste'); ?>
<?php echo $this->Form->textarea('testerrr', array('placeholder' => 'teste')); ?>
<?php echo $this->Form->submit('Ok', array('class' =>'btn btn-success', 'div' => false)); ?>
</div>
<input type="button" value="Reprovar" class="btn btn-danger reprovar">
<div class="formreprovar">
<?php echo $this->Form->create(null, array(
'url' => array('controller' => 'menus', 'action' => 'reprovar', $procuracao['Attorney']['id'])
)); ?>
<?php echo $this->Form->textarea('motivo', array('placeholder' => 'Motivo')); ?>
<?php echo $this->Form->submit('Ok', array('class' =>'btn btn-success pull-left', 'div' => false)); ?>
</div>
<?php endif; ?>
</ul>
</div>
<?php if($this->Session->read('Auth.User.id') == $procuracao['Attorney']['aprovador'] AND $procuracao['Attorney']['fluxo'] == 1): ?>
<div class="alert alert-success">
<b>Aprovado</b>
</div>
<?php endif; ?>
<?php if($this->Session->read('Auth.User.id') == $procuracao['Attorney']['aprovador'] AND $procuracao['Attorney']['fluxo'] == 3): ?>
<div class="alert alert-error">
<b>Recusado</b>
</div>
<?php endif; ?>
</td>
</tr>
<?php endforeach ?>
After a quick look, if looks like that form element is emitted inside an IF statement. Can you try taking it out? I am not sure exactly when you would or would not need to output the form tag, but that might be what is preventing it.
EDIT--it looks like you are naming the form "teste", the second form is not named. Trying taking the form name out--maybe it doesn't like them being named the same thing.
I have this form (I used crud generator and model generator):
Create Pig
[Name]
[Breed]
[Sickness] [Add sickness]
How do I make add sickness create a new textfield everytime I click it? I already have a table for the multivalued sicknessid, I just need to access that table and add all the sicknesses, use one same id so I can use it as foreign key in the table.
<?php
/* #var $this PigController */
/* #var $model Pig */
/* #var $form CActiveForm */
?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'pig-form',
'enableAjaxValidation'=>true,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'name'); ?>
<?php echo $form->dropDownList($model,'name');?>
<?php echo $form->error($model,'name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'breed'); ?>
<?php echo $form->dropDownList($model,'breed', $model- >getBreedOptions()); ?>
<?php echo $form->error($model,'breed'); ?>
</div>
/*
ENTER CODE FOR SICKNESS HERE
*/
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
I also had the same scenario. What i have done is with script.
Try this. It worked for me. Please do make necessary changes
$(function(){
$("#add").click(function(){
if(5 > $(".attr").length) {
var cycleBlock = '<tr id="item'+i+'">';
cycleBlock += '<td style="width: 447px;"> <label for="CategoryMstExt_Attribute">Attribute</label> <input type="text" id="CategoryMstExt_0_attributes" name="CategoryMstExt['+i+'][attributes]" class="attrName'+i+'" maxlength="100" size="44"> </td> <td> <label for="CategoryMstExt_Data_Type">Data Type</label> <select id="CategoryMstExt_'+i+'_datatype" name="CategoryMstExt['+i+'][datatype]" class="attr" onchange="javascript:checkSelection(this.value,'+i+')"> <option value="17">Textarea</option> <option value="16">Textbox</option> <option value="18">Listbox</option> </select><img onclick="deleteElm(item'+i+'.id);" src="<?php echo Yii::app()->request->baseUrl; ?>/assets/81ff99cf/gridview/delete.png" alt=""> </td>';
cycleBlock += '</tr>';
var $cycleBlock = $(cycleBlock);
$('#fields').append($cycleBlock);
i++;
} else {
alert('Maximum attributes limit reached');
}
});
});
<?php
<img style="margin-left:600px;" id="add" src="<?php echo Yii::app()->request->baseUrl; ?>/media/images/add.png">
<table id="fields" >
<tr id="item1" >
<td style="width: 447px;">
<?php echo $form->labelEx($model, 'Attribute'); ?>
<?php echo $form->textField($model, '[0]attributes', array('size' => 44, 'maxlength' => 100, 'class' => 'attrName0')); ?>
</td>
<td >
<?php echo $form->labelEx($model, 'Data Type'); ?>
<?php echo $form->dropDownList($model, '[0]datatype', Array('17' => 'Textarea', '16' => 'Textbox', '18' => 'Listbox'), array('onChange' => 'javascript:checkSelection(this.value,0)', 'class' => 'attr')); ?>
<img onclick="deleteElm(item1.id);" src="<?php echo Yii::app()->request->baseUrl; ?>/media/images/delete_2.png" alt="">
</td>
</tr>
</table>
?>