checkbox error in cakephp - php

<?php
$i= 0;
foreach($purchaseorder as $tdata):
$i++;
?>
<tr >
<td><?php echo $tdata['pay_date']; ?></td>
<td><?php echo $tdata['cylinder']; ?></td>
<td><?php echo $tdata['amount']; ?></td>
<td><?php echo $tdata['rtgs_no']; ?></td>
<td><?php echo $tdata['cheque_no']; ?></td>
<td><?php echo $tdata['dd_no']; ?></td>
<td><?php echo if ($tdata['approve']=='true')
{
?>
<img src="/../img/green.png" alt="alt-tag"/>;
<?php
}
else
{
?>
<img src="/../img/red.png" alt="alt-tag" />;
<?php } ?></td>
</tr>
<?php
endforeach;
?>
my code is when i check a checkbox and submit a green tick should be displayed in list page..if its not checked and submitted a red cross should be displayed..but i get a error in the above code..what sholud i do?

<td><?php if ($tdata['approve']=='true')
{ ?>
<img src="/../img/green.png" alt="alt-tag"/>
<?php }
else
{ ?>
<img src="/../img/red.png" alt="alt-tag" />
<?php } ?></td>

<?php
foreach($purchaseorder as $tdata):
?>
<tr >
<td><?php echo $tdata['pay_date']; ?></td>
<td><?php echo $tdata['cylinder']; ?></td>
<td><?php echo $tdata['amount']; ?></td>
<td><?php echo $tdata['rtgs_no']; ?></td>
<td><?php echo $tdata['cheque_no']; ?></td>
<td><?php echo $tdata['dd_no']; ?></td>
<td><?php if($tdata['approve']==true)
{
?>
<img src="/../img/green.png" alt="alt-tag"/>;
<?php
}
else
{ ?>
<img src="/../img/red.png" alt="alt-tag" />;
<?php
} ?>
</td>
</tr>
<?php
endforeach;
?>
try this code and if possible show me the data thats comes on "$purchaseorder" variable

First make var_dump($tdata) and look 'approve' index value. If is set $tdata['approve'] then change code:
<td><?php if ($tdata['approve']=='true')
{ ?>
<img src="/../img/green.png" alt="alt-tag"/>
<?php }
else
{ ?>
<img src="/../img/red.png" alt="alt-tag" />
<?php } ?></td>
for this
<?php
$approveImg = ($tdata['approve']=='true') ? 'green.png' : 'red.png';
?>
<td>
<img src="/../img/<?=$approveImg?>" alt="alt-tag"/>
</td>
Also check paths to images

Related

Do While with IF

i just want data will show if ['stt']==1
Here is the code :
<?php do { ?>
<tr>
<td><?php echo $row_daftaruser['id']; ?></td>
<td><?php echo $row_daftaruser['nama']; ?></td>
<td><?php echo $row_daftaruser['email']; ?></td>
<td><?php echo $row_daftaruser['username']; ?></td>
<td><?php echo $row_daftaruser['password']; ?></td>
<td><?php echo $row_daftaruser['alamat']; ?></td>
<td><?php echo $row_daftaruser['tgl_lahir']; ?></td>
<td><?php echo $row_daftaruser['stt']; ?></td>
</tr>
<?php } while ($row_daftaruser = mysql_fetch_assoc($daftaruser)); ?>
Can somebody help me?
you could try this:
<?php do { ?>
<?php if($row_daftaruser['stt'] == 1): ?>
<tr>
<td><?php echo $row_daftaruser['id']; ?></td>
<td><?php echo $row_daftaruser['nama']; ?></td>
<td><?php echo $row_daftaruser['email']; ?></td>
<td><?php echo $row_daftaruser['username']; ?></td>
<td><?php echo $row_daftaruser['password']; ?></td>
<td><?php echo $row_daftaruser['alamat']; ?></td>
<td><?php echo $row_daftaruser['tgl_lahir']; ?></td>
<td><?php echo $row_daftaruser['stt']; ?></td>
</tr>
<?php endif ?>
<?php } while ($row_daftaruser = mysqli_fetch_assoc($daftaruser)); ?>
This code will only display values if stt is equal to 1.
Also, use mysqli not mysql because it mysql is obsolete.
Why do not you write the query this way?
SELECT * FROM TABLE WHERE stt = 1;

How to pause or continue Foreach php

