switch ($mybb->input['action'])
{
case 'ranks':
$ranks = '';
$rank['image'] = htmlspecialchars_uni($rank['image']);
$rank['name'] = htmlspecialchars_uni($rank['name']);
$query = $db->simple_select('myachievements_ranks', '*', '', array('order_dir' => 'desc', 'order_by' => 'level'));
while ($rank = $db->fetch_array($query))
{
$bgcolor = alt_trow();
$required = '';
$rank['image'] = htmlspecialchars_uni($rank['image']);
$rank['name'] = htmlspecialchars_uni($rank['name']);
$rank['description'] = nl2br(htmlspecialchars_uni($rank['description']));
if ($rank['achievements_apid'] > 0)
{
// get achievement name
$query2 = $db->simple_select('myachievements_numposts', 'numposts,image,name,cat', 'apid='.intval($rank['achievements_apid']));
$achievement = $db->fetch_array($query2);
$achievement['numposts'] = ($mybb->user['postnum'] *100) /$achievement['numposts'] ;
if ($achievement['numposts'] > 100)
{
$achievement['pneed'] = 100;
}else{
$achievement['pneed'] = $achievement['numposts'];
}
if (strlen($achievement['pneed']) > 4)
$achievement['pneed'] = substr($achievement['pneed'], 0, 4);
$required .= '<div class="rankprogress d-flex flex-row align-items-center overflow-hidden relative"><div class="profile-yos rounded ml-3 text-center flex-shrink-0 flex-grow-0 yos-'.htmlspecialchars_uni($achievement['cat']).'" data-toggle="tooltip" data-placement="top" title="" data-original-title="'.htmlspecialchars_uni($achievement['name']).'"><i class="far fa-'.htmlspecialchars_uni($achievement['image']).'"></i></div>'.htmlspecialchars_uni($achievement['pneed']).'%<div class="ggprogress" style="width: '.htmlspecialchars_uni($achievement['pneed']).'%;"></div></div>';
}
if ($rank['achievements_aaid'] > 0)
{
// get achievement name
$query2 = $db->simple_select('myachievements_activity', 'time,image,name,cat', 'aaid='.intval($rank['achievements_aaid']));
$achievement = $db->fetch_array($query2);
$achievement['time'] = ($mybb->user['timeonline'] *100) /$achievement['time'] ;
if ($achievement['time'] > 100)
{
$achievement['ttneed'] = 100;
}else{
$achievement['ttneed'] = $achievement['time'];
}
if (strlen($achievement['ttneed']) > 4)
$achievement['ttneed'] = substr($achievement['ttneed'], 0, 4);
$required .= '<div class="rankprogress d-flex flex-row align-items-center overflow-hidden relative"><div class="profile-yos rounded ml-3 text-center flex-shrink-0 flex-grow-0 yos-'.htmlspecialchars_uni($achievement['cat']).'" data-toggle="tooltip" data-placement="top" title="" data-original-title="'.htmlspecialchars_uni($achievement['name']).'"><i class="far fa-'.htmlspecialchars_uni($achievement['image']).'"></i></div>'.htmlspecialchars_uni($achievement['ttneed']).'%<div class="ggprogress" style="width: '.htmlspecialchars_uni($achievement['ttneed']).'%;"></div></div>';
}
if ($rank['achievements_acid'] > 0)
{
// get achievement name
$query2 = $db->simple_select('myachievements_custom', 'image,name,cat', 'acid='.intval($rank['achievements_acid']));
$achievement = $db->fetch_array($query2);
$required .= '<div class="profile-yos rounded ml-3 text-center flex-shrink-0 flex-grow-0 yos-'.htmlspecialchars_uni($achievement['cat']).'" data-toggle="tooltip" data-placement="top" title="" data-original-title="'.htmlspecialchars_uni($achievement['name']).'"><i class="far fa-'.htmlspecialchars_uni($achievement['image']).'"></i></div>';
}
if ($rank['achievements_apoid'] > 0)
{
// get achievement name
$query2 = $db->simple_select('myachievements_points', 'points,image,name,cat', 'apoid='.intval($rank['achievements_apoid']));
$achievement = $db->fetch_array($query2);
$achievement['points'] = ($mybb->user['newpoints'] *100) /$achievement['points'] ;
if ($achievement['points'] > 100)
{
$achievement['npneed'] = 100;
}else{
$achievement['npneed'] = $achievement['points'];
}
if (strlen($achievement['npneed']) > 4)
$achievement['npneed'] = substr($achievement['npneed'], 0, 4);
$required .= '<div class="rankprogress d-flex flex-row align-items-center overflow-hidden relative"><div class="profile-yos rounded ml-3 text-center flex-shrink-0 flex-grow-0 yos-'.htmlspecialchars_uni($achievement['cat']).'" data-toggle="tooltip" data-placement="top" title="" data-original-title="'.htmlspecialchars_uni($achievement['name']).'"><i class="far fa-'.htmlspecialchars_uni($achievement['image']).'"></i></div>'.htmlspecialchars_uni($achievement['npneed']).'%<div class="ggprogress" style="width: '.htmlspecialchars_uni($achievement['npneed']).'%;"></div></div>';
}
eval("\$myachievements = \"".$templates->get("myachievements_ranks")."\";");
break;
}
$totalprogress = ($achievement['pneed'] + $achievement['ttneed'] + $achievement['npneed']) /3;`
I want to calculate following values
$totalprogress = ($achievement['pneed'] + $achievement['ttneed'] + $achievement['npneed']) /3;
But whole variable is not giving values
Related
I am creating nested comment system with reply. comments goes longer and longer in page that is why I wanted to toggle replies.
I already do that auto adding class margins etc.
I have problem with displaying button, show replies button displays under all comments which has parent-id 0, even if it doesn't have the replies.
because of this :
if($parent_id == 0){
$marginleft = 0;
$adclass = "parent";
$adbtn = '<button type="button" class="btn btn-primary btn-xs show_reply">show replies</button>';
}else{
$marginleft = $marginleft + 15;
$adclass = "child";
$adbtn = "";
}
Which is working correct way for the class and margin etc.
Here is the php code :
$post_id = intval($_POST["comment_post_id"]);
$parent = intval('0');
$active = 'Y';
$sth = $pdo->prepare(
"SELECT * FROM comments
JOIN profiles ON comments.com_uid = profiles.ik_uid
WHERE comments.comment_post_id = ?
AND comments.comment_parent_id = ?
AND comments.active = ? ORDER BY comment_id DESC
");
$sth->execute([$post_id, $parent, $active]);
$count = $sth->rowCount();
$output = '';
if($count > 0){
while($row = $sth->fetch()){
if($row['ik_img'] !== ''){
$image = explode('.',$row['ik_img']);
$ik_img = $image[0].".webp";
$ik = $row['ik_img'];
}else{
$ik_img = 'avatar.jpg';
$ik = 'avatar.jpg';
}
if($row['comment_parent_id'] !== $row['comment_id']){
$adclass = "parent";
$adbtn = '<button type="button" class="btn btn-primary btn-xs show_reply">show replies</button>';
}else{
$adclass = "child";
$adbtn = "";
}
$output .= '
<div class="form-group border-bottom '.$adclass.'">
<div class="row">
<div class="col-12"><b>'.htmlspecialchars(ucfirst($row["comment_sender_name"])).'</b> said!</div>
<div class="row">
<div class="col-2 stimg">
<picture>
<source type="image/webp" srcset="uploads/small/'.$ik_img.'">
<img src="uploads/small/'.$ik.'" alt="'.htmlspecialchars($row['comment_sender_name']).'" class="img-fluid">
</picture>
</div>
<div class="col-10 sttext">'.htmlspecialchars($row['comment']).'</div>
</div>
<div class="col-12 sttime">'.htmlspecialchars($row["comment_date"]).'
<button type="button" class="btn btn-primary btn-xs reply" id="'.intval($row["comment_id"]).'">Reply <i class="fas fa-share"></i></button>
</div>
<div class="col-12">'.$adbtn.'</div>
</div>
</div>
';
$output .= get_comments($pdo, intval($row["comment_id"]), intval($row["comment_post_id"]));
}
}
echo $output;
function get_comments($pdo, $parent_id = 0,$post_id, $active = 'Y', $marginleft = 0){
$stmt = $pdo->prepare(
"SELECT * FROM comments
JOIN profiles ON comments.com_uid = profiles.ik_uid
WHERE comments.comment_post_id = ?
AND comments.comment_parent_id = ?
AND comments.active = ? ORDER BY comment_id DESC
");
$stmt->execute([$post_id, $parent_id, $active]);
$count = $stmt->rowCount();
$output = '';
if($count > 0){
if($parent_id == 0){
$marginleft = 0;
$adclass = "parent";
$adbtn = '<button type="button" class="btn btn-primary btn-xs show_reply">show replies</button>';
}else{
$marginleft = $marginleft + 15;
$adclass = "child";
$adbtn = "";
}
while($row = $stmt->fetch()){
if($row['ik_img'] !== ''){
$image = explode('.',$row['ik_img']);
$ik_img = $image[0].".webp";
$ik = $row['ik_img'];
}else{
$ik_img = 'avatar.jpg';
$ik = 'avatar.jpg';
}
$output .= '
<div class="form-group border-bottom '.$adclass.'" style="padding-left:'.$marginleft.'px;">
<div class="row">
<div class="col-12"><b>'.htmlspecialchars(ucfirst($row["comment_sender_name"])).'</b> said!</div>
<div class="row">
<div class="col-2 stimg">
<picture>
<source srcset="uploads/small/'.$ik_img.'" type="image/webp">
<img src="uploads/small/'.$ik.'" alt="'.htmlspecialchars($row['comment_sender_name']).'" class="img-fluid">
</picture>
</div>
<div class="col-10 sttext">'.htmlspecialchars($row['comment']).'</div>
</div>
<div class="col-12 sttime">'.htmlspecialchars($row["comment_date"]).'
<button type="button" class="btn btn-primary btn-xs reply" id="'.intval($row["comment_id"]).'">Reply <i class="fas fa-share"></i></button>
</div>
<div class="col-12">'.$adbtn.'</div>
</div>
</div>
';
$output .= get_comments($pdo, intval($row["comment_id"]), $marginleft);
}
}
return $output;
}
Database setup :
Solved I used multilevel recursive function (Like a multilevel menu) it works fine.
First of all I've saw few mistakes in your code:
Your code makes too many requests to your database - for each comment you will make a new request your database to get it's sub comments - soon this will cause slow load speed of your pages
Your database structure doesn't use indexes - with many records this will cause slow requests to this table
Your html code is not good
Database structure for my example:
CREATE TABLE `comments` (
`comment_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`com_uid` int(10) unsigned DEFAULT NULL,
`comment_parent_id` int(10) unsigned DEFAULT NULL,
`comment_post_id` int(10) unsigned NOT NULL,
`comment` varchar(200) DEFAULT NULL,
`comment_sender_name` varchar(40) DEFAULT NULL,
`active` enum('Y','N') NOT NULL DEFAULT 'Y',
`comment_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`comment_id`),
KEY `com_uid` (`com_uid`),
KEY `comment_parent_id` (`comment_parent_id`),
KEY `comment_post_id` (`comment_post_id`),
KEY `active` (`active`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
PHP Code to generate the html:
$query = '
SELECT
*
FROM
comments
LEFT JOIN
profiles ON (comments.com_uid = profiles.ik_uid)
WHERE
comments.comment_post_id = :post_id AND
comments.active = :active
ORDER BY
comment_date ASC
';
$statement = $pdo->prepare($query);
$statement->execute([':post_id' => $post_id, ':active' => 'Y']);
$count = $statement->rowCount();
$comments = $statement->fetchAll(PDO::FETCH_ASSOC);
$comments = buildNestedComments($comments);
$html = getCommentsHtml($comments);
function getArrayWithKeys($array, $key)
{
$result = [];
foreach ($array as $value) {
$result[$value[$key]] = $value;
}
return $result;
}
function buildNestedComments($comments)
{
$comments = getArrayWithKeys($comments, 'comment_id');
$nestedComments = [];
foreach ($comments as &$comment) {
$parentId = (isset($comment['comment_parent_id']) && !empty($comment['comment_parent_id'])) ? (int)$comment['comment_parent_id'] : null;
if ($parentId === null) {
$nestedComments[] = &$comment;
if (!isset($comment['comments'])) {
$comment['count'] = 0;
$comment['comments'] = [];
}
} else {
if (isset($comments[$parentId])) {
if (!isset($comments[$parentId]['comments'])) {
$comments[$parentId]['count'] = 0;
$comments[$parentId]['comments'] = [];
}
$comments[$parentId]['count']++;
$comments[$parentId]['comments'][] = &$comment;
}
}
}
return $nestedComments;
}
function getCommentsHtml($comments)
{
$html = '';
foreach ($comments as $comment) {
if (
isset($comment['ik_img']) &&
!empty($comment['ik_img'])
) {
$image = explode('.',$comment['ik_img']);
$ik_img = $image[0] . '.webp';
$ik = $comment['ik_img'];
} else {
$ik_img = 'avatar.jpg';
$ik = 'avatar.jpg';
}
$class = (isset($comment['comment_parent_id']) && !empty($comment['comment_parent_id'])) ? 'comment-' . $comment['comment_id'] . ' comment-parent-' . $comment['comment_parent_id'] : 'comment-' . $comment['comment_id'];
$button = '';
$subCommentsHtml = '';
if (
isset($comment['comments']) &&
!empty($comment['comments'])
) {
$button = '<button type="button" class="btn btn-primary btn-xs show_reply">show replies</button>';
$subCommentsHtml = getCommentsHtml($comment['comments']);
}
$html .= '<div class="form-group border-bottom '.$class.'">
<div class="row">
<div class="col-12"><b>' . htmlspecialchars(ucfirst($comment["comment_sender_name"])) . '</b> said!</div>
<div class="row">
<div class="col-2 stimg">
<picture>
<source type="image/webp" srcset="uploads/small/' . $ik_img . '">
<img src="uploads/small/' . $ik . '" alt="'.htmlspecialchars($comment['comment_sender_name']).'" class="img-fluid">
</picture>
</div>
<div class="col-10 sttext">' . htmlspecialchars($comment['comment']) . '</div>
</div>
<div class="col-12 sttime">' . htmlspecialchars($comment["comment_date"]) . '
<button type="button" class="btn btn-primary btn-xs reply" id="' . intval($comment["comment_id"]) . '">Reply <i class="fas fa-share"></i></button>
</div>
<div class="col-12">' . $button . '</div>
<div class="sub-comments">' . $subCommentsHtml . '</div>
</div>
</div>';
}
return $html;
}
As you can see in my example I'm getting all comments at once and after that I've made few things:
Getting the comments as associative array with comment_id as key in getArrayWithKeys function
Getting a nested associative array with parent comments and all of their sub comments are in comments key of the array in buildNestedComments function
Getting the html for all of these comments where sub comments are nested in div with class sub-comments for easier management with javascript
Then you will be able to use a little css and javascript to style this html and to show/hide sub comments.
Also you have to think about few points:
Amount of comments - if there are a lot of comments maybe it will be better to load first 10-20 comments
Lazy load of comments - first load all parent comments and then load their sub comments
You said,
"I have problem with displaying button, show replies button displays under all
comments which has parent-id 0, even if it doesn't have the replies.".
I think you can achiave it with sql query - you can calculate column replies_count with sub query. With that info you can modifie php code to draw
Show replies (replies_count) btn if they exist.
This would be a query:
SELECT *,
(
select count(*)
from comments cc
where cc.comment_parent_id = c.id
) replies_count
FROM comments c
JOIN profiles ON c.com_uid = profiles.ik_uid
WHERE c.comment_post_id = ?
AND c.comment_parent_id = ?
AND c.active = ? ORDER BY comment_id DESC
And then, in PHP you just use it like this:
if( $row['replies_count'] > 0 ) {
// draw btn
}
I have integrated the PHP SDK from Github: https://github.com/evernote/evernote-cloud-sdk-php
I have managed to connect a Premium account using Developer Token. It works a treat.
However, when I try to access more accounts, I get an error. Here is my code
<pre>
require_once '../libs/evernote/src/autoload.php';
require_once('../libs/mysql.class.php');
require_once('../libs/debug.php');
require_once('../libs/functions.php');
session_start();
//Siren is the search term
$gMysql = new MySQL_Class(array("host"=>"localhost","user"=>"horscote","password"=>"feO#6i77","dbname"=>"horscote"));
$gMysql->connect();
$siren = $_POST['id'];
//if logged user - saved as viewed
$sqlViewed = 'SELECT evernoteSync FROM company WHERE SIREN='.$siren;
$isSync = $gMysql->queryValue($sqlViewed);
$gMysql->close();
if($isSync==1)
{
$gMysql->connect();
//get all admin evernotes
$evernotes = $gMysql->queryList('SELECT * FROM evernote_users e inner join users u on u.id=e.userid WHERE evernote=1 ORDER BY e.ID');
$maintable = '';
foreach($evernotes as $evernote)
{
//var_dump($evernote);
$token = $evernote['token'];
$sandbox = false;
$china = false;
$client = new \Evernote\Client($token, $sandbox, null, null, $china);
$search = new \Evernote\Model\Search($siren);
$notebook = new \Evernote\Model\Notebook();
//$notebook->guid = $evernote['notebook_guid'];
//$scope = \Evernote\Client::SEARCH_SCOPE_ALL;
//$order = \Evernote\Client::SORT_ORDER_REVERSE | \Evernote\Client::SORT_ORDER_RECENTLY_CREATED;
//var_dump($notebook);
$maxResult = 5;
$results = $client->findNotesWithSearch($search, $notebook, $scope, $order, $maxResult);
//var_dump($results);
$table = '<div class="panel-group" id="accordionEvernote" role="tablist" aria-multiselectable="true" style="margin-top:10px">';
$i=0;
foreach ($results as $result) {
$noteGuid = $result->guid;
$note = $client->getNote($noteGuid);
$in = '';
if($i==0)
{
$in = ' in';
$plusMinus = '<i class="more-less fa fa-chevron-right"></i>';
}
else
{
$plusMinus = '<i class="more-less fa fa-chevron-right"></i>';
}
$advancedClient = new \Evernote\AdvancedClient($token, $sandbox);
$noteStore = $advancedClient->getNoteStore();
$userStore = $advancedClient->getUserStore();
$userInfo = $userStore->getPublicUserInfo($evernote['username']);
$completeNote = $noteStore->getNote($token,$noteGuid,TRUE,TRUE,TRUE,TRUE);
$resources = $completeNote->resources;
$sResources = '';
foreach($resources as $res)
{
$resource = $noteStore->getResource($token, $res->guid, true, true, true, true);
$fileContent = $res->data->body;
$fileType = $res->mime;
$fileName = $res->attributes->filename;
$resGuid = $res->guid; // example GUID
$resUrl = $userInfo->webApiUrlPrefix . 'res/' . $resGuid;
$attribute = $noteStore->getResourceAttributes($token, $res->guid);
$fileName = $attribute->fileName;
$sResources .= '
<div class="col-xs-10 col-sm-4 col-md-2">
<div class="thumbnail" style="text-align:center">
<i class="fa fa-file-text" aria-hidden="true" style="font-size:40px;color:#F05F40"></i>
<div class="caption">
<a tatget="_blank" href="'.$resUrl.'" style="font-size:10px">'.$fileName.'</a>
</div>
</div>
</div>';
}
$tags = $noteStore->getNoteTagNames($token,$noteGuid);
$created = date('d/m/Y',$completeNote->created/1000);
$updated = date('d/m/Y',$completeNote->updated/1000);
$hashTags = '';
foreach($tags as $tag)
{
$hashTags .='<span class="label label-primary" style="margin-right:5px"> <i class="fa fa-tag" aria-hidden="true"></i> '.$tag.'</span>';
}
$table .='<div class="panel panel-default">
<div class="panel-heading" role="tab" id="heading'.$note->guid.'">
<h4 class="panel-title" style="font-size:12px">
<a role="button" data-toggle="collapse" data-parent="#accordionEvernote" href="#collapse'.$note->guid.'" aria-expanded="true" aria-controls="collapse'.$note->guid.'">
'.$plusMinus.'
'.$note->title.' - Crée le '.$created.' par '.$evernote['firstName'].' - Modifié le '.$updated.'</i>
</a>
</h4>
</div>
<div id="collapse'.$note->guid.'" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading'.$note->guid.'">
<div class="panel-body">
<div id="ntD'.$note->guid.'">
<div style="margin-bottom:10px">'.$hashTags.'</div>
<div style="margin-bottom:10px" id="resources" class="row">'.$sResources.'</div>
'.$note->content.'
</div>
</div>
</div>
</div>';
$i++;
}
$maintable .=$table;
}
$gMysql->close();
if(isset($noteGuid) && !empty($noteGuid))
{
echo '<div style="text-align:justify">'.$maintable.'</div>';
}
else
{
$table = 'Aucune note trouvée pour cette société.';
echo $table;
}
}
else
{
$table = '<div style="text-align:center"><button class="btn btn-success btn-lg" onclick="sync('.$siren.')"> Syncroniser</button></div>';
echo $table;
}
</pre>
Any idea if all the accounts need to be premium? The premium account works but the others don't.
I have a project in this i am stuck because i want to search by industry, educational level, Areas of Experience but it does not act in the way i want to do. I have a dropdown list named industry after selecting industry the educational level, Areas of Experience comes in a checkbox. After selecting the box i want to search and display the result. My Search controller is
public function searchProfessionals (Request $request)
{
$industry = $request->input('industry');
$educationLevels = $request->input('educationLevels');
$areasOfExperiences = $request->input('areasOfExperiences');
$startPrice = $request->input('start_price');
$endPrice = $request->input('end_price');
$meetingType = $request->input('meeting_type');
if ($meetingType == 1) {
$type = [1, 1];
} elseif ($meetingType == 2) {
$type = [2, 2];
} elseif ($meetingType === 3) {
$type = [1, 2];
} else {
$type = [1, 2];
}
$userMeetings = array();
$userRoles = array();
$users = array();
$showUsers = array();
$userHourRates = array();
$userIndus = UserIndustry::where('industry_id', $industry)->get();
$userDegrees = UserDegree::where('degree_id', $educationLevels)->get();
$userAreaOfExperiences = UserAreaOfExperience::where('area_of_experience_id', $areasOfExperiences)->get();
if (!empty($userIndus)) {
foreach ($userIndus as $userInd) {
if (!empty($userDegrees)) {
foreach ($userDegrees as $userDegree) {
if (!empty($userAreaOfExperiences)) {
foreach ($userAreaOfExperiences as $userAreaOfExperience) {
$userHourRates[] = UserTime::where('user_id', $userAreaOfExperience->user_id)->whereBetween('hour_rate', [$startPrice, $endPrice])->first();
}
}
$userHourRates[] = UserTime::where('user_id', $userDegree->user_id)->whereBetween('hour_rate', [$startPrice, $endPrice])->first();
}
}
$userHourRates[] = UserTime::where('user_id', $userInd->user_id)->whereBetween('hour_rate', [$startPrice, $endPrice])->first();
}
My blade template is
#extends ('frontends.layouts.app')
#section ('main')
<div id="content-block" class="margin-top-140">
<div class="container-fluid block custom-container">
<h3 class="block-title">Browse Professionals</h3>
<div class="block-subtitle"><span>Connect</span> <span>Learn</span> <span>Inspire</span> <span>Thrive</span> </div>
<div class="row">
{{--<form action="" method="post">--}}
<div class="col-md-2 left-feild">
<div class="margin-bottom-30">
<h3>Search Filters</h3>
</div>
#if(Auth::check() && Auth::user()->user_role->role_id == 1000000)
<div class="be-vidget">
<h3 class="letf-menu-article"> Looking To </h3>
<div class="creative_filds_block">
<div class="radio">
<label><input type="radio" name="lookingTo" onclick="lookingTo(2)"> Seek Advice</label>
</div>
<div class="radio">
<label><input type="radio" name="lookingTo" onclick="lookingTo(3)"> Share Advice</label>
</div>
</div>
</div>
<script>
function lookingTo(e) {
$.ajax({
type: 'POST',
url: '{{ URL::to('looking/to') }}/' + e,
success: function (result) {
$('#browse_professionals').html(result);
}
});
}
</script>
#endif
<div class="be-vidget">
<h3 class="letf-menu-article">Professionals</h3>
<div class="-creative_filds_block">
<div class="fp-panel-wrap">
<a class="toggle-btn active" onclick="open_industry()" href="#" data-target="#ul_industry" id="a_industry">Industry</a>
<ul id="ul_industry" class="fp-panel open" style="overflow:scroll; height:200px;">
#if(!empty($industries))
#foreach($industries as $industry)
<li value="{{ $industry->id }}">{{ (!empty($industry['name'])) ? $industry['name'] : '' }} </li>
#endforeach
#endif
</ul>
<script>
function industry_search(e) {
$.ajax({
type: 'POST',
url: '{{ URL::to('professionals/industry') }}/' + e,
success: function (result) {
$('#education_experience').html(result);
$('#a_industry').attr('class', 'toggle-btn');
$('#ul_industry').css('display', 'none');
$('#education_experience').css('display', 'block');
$('#eduLevel').css('display', 'block');
$('#areaExperience').css('display', 'block');
}
});
}
function open_industry() {
$('#education_experience').css('display', 'block');
$('#education_experience').css('display', 'block');
$('#eduLevel').css('display', 'none');
$('#areaExperience').css('display', 'none');
}
</script>
<div id="education_experience" style="">
<a id="a_education" class="toggle-btn" href="#" data-target="#eduLevel">Education Level</a>
<ul id="eduLevel" class="no-link fp-panel" style="overflow:scroll; height:200px;">
#if(!empty($degrees))
#foreach($degrees as $degree)
<li value="{{ $degree->id }}">{{ (!empty($degree['name'])) ? $degree['name'] : '' }}</a> </li>
#endforeach
#endif
</ul>
<a id="a_experience" class="toggle-btn" href="#" data-target="#areaExperience">Areas of Experience</a>
<ul id="areaExperience" class="no-link fp-panel" style="overflow:scroll; height:200px;">
</ul>
</div>
</div>
</div>
</div>
<div class="be-vidget">
<h3 class="letf-menu-article">Meeting Preferences</h3>
<label>Price</label>
<br> <br>
<input type="hidden" id="price_ranger" class="range-slider" value="23"/>
<label style="margin-top: 30px;">Type</label>
<div class="form-group">
<select class="form-input" id="meeting_type">
<option value="3">All</option>
<option value="1">Phone Meeting</option>
<option value="2">Web Meeting</option>
</select>
</div>
</div>
<button id="search_professionals" type="button" class="btn color-2 size-2 btn-block hover-1">Apply Filter</button>
#if(Session::has('remove_filter'))
<button type="button" class="btn btn-danger size-2 btn-block hover-1">Remove Filter</button>
#endif
<script>
var industry = '';
$('#ul_industry li').click(function() {
industry = $(this).attr('value');
// console.log(industry);
});
$("#search_professionals").click(function () {
var degrees = new Array();
$('input[name="degrees_checkbox"]:checked').each(function() {
degrees.push(this.value);
});
var experiences = new Array();
$('input[name="experiences_checkbox"]:checked').each(function() {
experiences.push(this.value);
});
var price_ranger = $("#price_ranger").val();
var price_ranger_array = price_ranger.split(",");
var start_price = price_ranger_array[0];
var end_price = price_ranger_array[1];
var meeting_type = $("#meeting_type").val();
$.ajax({
'type' : 'post',
'url' : '{{ URL::to('search/professionals') }}',
'data' : {
'industry' : industry,
'educationLevels' : degrees,
'areasOfExperiences' : experiences,
'start_price' : start_price,
'end_price' : end_price,
'meeting_type' : meeting_type
},
'success' : function (result) {
console.log(result);
$('#browse_professionals').html(result);
}
});
});
</script>
</div>
{{--</form>--}}
<div class="col-md-10">
<div id="browse_professionals" class="row _post-container_">
#if (!empty($valid_providers))
#foreach ($valid_providers as $provider)
<div class="category-1 custom-column-5">
<div class="be-post">
<figure class="ratio-4-3 be-img-block-alt">
<div class="ratio-inner" style="background-image: url('{{ !empty($provider->user_detail->avatar) ? URL::to($provider->user_detail->avatar) : '' }}')">
<img src="{{ !empty($provider->user_detail->avatar) ? URL::to($provider->user_detail->avatar) : '' }}" alt="{{ !empty($provider->username) ? URL::to($provider->username) : '' }}">
</div>
</figure>
<div class="be-post-title">{{ (!empty($provider->user_share->share)) ? str_limit($provider->user_share->share, 90) : '' }}</div>
<div class="author-post">
<span>{{ !empty($provider->user_detail->first_name) ? $provider->user_detail->first_name : '' }} {{ !empty($provider->user_detail->last_name) ? $provider->user_detail->last_name : '' }}</span>
</div>
<span>{{ (!empty($provider->user_detail->credentials)) ? str_limit($provider->user_detail->credentials, 25) : '' }}</span>
<div data-value="4" class="static-rating"></div>
<div class="info-block clearfix">
<a class="btn color-1 size-2 hover-1 pull-right" href="{{ !empty($provider->username) ? URL::to($provider->username) : '' }}">Contact</a>
<h3 class="rate"> ${{ (!empty($provider->user_time->hour_rate)) ? $provider->user_time->hour_rate : '' }} /hr</h3>
</div>
</div>
</div>
#endforeach
#endif
</div>
</div>
</div>
</div>
</div>
#endsection
please help me. I am stuck this very badly. Sorry for my bad English
The answer will be
public function searchProfessionals(Request $request)
{
$industry = $request->input('industry');
$educationLevels = $request->input('educationLevels');
$areasOfExperiences = $request->input('areasOfExperiences');
$startPrice = $request->input('start_price');
$endPrice = $request->input('end_price');
$meetingType = $request->input('meeting_type');
$userDetails = array();
$userMeetings = array();
$userRoles = array();
$users = array();
$showUsers = array();
$userHourRates = array();
$userDegrees = array();
$userIndustryArray = array();
$userExperience = array();
$userAr = array();
$data['usersDegress'] = '';
$data['usersExperience'] = '';
$intersect_array = array();
$data['userDetails'] = UserDetail::all();
$data['userTime'] = UserTime::whereBetween('hour_rate',[$startPrice,$endPrice])->get();
$userPriceArray = array();
foreach ($data['userTime'] as $price) {
foreach ($data['userDetails'] as $userDetail) {
if ($price->user_id == $userDetail->user_id) {
$userPriceArray[] = $userDetail;
}
}
}
$newArray = array();
$data['userMeeting'] = UserMeeting::where('meeting_id', $meetingType)->get();
foreach ($userPriceArray as $price) {
foreach ($data['userMeeting'] as $meet) {
if ($price->user_id == $meet->user_id) {
$newArray[] = $price;
}
}
}
if(!empty($industry)) {
$data['userIndustry'] = UserIndustry::where('industry_id',$industry)->get();
foreach ($data['userIndustry'] as $userIn){
foreach ($newArray as $new){
if($new->user_id == $userIn->user_id){
$userIndustryArray[] = $new ;
}
}
}
if(count($educationLevels) >0){
$data['usersDegress'] = UserDegree::whereIn('degree_id',$educationLevels)->get();
foreach ($data['usersDegress'] as $education ){
foreach ($userIndustryArray as $n){
if($n->user_id == $education->user_id){
$userDegrees[] = $n ;
}
}
}
}
if(count($areasOfExperiences) >0){
$data['usersExperience'] = UserAreaOfExperience::whereIn('area_of_experience_id',$areasOfExperiences)->get();
foreach ($data['usersExperience'] as $experience ){
foreach ($userIndustryArray as $ex){
if($ex->user_id == $experience->user_id){
$userExperience[] = $ex ;
}
}
}
}
}else{
$userIndustryArray = $newArray ;
}
if(count($educationLevels)> 0 && count($areasOfExperiences) >0) {
$intersect_array = array_intersect ($userDegrees,$userExperience);
$userIndustryArray =$intersect_array;
}else if(count($educationLevels) == 0 && count($areasOfExperiences) >0) {
$intersect_array = $userExperience;
$userIndustryArray =$intersect_array;
}
else if(count($educationLevels)> 0 && count($areasOfExperiences) == 0) {
$intersect_array = $userDegrees;
$userIndustryArray =$intersect_array;
}else if(count($educationLevels) == 0 && count($areasOfExperiences) == 0) {
$userIndustryArray =$userIndustryArray;
}
$string = '' ;
foreach ($userIndustryArray as $item){
$userRatingShow = Review::where('provider_id',$item->user_id)->avg('rating');
if(empty($userRatingShow)){
$userRatingShow = 0;
}
$avatar = '';
$name = '';
$user = User::find($item->user_id) ;
if(!empty($user)){
$name = $user->username ;
}
if(!empty($item->avatar )){
$avatar = url($item->avatar);
}else{
}
$userTime= UserTime::where('user_id',$item->user_id)->orderby('id','desc')->first();
if(!empty($userTime)){
$userTimeShow = $userTime->hour_rate ;
}
$bio = '';
$user_share = UserShare::where('user_id',$item->user_id)->orderby('id','desc')->first();
if(!empty($user_share)) {
$bio =str_limit($user_share->share,85);
}
$string .= '<div class="category-1 custom-column-5">
<div class="be-post">
<figure class="ratio-4-3 be-img-block-alt">
<div class="ratio-inner" style="background-image: url(' . $avatar . ')">
<img src="' . $avatar . '" alt="omg">
</div>
</figure>
<div class="be-post-title">' . $bio . '</div>
<div class="author-post">
<span>
<a href="' . url($name) . '">' .
$item->first_name . ' ' . $item->last_name . '
</a>
</span>
</div>
<span>' . $item->credentials . '</span>
</div>
<div data-value="' . $userRatingShow . '" class="static-rating"></div>
<div class="info-block clearfix">
<a class="btn color-1 size-2 hover-1 pull-right" href="' . url($name) . '">Contact</a>
<h3 class="rate">$' . $userTimeShow . '/hr</h3>
</div>
</div>
</div>
';
}
if(!empty($string)) {
return response($string);
}else{
echo '<div class="text-center margin-top-140"><h2>Sorry, no members meet your criteria.</h2></div>';
echo '<div class="text-center margin-top-50"><h2>Please revise your search.</h2></div>';
}
}
I currently pull through data from a soap feed using this PHP, is there anyway for me to have the results ordered from high to low using the data from $weekrent?
Any help would be great! Here is my PHP code:
<?php
$wsdl = "http://portal.letmc.com/PropertySearchService.asmx?WSDL";
$client = new SoapClient($wsdl, array ("trace"=>1, "exceptions"=>0));
$strClientID = "{0050-e58a-cd32-3771}";
$strBranchID = "{0004-e58a-cd32-399e}";
$strAreaID = $_GET['area'];
$nMaxResults = $_GET['perpage'];
$nRentMinimum = $_GET['minrent'];
$nRentMaximum = $_GET['maxrent'];
$nMaximumTenants = $_GET['numtennants'];
$parameters = array( "strClientID"=>$strClientID,
"strBranchID"=>$strBranchID,
"strAreaID"=>$strAreaID,
"nMaxResults"=>$nMaxResults,
"nRentMinimum"=>$nRentMinimum,
"nRentMaximum"=>$nRentMaximum,
"nMaximumTenants"=>$nMaximumTenants
);
$values = $client->SearchProperties($parameters);
if(!is_array($values->SearchPropertiesResult->PropertyInfo))
{
$values->SearchPropertiesResult->PropertyInfo = array($values->SearchPropertiesResult->PropertyInfo);
}
if($values != '')
{
foreach ($values->SearchPropertiesResult->PropertyInfo as $message)
{
$uglyid = $message->ID;
$id = $message->FriendlyID;
$mainphoto = $message->MainPhoto->PhotoUrl;
$furnished = $message->Furnished;
$addressline1 = $message->Address1;
$rooms = $message->MaxTenants;
$rent = $message->Rent;
$description = $message->Description;
$isletagreed = $message->IsLetAgreed;
$facilities = $message->Facilities->FacilityInfo;
$photos = $message->Photos->PhotoInfo;
$roomsinfo = $message->Rooms->RoomInfo;
$facilitiesstring = serialize($facilities);
$extractnumbers = ereg_replace("[^0-9]", "", $rent);
$monthrent = ($extractnumbers) / $rooms;
$monthrentrounded = number_format(($monthrent/100),2);
$weekrent = ($monthrentrounded) * 12 / 52;
$weekrentrounded = floor($weekrent * 100) / 100;
$roomsinfojson = json_encode($roomsinfo);
$facilitiesjson = json_encode($facilities);
$roomsinfodouble = (substr_count(strip_tags($roomsinfojson),"Double"));
$roomsinfosingle = (substr_count(strip_tags($roomsinfojson),"Single"));
$roomsinfobathroom = (substr_count(strip_tags($roomsinfojson),"Bathroom"));
$roomsinfoshower = (substr_count(strip_tags($roomsinfojson),"Shower"));
$facilitiesparking = (substr_count(strip_tags($facilitiesjson),"Parking"));
$facilitiesgarden = (substr_count(strip_tags($facilitiesjson),"Garden"));
$totalbathrooms = $roomsinfobathroom + $roomsinfoshower;
$totalimages = count($photos);
echo '
<div class="col-property-box col-property-box-1-3">
<div class="owl-property-box">';
$i=0; foreach ($photos as $data) { if($i==4) break; echo '<div class="property-grid-box-picture" style="background: url('. $data->PhotoUrl .') center center;"></div>'; $i++; };
echo '</div>
<div class="property-grid-box">
'. $addressline1 .'
<p class="property-grid-box-text">'. limit_words($description,19) .'...</p>
<div class="property-grid-box-price">
<div class="section group">
<div class="col col-property-box-1-2 property-grid-box-price-border-right">
<div class="property-grid-box-price-top">£'. $weekrentrounded.'pp</div> <div class="property-grid-box-price-under">Weekly</div>
</div>
<div class="col col-property-box-1-2">
<div class="property-grid-box-price-top">£'. $monthrentrounded .'pp</div> <div class="property-grid-box-price-under">Monthly</div>
</div>
</div>
</div>
<div class="property-grid-box-icon-box">
<div class="section group">
<div class="col col-1-3-border no-left-border">
<span class="property-grid-box-number-icon"><center><i class="fa fa-bed"></i></center><div class="property-grid-box-number-text">'. $rooms .'</div></span>
</div>
<div class="col col-1-3-border">
<span class="property-grid-box-number-icon"><center><i class="flaticon-shower5"></i></center><div class="property-grid-box-number-text">'. $totalbathrooms .'</div></span>
</div>
<div class="col col-1-3-border">
<span class="property-grid-box-number-icon"><center><i class="flaticon-beds12"></i></center><div class="property-grid-box-number-text">'. $totalimages .'</div></span>
</div>
</div>
</div>
</div>
</div>
';
}
}
function limit_words($string, $word_limit)
{
$words = explode(" ",$string);
return implode(" ",array_splice($words,0,$word_limit));
}
?>
you can use usort function .. so you get the sorted result
Read more on php
You can put your messages data to temporary array along with calculated weekrent and then sort desc by weekrent value with usort
if($values != '')
{
$arrayForSort = array();
foreach ($values->SearchPropertiesResult->PropertyInfo as $message) {
$rent = $message->Rent;
$rooms = $message->MaxTenants;
$extractnumbers = ereg_replace("[^0-9]", "", $rent);
$monthrent = ($extractnumbers) / $rooms;
$monthrentrounded = number_format(($monthrent/100),2);
$weekrent = ($monthrentrounded) * 12 / 52;
$arrayForSort[] = array('weekrent' => $weekrent, 'message' => $message);
}
usort($arrayForSort, function($a, $b) {
if ($a['weekrent'] == $b['weekrent']) {
return 0;
}
return ($a['weekrent'] > $b['weekrent']) ? -1 : 1;
});
foreach ($arrayForSort as $item)
{
$message = $item['message'];
// Your code here to proper process the message ...
Please take a look at the loop:
$category = $mysqli->query('SELECT * FROM category');
$divcounter = 0;
while($row = $category->fetch_assoc()) {
print '<div class="item col-xs-12 col-sm-6 col-md-3 col-lg-2">';
print '<h4><span class="glyphicon glyphicon-triangle-right" aria-hidden="true"></span> '.$row["catname"].'</h4>';
print '<div id="tvb'.$row["id"].'">';
$link = $mysqli->query("SELECT * FROM links WHERE category='{$row["id"]}'");
while($row = $link->fetch_assoc()) {
print '<li>'.$row["name"].' <span class="glyphicon glyphicon-remove text-danger" aria-hidden="true"></span></li>';
}
$link->free();
print '</div>';
print '</div>';
$divcounter++;
!($divcounter % 2) ? print '<div class="clearfix visible-sm-block"></div>' : '';
!($divcounter % 4) ? print '<div class="clearfix visible-md-block"></div>' : '';
!($divcounter % 6) ? print '<div class="clearfix visible-lg-block"></div>' : '';
}
Please advise how do I create a button that sit next to the li to delete that current listed row from db? Thanks
<span class="glyphicon glyphicon-remove text-danger" aria-hidden="true"></span>
This is the content of delete.php:
if(isset($_POST['catid']) and is_numeric($_POST['catid']))
$id=$_POST['catid'];
$query = "DELETE FROM category WHERE id=(?)";
$statement = $mysqli->prepare($query);
$statement->bind_param('i', $id);
$statement->execute();
$statement->close();
while($row = $link->fetch_assoc()) {
print '<li>delete'.$row["name"].' <span class="glyphicon glyphicon-remove text-danger" aria-hidden="true"></span></li>';
}