Code:
<?php
require 'Controllers/MenuController.php';
$menuController = new MenuController();
if(isset($_POST['types']))
{
$menuTables = $menuController->CreateTypeTables($_POST['types']);
}
else
{
$menuTables = $menuController->CreateTypeTables("%");
}
$title = 'Menus';
$content = $menuController->CreateMenuDropdownList(). $menuTables;
include 'Template.php';
?>
Basically when i do it this way, my page doesnt anything, not even a echo
It doesn't even show my background pic from css
But when i exclude the function:
<?php
require 'Controllers/MenuController.php';
$menuController = new MenuController();
// if(isset($_POST['types']))
//{
// $menuTables = $menuController->CreateTypeTables($_POST['types']);
// }
// else
// {
// $menuTables = $menuController->CreateTypeTables("%");
// }
$title = 'Menus';
$content = "test";
//$menuController->CreateMenuDropdownList() . $menuTables;
include 'Template.php';
?>
it shows my background pic and the content; 'test'.
I think there is something wrong with my functions but i triple checked them
Sooooo help!
Here is the MenuController.php file;
<?php
require ("Model/MenuModel.php");
class MenuController {
function CreateMenuDropdownList(){
$menuModel = new MenuModel();
$result = "<form action = '' method = 'post' width = 200px'>
Type:
<select name = 'types' >
<option value = '%' >All</option>
".$this->CreateOptionValues($menuModel->GetMenuTypes()).
"</select>
<input type = 'submit' value = 'Search' />
</form>";
return $result;
}
function CreateOptionValues(array $types){
$result = "";
foreach ($types as $type){
$result = $result . "<option value='$type'>$type</option>";
}
return $result;
}
function CreateTypeTables($types){
$menuModel = new MenuModel();
$menuArray = $menuModel->GetItemsByType($types);
$result = "";
foreach ($menuArray as $key => $product){
$result = $result .
"
<table class = 'coffeeTable'>
<tr>
<th></th>
<th>Name: </th>
<td>$product->desc</td>
<tr>
<tr>
<th></th>
<th>Type: </th>
<td>$product->type</td>
<tr>
<tr>
<th></th>
<th>Price: </th>
<td>$product->price</td>
<tr>
<form method='post'>
<button type='submit' name='insert' value='$product->id' class='button1'>Add</button>
</form>
</table>";
}
return $result;
}
}
Related
I'm trying to create a SQL query for a Wordpress multisite. I just don't get an answer.
The multisite has an id of 2 and the table is also named 2. Can someone help my with it?
If I change wp_2_posts, wp_2_postmeta to wp_posts, wp_postmeta, then it will work but only for the multisite with id = 1. I try a lot but not correct result.
<table class="tg">
<tr>
<th colspan="4" class="tg-dqty"> <b>Vandaag: <?=$date?> <!–– automatic date ––> </b>
</th>
</tr>
<tr>
<td class="tg-apa9">Datum/Tijd</td>
<td class="tg-apa9">De klant</td>
<td class="tg-apa9">Kapper</td>
<td class="tg-apa9">Betaling</td>
</tr>
<?php
$query_res = "SELECT * FROM wp_2_posts as wp,wp_2_postmeta as wpm,wp_blogs as blg WHERE wp.ID=wpm.post_id and wpm.meta_key='_sln_booking_date' and wpm.meta_value='$date' and blg.blog_id='2'";
$results_d = $wpdb->get_results($query_res);
foreach($results_d as $resultsd)
{
$post_id = $resultsd->ID;
$first_name = get_post_meta($post_id, '_sln_booking_firstname', true);
$last_name = get_post_meta($post_id, '_sln_booking_lastname', true);
$date = get_post_meta($post_id, '_sln_booking_date', true);
$time = get_post_meta($post_id, '_sln_booking_time', true);
$services = get_post_meta($post_id, '_sln_booking_services', true);
$attendants = array();
foreach($services as $service)
{
$attendants[] = $service['attendant'];
}
$attendants = array_unique($attendants);
$attendant_names = '';
if(count($attendants) > 0)
{
$attendants = implode(',', $attendants);
$query_res = "SELECT post_title FROM `wp_2_posts`, `wp_blogs`
WHERE post_type='sln_attendant' AND ID IN ($attendants) AND blg.blog_id = '2'";
$results_a = $wpdb->get_results($query_res);
$disattendants = array();
foreach($results_a as $result)
{
$disattendants[] = $result->post_title;
}
$attendant_names = implode(',', $disattendants);
//print_r($results);
}
$status = $resultsd->post_status;
$statuses = array('sln-b-paid'=>'Betaald','sln-b-paylater'=>'Betaal later','sln-b-canceled'=>'Geannuleerd','sln-b-confirmed'=>'Bevestigd');
$classes = array('sln-b-paid'=>'tg-jsol','sln-b-paylater'=>'tg-8a9r','sln-b-canceled'=>'tg-jsolc','sln-b-confirmed'=>'tg-jsol');
?>
<tr>
<td class="<?=$classes[$status]?>">Om <?=$time?> uur<br><?=$date?></td>
<td class="<?=$classes[$status]?>"><?=$first_name?> <?=$last_name?></td>
<td class="<?=$classes[$status]?>"><?=$attendant_names?></td>
<td class="<?=$classes[$status]?>"><?=$statuses[$status]?></td>
</tr>
<?php
}
?>
</table>
hi all i am trying to display array of data in a table .but the main task is i need to display all users that are under one supervisor, they may/may not have attempted the test .i am using if else condition in controller but am getting error like
Message: Undefined index: status and Message: Undefined index:
submittimestamp
below is my code
controller:
if ($supervisor) {
$users_query="SELECT u.* ,v.value FROM usr_data u, udf_text v WHERE u.usr_id != 6 AND u.usr_id = v.usr_id " . $supervisor_condition . " GROUP BY u.usr_id";
// echo $users_query;
$user_records = $this->base_model->executeSelectQuery($users_query);
$final_dataa = [];
foreach ($user_records as $user) {
$user=(object)$user;
$user_test=" SELECT u.*,o.title,ta.*,tpr.workingtime, tpr.pass, tpr.tstamp, tpr.points, tpr.maxpoints, tm.minimum_level, tcr.mark_official,(tcr.reached_points/tcr.max_points)*100 as result,v.value,ta.submittimestamp,tcr.mark_official FROM usr_data u, object_data o,tst_tests tt,tst_active ta,tst_pass_result tpr, tst_result_cache tcr,udf_text v, tst_mark tm WHERE u.usr_id != 6 AND u.usr_id=ta.user_fi AND tt.obj_fi=o.obj_id AND v.usr_id=u.usr_id AND ta.test_fi=tt.test_id AND tt.test_id = tm.test_fi AND tcr.active_fi=ta.active_id AND tm.passed = 1 AND ta.active_id=tpr.active_fi AND tcr.active_fi=ta.active_id AND v.field_id='2' AND ta.user_fi = $user->usr_id GROUP by ta.submittimestamp";
// echo $user_test;
$tst_records=$this->base_model->executeSelectQuery($user_test);
if (count($tst_records)) {
foreach ($tst_records as $tst) {
$tst=(object)$tst;
$dta['usr_id'] = $user->usr_id;
$dta['firstname'] = $user->firstname;
$dta['matriculation'] = $user->matriculation;
$dta['approve_date'] = $this->udfTextData(1, $user->usr_id);
$dta['department'] = $user->department;
$dta['job_title'] = $this->udfTextData(6, $user->usr_id);
$dta['submittimestamp'] = $tst->submittimestamp;
$dta['test_title'] = $tst->title;
$dta['division'] = $tst->value;
$mark_official = $tst->mark_official;
if ($mark_official == "passed" || $mark_official == "Passed" || $mark_official == "PASSED") {
$result_status = '<span class="label label-primary"> Completed </span>';
$completed = TRUE;
} else {
$result_status = '<span class="label label-danger"> Failed </span>';
$failed = TRUE;
}
$dta['status'] = $result_status;
$final_dataa[] = $dta;
}
}
else{
$dta['usr_id'] = $user->usr_id;
$dta['firstname'] = $user->firstname;
$dta['matriculation'] = $user->matriculation;
$dta['approve_date'] = $this->udfTextData(1, $user->usr_id);
$dta['department'] = $user->department;
$dta['job_title'] = $this->udfTextData(6, $user->usr_id);
$dta['test_title'] = $user->title;
$dta['division'] = $user->value;
$final_dataa[] = $dta;
}
}
}
$dataa['recordss'] = $final_dataa;
$this->load->view('supervisor', $dataa);
I am using if else condition if users have test else not like that .below is my view code
view:
<h3> Skill Matrix Report Process Based Training Record in LMS </h3>
<hr>
<?php $uniq_rec = array_unique($recordss,SORT_REGULAR);
// var_dump($uniq_rec);
$uniq_name = array_unique(array_column($recordss, 'firstname'));
$uniq_test = array_unique(array_column($recordss, 'test_title'));
?>
<table class="table" id="myTable">
<thead>
<tr>
<th>Employe NO</th>
<th>Employe Name</th>
<th>Date Joined</th>
<th>division</th>
<th>department</th>
<th>jobtitle</th>
<?php
foreach ($uniq_test as $row) {
?>
<th><?php echo $row?></th>
<?php
}
?>
</tr>
</thead>
<tbody>
<?php
foreach ($uniq_rec as $row) {
$row = (object)$row;
// var_dump($row);
$date_joined_y = substr($row->approve_date,0,4);
$date_joined_m = substr($row->approve_date,4,2);
$date_joined_d = substr($row->approve_date,6,2);
$date_joined = $date_joined_d."-".$date_joined_m."-".$date_joined_y;
?>
<tr>
<td><?php echo ucfirst($row->matriculation); ?></td>
<td><?php echo $row->firstname?></td>
<td> <?php echo ucfirst($date_joined); ?></td>
<td><?php echo ucfirst($row->division); ?></td>
<td><?php echo ucfirst($row->department); ?></td>
<td><?php echo ucfirst($row->job_title); ?></td>
<?php
foreach ($uniq_test as $uniq) {;
$status = "";
foreach ($recordss as $rec) {
if($uniq == $rec['test_title'] && $rec['firstname'] == $row->firstname){
echo "<td>".$rec['status'].$rec['submittimestamp']."</td>";
$status = "true";
}
}
if($status != "true"){
echo "<td></td>";
}
$status = "";
}
?>
but the main task is i need to display all users who are attempted test or not but those users are under one Supervisor
submittimestampbut the main task is i need to display all users who are attempted test or not but those users are under one Supervisor.i am using if else condition in controller but am getting error like
Message: Undefined index: status and Message: Undefined index:
submittimestamp
I want to delete the image not only in database, but in folder too.
this is my model
public function delete($id)
{
if ($this->db->delete("np_gallery", "id = ".$id))
{
return true;
}
}
this is my controller
public function delete_image($id)
{
$this->np_gallery_model->delete($id);
$query = $this->db->get("np_gallery");
$data['records'] = $query->result();
$this->load->view('admin/gallery/gallery_listing',$data);
}
this is my view
<table class="table table-bordered">
<thead>
<tr>
<td>Sl No</td>
<td>Tag</td>
<td>Image</td>
<td>Action</td>
</tr>
</thead>
<?php
$SlNo=1;
foreach($records as $r)
{
?>
<tbody>
<tr>
<?php $image_path = base_url().'uploads';?>
<td><?php echo $SlNo++ ; ?></td>
<td><?php echo $r->tag; ?></td>
<td><img src="<?php echo $image_path; ?>/images/gallery/<?php echo $r->picture;?>" style=" width:35%; height:100px;"/></td>
<td>
</td>
</tr>
</tbody>
<?php } ?>
</table>
I succeed in deleting the data in the database, but the image in the folder are not also be deleted.
Add some extra code in your controller:
public function delete_image($id)
{
$image_path = base_url().'uploads/images/gallery/'; // your image path
// get db record from image to be deleted
$query_get_image = $this->db->get_where('np_gallery', array('id' => $id));
foreach ($query_get_image->result() as $record)
{
// delete file, if exists...
$filename = $image_path . $record->picture;
if (file_exists($filename))
{
unlink($filename);
}
// ...and continue with your code
$this->np_gallery_model->delete($id);
$query = $this->db->get("np_gallery");
$data['records'] = $query->result();
$this->load->view('admin/gallery/gallery_listing',$data);
}
}
Note: alternativelly, you can do it inside your model delete() method instead. Consider where it better fits your applicaction needs.
Try these
foreach ($query_get_image->result() as $record)
{
// delete file, if exists...
$filename = $image_path . $record->picture;
if (file_exists($filename))
{
unlink($filename);
}
// ...and continue with your code
$this->np_gallery_model->delete($id);
$query = $this->db->get("np_gallery");
$data['records'] = $query->result();
$this->load->view('admin/gallery/gallery_listing',$data);
}
I have a question. How do I do to rescue the variable $row in this function ListarGeral(). so I can use the function EditarGeral() . I tried to do, but nothing happened
here's what I tried to do:
<?php
include ('Banco.php');
Class GeralControle {
private $consulta;
private $row = array();
public function GeraloDao() {
$novaconexao = new Banco();
$this->consulta = $novaconexao->conectar();
}
public function ListarGeral() {
$this->GeraloDao();
echo '<table border="1" cellspacing="2">
<tr>
<td>ID</td>
<td>CPF</td>
</tr>';
if ($resultado = $this->consulta->query("select * from cadastro")) {
while ($this->row = $resultado->fetch_row()) {
echo '<tr>
<td>'.$this->row[0].'</td>
<td>'.$this->row[1].'</td>
</tr>';
echo $this->row[0];
}
$resultado->close();
}
echo '</table>';
}
public function EditarGeral(){
$this->ListarGeral();
echo $this->row[0];
}
}
$pessoa2 = new GeralControle();
$pessoa2->ListarGeral();
$pessoa3 = new GeralControle();
$pessoa3->EditarGeral();
Thank you!
if ($resultado = $this->consulta->query("select * from cadastro")) {
$rows = array();
while ($this->row = $resultado->fetch_row()) {
echo '<tr>
<td>'.$this->row[0].'</td>
<td>'.$this->row[1].'</td>
</tr>
';echo $this->row[0];
array_push($rows, $this->row);
}
EditarGeral($rows);
}
I have a chart and a text file that is taking in some data. I would like to organize the data I have by putting the user with the highest score on the top of the table and coloring everything in their row blue. Any idea how I could do this?
file one:
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<title>High Score</title>
</head>
<body>
form action="data.php" method="POST">
<table border="1">
<tr><td>Player Name</td><td><input type="text" name="name"</td></tr>
<tr><td>Score</td><td><input type="text" name="score"</td></tr>
<tr><td colspan="2" align="center"><input type="submit"></td></tr>
</table>
</form>
</body>
</html>
Data.php:
<?php
$name = $_POST['name'];
$score = $_POST['score'];
$DOC_ROOT = $_SERVER['DOCUMENT_ROOT'];
# $fp = fopen("$DOC_ROOT/../phpdata/highscore.txt","ab");
if(!$fp) {
echo 'Error: Cannot open file.';
exit;
}
fwrite($fp, $name."|".$score."\n");
?>
<?php
$DOC_ROOT = $_SERVER['DOCUMENT_ROOT'];
$players = file("$DOC_ROOT/../phpdata/highscore.txt");
echo "<table border='2'>";
echo "<tr> <td>Name</td> <td>Score</td> </tr>";
for($i = 0; $i < sizeof($players); $i++) {
list($name,$score) = explode('|', $players[$i]);
echo '<tr><td>'.$name.'</td><td>'.$score.'</td></tr>';
}
echo '</table>';
?>
Format all players/scores into arrays like array('name' => 'Bob', 'score' => 42):
foreach ($players as &$player) {
list($name, $score) = explode('|', $player);
$player = compact('name', 'score');
}
unset($player);
Sort the array by score (PHP 5.3 syntax):
usort($players, function ($a, $b) { return $b['score'] - $a['score']; });
Output the results, setting a class on the first row:
$first = true;
foreach ($players as $player) {
$class = $first ? ' class="highlight"' : null;
$first = false;
printf('<tr%s><td>%s</td><td>%s</td></tr>', $class, htmlspecialchars($player['name']), htmlspecialchars($player['score']));
}
Now highlight that class using CSS (or do it directly in the HTML, or whatever else you want to do).