This is my code,
<?php $i=1; foreach($xls as $xls): ?>
<tr>
<td><?php echo $i; ?></td>
<td><?php echo $xls->jenis; ?></td>
<td><?php echo $xls->user; ?></td>
<td><?php echo $xls->nama; ?></td>
<td><?php echo $xls->unit; ?></td>
<?php if (is_array($jawab) || is_object($jawab)){ ?>
<?php if(isset($jawab)) {?>
<?php $limit=0;?>
<?php foreach($jawab as $row): ?>
<td><?php echo $row['ket_jawaban']; ?></td>
<?php $limit++; if($limit==2) break; endforeach; }} ?>
</tr>
<?php $i++; endforeach; ?>
</tbody>
How do I make each print 2 lines from foreach 2nd move to the bottom line (tr)
OK, with explanation:
The above code prints like this:
But I want to print like this:
It's simple. Change the name of one of your $jawab variables in the foreach loop.
<?php foreach($jawab as $jawab): ?>
And NEVER repeat a variable name in a loop.
UPDATE:
Try to change your loop:
<?php $limit=0;?>
<?php foreach($jawab as $row): ?>
<td><?php echo $row['ket_jawaban']; ?></td>
<?php $limit++; if($limit==2) break; endforeach; }} ?>
to:
<td><?php echo $jawab[i*2]['ket_jawaban']; ?></td>
<td><?php echo $jawab[i*2-1]['ket_jawaban']; ?></td>

Loop php values from an echo in HTML

I have a little issue when I try to to loop my php values in HTML. So far this is what I tried but I have not excpected result.
If I remove the loop I only get the first entry. I would like to echo all the possibles entries from my research.
This is my code ( from an SQL request).
<html>
<table>
<tr>
<th>Name</th>
<th>Surname</th>
<th>Number</th>
<th>Adress</th>
<th>link</th>
<!--<th class="glyphicon glyphicon-pencil"></th>-->
</tr>
<tr>
<?php $rowG = oci_fetch_array($stid, OCI_RETURN_NULLS);?>
<?php foreach($array as $rowG=>$value): ?> <tr>
<td><?php echo $rowG[2]; ?></td>
<td><?php echo $rowG[1]; ?></td>
<td><?php echo $rowG[0]; ?></td>
<td><?php echo $rowG[3]?></td>
<td><?php echo "<a href='./consultation.php?Login=$rowG[2]'> Link </a>" ; ?></td>
<?php endforeach;}} ?>
</tr>
</table>
</html>
Do you know where I made my mistake ?
Thank you for your help
Edit : Finally I managed to do it by using a do{}while loop.
Thank you all for your help
RFlow
It's hard to guess what you are trying to do or even what actually happens, since I don't know what is assigned to $rowG, so I tried to hack meaning out of this from the code's errors and came up with that :
<?php
while ($rowG = oci_fetch_array($stid, OCI_RETURN_NULLS)) {
?>
<tr>
<td><?php echo $rowG[2]; ?></td>
<td><?php echo $rowG[1]; ?></td>
<td><?php echo $rowG[0]; ?></td>
<td><?php echo $rowG[3]; ?></td>
<td><?php echo ' Link '; ?></td>
</tr>
<?php
}
?>
If it doesn't work with you, you'll have to provide the informations that should have been included in your question since the begining.
This is basic iteration over query results:
while ($rowG = oci_fetch_array($stid, OCI_RETURN_NULLS)) {?>
<tr>
<td><?php echo $rowG[2]; ?></td>
<td><?php echo $rowG[1]; ?></td>
<td><?php echo $rowG[0]; ?></td>
<td><?php echo $rowG[3]?></td>
<td><?php echo "<a href='./consultation.php?Login=$rowG[2]'> Link </a>" ; ?></td>
</tr>
<?php
}
<?php foreach($array as $rowG=>$value): ?> <tr>
<td><?php echo $rowG[2]; ?></td>
<td><?php echo $rowG[1]; ?></td>
<td><?php echo $rowG[0]; ?></td>
<td><?php echo $rowG[3]?></td>
<td><?php echo "<a href='./consultation.php?Login=$rowG[2]'> Link </a>" ; ?></td>
<?php endforeach;}} ?>
Would be :
<?php foreach($rowG as $arr): ?> <tr>
<td><?php echo $arr[2]; ?></td>
<td><?php echo $arr[1]; ?></td>
<td><?php echo $arr[0]; ?></td>
<td><?php echo $arr[3]?></td>
<td><?php echo "<a href='./consultation.php?Login=$arr[2]'> Link </a>" ; ?></td>
<?php endforeach;}} ?>
Note the use of $arr instead of $rowG.
In the original code $array is not used.

Replace buttons with image in PHP code

