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>
Related
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'm newbie in this and want to show IPsuit 4 latest topic in my website that works with wordpress.
so when I used following code and sql query, php used too much memory and run many process:
function ipslatest_main()
{
$db_user = get_option('ipslatest_db_user');
$db_name = get_option('ipslatest_db_name');
$db_pass = get_option('ipslatest_db_pw');
$db_host = get_option('ipslatest_db_host');
$prefix = get_option('ipslatest_db_prefix');
$url = get_option('ipslatest_url');
$limit = get_option('ipslatest_limit');
$title = get_option('ipslatest_title');
$width = get_option('ipslatest_width');
$direction = get_option('ipslatest_direction');
$translations = array('موضوع','بازديد','پاسخ','ارسال کننده');
$db = new wpdb( $db_user, $db_pass, $db_name,$db_host );
$q = $db->get_results( 'SELECT topic_firstpost,starter_name FROM '.$prefix.'forums_topics ORDER BY tid DESC LIMIT '.$limit );
echo '<div id="ipslatest-mainTitle" style="width:'.$width.'">'.$title.$position.'</div>';
echo '<table id="ipslatestTopics" border=0 style="padding:10px;width:'.$width.'">';
echo '<tr><td class="ipslatest-row-views">'.$translations[2].'</td><td class="ipslatest-row-answers">'.$translations[1].'</td><td class="ipslatest-row-sender">'.$translations[3].'</td><td class="ipslatest-row-title">'.$translations[0].'</td> </tr>';
if (is_array($q) || is_object($q))
{
foreach ($q as $key => $row) {
$topicDetails = $db->get_row('SELECT title,tid,views,posts FROM '.$prefix.'forums_topics WHERE tid='.$row->topic_firstpost);
$userMemberID = $db->get_row('SELECT member_group_id FROM '.$prefix."core_members WHERE name='".$row->starter_name."'");
$userShowingData = $db->get_row('SELECT prefix,suffix FROM '.$prefix.'core_groups WHERE g_id='.$userMemberID->member_group_id);
echo '<tr id="ipstopic"> <td class="ipslatest-row-views-content"> <span>'.$topicDetails->views.' </span></td> <td class="ipslatest-row-answers-content"><span>'.($topicDetails->posts - 1).'</span></td> <td id="ipslatest-row-sender-content">'.$userShowingData->prefix.$row->starter_name.$userShowingData->suffix.'</td> <td class="ipsTitle"> <a rel="follow" href="'.$url.'topic/'.$topicDetails->tid.'-'.strtolower(str_replace(" ","-",$topicDetails->title)).'">'. strip_tags($topicDetails->title) .' </a> </td> </tr>';
}
}
echo '</table>';
}
of course this is part of my code but can you help me where is the problem?
I'm using php 7.0.26 and MariaDB 10.1.29.
Don't give me negative point please. I'm new in this. :(
thanks.
I am using Laravel as framework and the class simple_html_parse_DOM to parse a website .
The problem is the foreach didn't work .It just parse the first element.
I want to parse the elements in every tr :
example of the page i want to parse:
<tr>
<td class="allf">ADWYA</td>
<td>8.85</td>
<td>9.02</td>
<td>8.84</td>
<td>3256</td>
<td>29369</td>
<td><b>9.02</b></td>
<td><span class="quote_up2">0.00%</span></td>
</tr>
<tr>
<td class="allf">AETECH</td>
<td>1.19</td>
<td>1.19</td>
<td>1.19</td>
<td>1193</td>
<td>1420</td>
<td><b>1.19</b></td>
<td><span class="quote_up2">0.00%</span></td>
</tr>
<tr>
<td class="allf">AIR LIQUIDE TUNISIE</td>
<td>147.00</td>
<td>147.00</td>
<td>147.00</td>
<td>6</td>
<td>882</td>
<td><b>147.00</b></td>
<td><span class="quote_up2">0.00%</span></td>
my code:
$html = new simple_html_dom();
$html->load_file('http://www.ilboursa.com/marches/aaz.aspx');
$e = $html->find('#tabQuotes',0)->find('.alri');
$i=0;
foreach ($e as $alri) :
$Nom = $alri->children($i)->children(0)->plaintext;
$Ouverture = $alri->children($i)->children(1)->plaintext;
$Haut=$alri->children($i)->children(2)->plaintext;
$Bas=$alri->children($i)->children(3)->plaintext;
$Volumetitre =$alri->children($i)->children(4)->plaintext;
$Volumedt=$alri->children($i)->children(5)->plaintext;
$Dernier =$alri->children($i)->children(6)->plaintext;
$Variation=$alri->children($i)->children(7)->plaintext;
$cours = \App\Cours::create(array(
'Nom'=>$Nom,
'Ouverture'=>$Ouverture,
'Haut'=>$Haut,
'Bas'=>$Bas,
'Volumetitre' =>$Volumetitre,
'Volumedt'=>$Volumedt,
'Dernier'=>$Dernier,
'Variation' =>$Variation
));
$i++;
endforeach;
$e = $html->find('#tabQuotes',0)->find('.alri');
// For every table
foreach ($e as $alri)
// For every tr
foreach($alri->find('tr') as $tr) {
// array of td
$tds = $tr->find('td');
$Nom = $tds[0]->plaintext;
$Ouverture = $tds[1]->plaintext;
$Haut = $tds[2]->plaintext;
$Bas = $tds[3]->plaintext;
$Volumetitre = $tds[4]->plaintext;
$Volumedt = $tds[5]->plaintext;
$Dernier = $tds[6]->plaintext;
$Variation = $tds[7]->plaintext;
$cours = \App\Cours::create(array(
'Nom'=>$Nom,
'Ouverture'=>$Ouverture,
'Haut'=>$Haut,
'Bas'=>$Bas,
'Volumetitre' =>$Volumetitre,
'Volumedt'=>$Volumedt,
'Dernier'=>$Dernier,
'Variation' =>$Variation
));
}
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;
}
}
Ok so I have this PHP page.
Anyone able to help me add in a count of rows?
<h2>All Open Incidents</h2>
<table class="table table-striped table-bordered table-head-bordered-bottom table-condensed">
<thead>
<tr>
<th class=span1>Ticket ID</th>
<th class=span2>Title</th>
<th class=span2>Submitter</th>
<th class=span2>Owner</th>
<th class=span2>Status</th>
<th class=span1>Created</th>
<th class=span1>Modified</th>
<th class=span1>SLA</th>
</tr>
</thead>
<tbody>
<?php
$query1 = "
SELECT HD_TICKET.ID as ID,
HD_TICKET.TITLE as Title,
HD_STATUS.NAME AS Status,
HD_PRIORITY.NAME AS Priority,
HD_TICKET.CREATED as Created,
HD_TICKET.MODIFIED as Modified,
HD_TICKET.CUSTOM_FIELD_VALUE10 as SLA,
S.FULL_NAME as Submitter,
O.FULL_NAME as Owner,
HD_TICKET.CUSTOM_FIELD_VALUE0 as Type
FROM HD_TICKET
JOIN HD_STATUS ON (HD_STATUS.ID = HD_TICKET.HD_STATUS_ID)
JOIN HD_PRIORITY ON (HD_PRIORITY.ID = HD_TICKET.HD_PRIORITY_ID)
LEFT JOIN USER S ON (S.ID = HD_TICKET.SUBMITTER_ID)
LEFT JOIN USER O ON (O.ID = HD_TICKET.OWNER_ID)
WHERE (HD_TICKET.HD_QUEUE_ID = $mainQueueID) AND
(HD_STATUS.NAME like '%Open%')
ORDER BY ID DESC
";
$result1 = mysql_query($query1);
$num = mysql_num_rows($result1);
$i = 0;
while ($i < $num)
{
$ID = mysql_result($result1,$i,"ID");
$Title = mysql_result($result1,$i,"Title");
$Status = mysql_result($result1,$i,"Status");
$Type = mysql_result($result1,$i,"Type");
$Created = mysql_result($result1,$i,"Created");
$Modified = mysql_result($result1,$i,"Modified");
$Priority = mysql_result($result1,$i,"Priority");
$Owner = mysql_result($result1,$i,"Owner");
$Submitter = mysql_result($result1,$i,"Submitter");
$SLA= mysql_result($result1,$i,"SLA");
$ID = stripslashes($ID);
$Title = stripslashes($Title);
$Status = stripslashes($Status);
$Type = stripslashes($Type);
$Created = stripslashes($Created);
$Modified = stripslashes($Modified);
$Priority = stripslashes($Priority);
$Owner = stripslashes($Owner);
$Submitter = stripslashes($Submitter);
$SLA = stripslashes($SLA);
$StatusSpan="";
if ($Status=="Stalled")
{
$StatusSpan="<span class='label label-warning'>$Status</span>";
}
$PriortySpan="";
if ($Priority=="High")
{
$PriortySpan="<span class='label label-important'><i class='icon-exclamation-sign icon-white'></i>High</span>";
}
if ($Priority=="Low")
{
$PriortySpan="<span class='label'>Low</span>";
}
if ($Priority=="Medium")
{
$PriortySpan="<span class='label'>Medium</span>";
}
if ($Priority=="Critical")
{
$PriortySpan="<span class='label'><i class='icon-exclamation-sign icon-white'></i>Critical</span>";
}
echo "<tr><td><a href='http://$KaceBoxDNS/adminui/ticket.php?ID=$ID' target='_blank'>$ID</a> $StatusSpan $PriortySpan</td> \n";
echo "<td>$Title</td> \n";
echo "<td>$Submitter</td> \n";
echo "<td>$Owner</td> \n";
echo "<td>$Status</td> \n";
echo "<td>$Created</td> \n";
echo "<td>$Modified</td> \n";
echo "<td>$SLA</td> \n";
echo "</tr> \n";
$i++;
}
echo "</tbody></table> \n";
?>
So basically, I want to count the number of results (8 for instance) and display
8 Results Found
At the moment I can get it to count, but it loops and puts "8 results found" 8 times, any help would be greatly apprecaited.
:)
Assuming that the number of results is in $num, you just need to add the line outside the while ($i < $num) loop, e.g. after the table close tag:
echo "</tbody></table>\n";
echo "<p>$num results found! Woohoo!</p>";