I am trying to display images in place of buttons for various activities like Edit Record, Delete Record, Download, Save, Reset. I am able to show the image but the result is very output is looks very childish and nonprofessional. Actually images are coming on button as shown in image
But I want image to display like this
Here is the code which gives the 1st image output.
<tr style="background-color: rgb(253, 253, 183); color: rgb(42, 16, 179);font-size: 13px;" >
<td><?php echo $row->eq_application_no; ?></td>
<td><?php echo $row->eq_class; ?></td>
<td><?php echo $row->eq_name;?></td>
<td><?php echo $row->mid_name; ?></td>
<td><?php echo $row->last_name; ?></td>
<td><?php echo $row->eq_sex; ?></td>
<td><?php echo $row->father_name; ?></td>
<td><?php echo $row->eq_dob; ?></td>
<td><?php echo $row->age.",".$row->month.",".$row->day;?></td>
<td><?php echo $row->scat_id;?></td>
<td><?php echo $row->parent_cate_id;?></td>
<td><?php echo $row->no_of_transfer;?></td>
<td><?php echo $tc_case; ?></td>
<td><?php echo$row->last_school_type; ?></td>
<td><?php echo $row->eq_prv_acdmic;?></td>
<td><?php if($row->kv_tc_date=="1970-01-01"){echo "-";}else{echo $row->kv_tc_date;}?></td>
<td><?php echo $row->kv_tc_no;?></td>
<td><?php echo $row->last_class_cgpa;?></td>
<!--value="Edit"-->
<td><input type="button" id="<?php echo $row->es_enquiryid;?>" onclick="edit_record(<?php echo $row->es_enquiryid;?>)" style="background-image:url(images/edit24.png);width:24px;height:24px;"></td><td>
<!--value="Delete"-->
<input type="button" id="<?php echo $row->es_enquiryid;?>" onclick="delete_record(<?php echo $row->es_enquiryid;?>)" style="background-image:url(images/delete24.png);width:24px;height:24px;" ></td><td><?php
if($eligible=="Y")
{?><input type="checkbox" class="app" name="app[]" d="
<?php echo $row->es_enquiryid;?>" value="<?php echo $row->es_enquiryid;?>">
<?php }
else
{
echo"-";
}
?></td>
</tr>
<?php } ?>
</tbody>
</table>
<table>
<tr>
Add image directly then:
<img src="images/delete24.png" id="<?php echo $row->es_enquiryid;?>" onclick="delete_record(<?php echo $row->es_enquiryid;?>)" style="cursor:pointer;width:24px;height:24px;" />

why Cannot use object of type stdClass as array in

I am trying do pagination,which is working but dont know why my edit and delte functionality stopped working.
This is My Controller
function view($page=0){
$config = array();
$config["base_url"] = base_url() . "index.php/employee/view";
$config["total_rows"] = $this->employee_model->getTotalEmployeeCount();
$config["per_page"] =5;
$this->pagination->initialize($config);
$this->data["results"] = $this->employee_model->getEmployee($config["per_page"], $page);
$this->data["links"] = $this->pagination->create_links();
$this->data['title'] = 'Payroll System';
$this->data['message'] = $this->session->flashdata('message');
$this->load->view('employee_view', $this->data);
}
This is My Model
function getTotalEmployeeCount() {
return $this->db->count_all('user');
}
function getEmployee($limit, $start) {
$this->db->limit($limit, $start);
$this->db->select('id,firstname,lastname,presentadress,contactno,dateofjoining,email');
$qry= $this->db->get('user');
return $qry->result_array();
}
This is my view
<?php
foreach ($results as $m){
?>
<tr style="text-align:center;">
<td><?php echo $m['id'] ?></td>
<td><?php echo $m['firstname'] ?></td>
<td><?php echo $m['lastname'] ?></td>
<td><?php echo $m['dateofjoining'] ?></td>
<td><?php echo $m['presentadress'] ?></td>
<td><?php echo $m['contactno'] ?></td>
<td><?php echo $m['email'] ?></td>
<td>Edit</td>
<td>
<?php
echo anchor('employee/delete_employee/'.$m->id, 'Delete', array('onClick' => "return confirm('Are you sure you want to delete?')"));
?>
</td>
<?php
}
?>
<?php echo $this->pagination->create_links()?>
In my model if change result_array to result then it gives error of "Cannot use object of type stdClass as array in".Thats why i used result_array,But now delete and edit functionality not working.I am getting the error of "Trying to get property of non object".
Help me to end this error
If you change result from result_array in model, in view you should access those elements like this.
<td><?php echo $m->id; ?></td>
<td><?php echo $m->firstname; ?></td>
<td><?php echo $m->lastname; ?></td>
Just try like this
<td><?php echo $m->id; ?></td>
<td><?php echo $m->firstname; ?></td>
<td><?php echo $m->lastname; ?></td>
change single line in your view :
<?php
foreach ($results as $m){
?>
<tr style="text-align:center;">
<td><?php echo $m['id'] ?></td>
<td><?php echo $m['firstname'] ?></td>
<td><?php echo $m['lastname'] ?></td>
<td><?php echo $m['dateofjoining'] ?></td>
<td><?php echo $m['presentadress'] ?></td>
<td><?php echo $m['contactno'] ?></td>
<td><?php echo $m['email'] ?></td>
<td>Edit</td>
<td>
<?php
//change here ///
echo anchor('employee/delete_employee/'.$m['id'], 'Delete', array('onClick' => "return confirm('Are you sure you want to delete?')"));
?>
</td>
<?php
}
?>
<?php echo $this->pagination->create_links()?>

Categories