Conditional formatting on data fetched from MYSQL

I’m not an expert in PHP and I’m trying to apply conditional formatting on data fetched from wpdb. To be fair, I’m trying to create shortcode for this. My motto is to fetch values for $ previous_marks & $ current_marks from the database and change the color of $ current_marks according to if, else condition. According to condition:

  • If $ current_marks > $ previous_marks, then value of $ current_marks should be displayed in green color along with pass.png image next to the value.
  • Else value of $ current_marks should be displayed in red color along with fail.png image next to the value.

I also need help in displaying images next to $ current_marks value & I have no code for it:

Here’s how my code looks like:

    add_shortcode( 'marks_col', function () {     $  subject = $  _GET['subject'];          global $  wpdb;     $  previous_marks = $  wpdb->get_results( "SELECT prev FROM grade WHERE sub='" .$  subject. "'");     $  current_marks = $  wpdb->get_results( "SELECT current FROM grade WHERE sub='" .$  subject. "'");     if ($  previous_marks < $  current_marks) {        echo "<p style="color:green">" .$  current_marks. "</p>"; ##display pass.png next to $  current_marks value     } else {        echo "<p style="color:red">" .$  current_marks. "</p>"; ##display fail.png next to $  current_marks value     }     } ); 

$ subject is fetched from the website’s URL: www.domain.com/results?subject=biology. Currently, on using the shortcode [marks_col] on WP installation, it’s just printing ‘Array’ in red color & nothing else. Any help would be greatly appreciated.

How is readiness of instructions fetched from RAM signaled to the CPU?

In simple CPU architectures, such as the one discussed here https://youtu.be/zltgXvg6r3k?t=109, an instruction loaded from RAM is executed exactly one clock cycle after it is loaded into the instruction register.

However, I am told that in real/modern architectures it takes hundreds of clock cycles to fetch instructions from RAM (using caches in between). But that completely throws off my understanding of how things work. Could someone please outline the techniques that enable instructions ordered from RAM to get executed after some indefinite number of clock cycles in the future?

Please don’t just say e.g. "by stalling", but actually outline in terms of signals, chips, etc. how these things are organized. Thanks!

Is there a way to get all paging info for a list up front so that very large lists can be fetched in parallel?

I am using SharePoint online and SharePoint 2013+ onprem.

I have written a CSOM rest program that fetches all the items in a list and fetches list items in 5000 item batches, the maximum allowed by the list item view threshold.

Here is an example of the XML payload of the CSOM request to get one of the pages.

<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="14.0.0.0" LibraryVersion="16.0.0.0"          ApplicationName=".NET Library" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009">     <Actions>         <ObjectPath Id="10019" ObjectPathId="10018"/>         <Query Id="10020" ObjectPathId="10018">             <Query SelectAllProperties="true">                 <Properties/>             </Query>             <ChildItemQuery SelectAllProperties="true">                 <Properties>                     <Property Name="Id" ScalarProperty="true"/>                     <Property Name="DisplayName" ScalarProperty="true"/>                     <Property Name="HasUniqueRoleAssignments" ScalarProperty="true"/>                     <Property Name="File" SelectAll="true">                         <Query SelectAllProperties="false">                             <Properties/>                         </Query>                     </Property>                     <Property Name="ContentType" SelectAll="false">                         <Query SelectAllProperties="false">                             <Properties>                                 <Property Name="Name" ScalarProperty="true"/>                             </Properties>                         </Query>                     </Property>                 </Properties>             </ChildItemQuery>         </Query>     </Actions>     <ObjectPaths>         <Method Id="10018" ParentId="9" Name="GetItems">             <Parameters>                 <Parameter TypeId="{3d248d7b-fc86-40a3-aa97-02a75d69fb8a}">                     <Property Name="AllowIncrementalResults" Type="Boolean">false</Property>                     <Property Name="DatesInUtc" Type="Boolean">true</Property>                     <Property Name="FolderServerRelativePath" Type="Null"/>                     <Property Name="FolderServerRelativeUrl" Type="Null"/>                     <Property Name="ListItemCollectionPosition" TypeId="{922354eb-c56a-4d88-ad59-67496854efe1}">                         <Property Name="PagingInfo" Type="String">Paged=TRUE&amp;p_ID=6500</Property>                     </Property>                     <Property Name="ViewXml" Type="String">&lt;View Scope="RecursiveAll"&gt;&lt;RowLimit&gt;500&lt;/RowLimit&gt;&lt;/View&gt;</Property>                 </Parameter>             </Parameters>         </Method>         <Identity Id="9"                   Name="740c6a0b-85e2-48a0-a494-e0f1759d4aa7:site:2386a403-8d76-4737-b774-dabad52201e3:web:7a2f544f-e3ed-444e-8de3-178c2c9b5848:list:63029d5e-0588-4406-89f4-9b5a69ae5d81"/>     </ObjectPaths> </Request> 

Notice the Paged=TRUE&amp;p_ID=6500 is specified which means get me the next page of results starting at p_ID 6500.

So the simple algorithm to fetch all the items is this:

next_page_id = 0 while (next_page_id is not null)    get next page of list items starting at next_page_id.    if there is another page       set next_page_id to that page id.    else       set next_page_id to null. 

But the main flaw with this is that now a list with 1,000,000 items can only be fetched with a single thread. Which means that this can potentially fetch for hours and hours if a single list has millions of records in it.

To get past this, I tried to use the List.ItemCount to create a blocking collection of pages that we need to fetch. For example, if you have 150000 records in a list, create Paged=TRUE&amp;p_ID=0, Paged=TRUE&amp;p_ID=5000, and Paged=TRUE&amp;p_ID=10000 and a thread pool can grab pages to fetch until there is no more work to do.

But this isn’t correct. You will end up with incomplete lists, because the p_ID is not the “index of result.” It has some other meaning that I do fully understand.

Is there a way to do what I am trying to do?

Create a Custom menu item fetched by Product Categories and Sub Categories

So one of our clients uses an ERP in order to update the products of woocomerce in his wordpress website. The ERP is updating the database directly for everything regarding the products,categories,subcategories etc. Their only issue is that they want to create a menu item at the main menu and when they add a new category/subcategory or remove an existing to dynamically update that menu_item that will hold the product categories/sub-categories.

Is there any function that renders ALL the product categories as menus because the code I started implementing seems way an overkill.

require_once('../../../wp-config.php'); require_once('ProductToMenu.php');  global $  wp_query; global $  wpdb;  $  productToMenuHelper = new ProductToMenu();  $  activeTemplateResult = $  wpdb->get_results("SELECT * FROM `wp_options` where option_name='template'"); $  activeTemplate = $  activeTemplateResult[0]->option_value;  $  templateOptionsResult = $  wpdb->get_results("SELECT * FROM `wp_options` where option_name ='theme_mods_".$  activeTemplate."'");     $  templateOptions = $  productToMenuHelper->unserializeOption($  templateOptionsResult[0]->option_value);   $  mainMenuId = $  templateOptions["nav_menu_locations"]["top"];  $  menuItems =  $  wpdb->get_results("SELECT p.*    FROM wp_posts AS p    LEFT JOIN wp_term_relationships AS tr ON tr.object_id = p.ID   LEFT JOIN wp_term_taxonomy AS tt ON tt.term_taxonomy_id = tr.term_taxonomy_id  WHERE p.post_type = 'nav_menu_item' and tt.term_id={$  mainMenuId}"); var_dump($  menuItems); 

What Im trying to do is find the main menu from template, find all the menu items of that menu and after that get a payload of all product categories and subcategories and check if exist in the menu items payload

Depositing a letter at Orly airport to be fetched by someone else

I have a problem with an important document that needs to pass from one person to another.

Person A bringing the document transits Orly on Saturday evening (going through the public spaces, with several hours of slack time, enough to go to some airport hotel but not enough to get into some random place in Paris).

Person B gets to Orly on Sunday afternoon (and would like to just leave by plane as soon as possible, but that plane is not booked yet, and he’s not leaving without the document, because it’s his passport!).

There is no luggage deposit at Orly (and I suspect most deposit services would only return things to the person that effected the deposit, or would have some physical token that would present the same problem).

There would be no problem having the document inspected, it’s just a passport.

None of the persons have access to any prestige Air France frequent flyer services (both are traveling low-cost and regretting it).

The possibilities I see right now are:

  • Deposit with a Person C I know in Paris, who would need to meet up with Person A on a Saturday evening, and again with person B on Sunday evening, with transport costs I estimate at some 150 euros in addition to all the hours of bother inflicted on just a friend.

  • Find a hotel close to Orly that Person B can reserve a room at, where Person A would deposit the document and Person B would get it (and maybe not even sleep in the room if he can get a plane later in the evening). It would probably have to be an upscale hotel though.

  • Deposit at a lost-and-found and hope that Person B can get it out . . . no, just joking, any of the two previous solutions are better!

Is there any other way?

How do we perform groupby operation on data fetched from a database

var grouped = from a in db.Logs                          group a by a.email into g  <!-- begin snippet: js hide: false console: true babel: false -->

I am using a table having email and login_time I need to group them based on email and from that i need to get the min login time of a particular email_id for datetime.today. I use min function to find the first login. I am using 24 hr format;

I would like to know how to display the data on the website after being fetched via ajax

$  .ajax({                url: "http://bc-net/Sandbox/juandev/_api/web/lists/GetByTitle('Qlinks')/items",                method: "GET",                headers: { "Accept": "application/json; odata=verbose" },                success: function (data) {                var items = data.d.results;                      if (items.length > 0 ) {                          //This section can be used to iterate through data and show it on screen                      }                     console.log(items);                      },               error: function (data) {                   alert("Error: "+ data);              }       }); 

The console shows I have fetched the items that live on the list but I am not sure how to inject them on the website.

Send data in res.send method fetched from two collections node.js

I have two collections categories and subcategories each category have multiple subcategories. And in subcategories collection each document have a category_id field. and now i want when i am fetching data for a particular subcategory from that with category_id fetch category details here is my code i am not getting any response from ‘data.category_id‘ Here is my code

exports.TopicsBySubcategoryId = (req, res) => { Subcategory.findOne({         _id: req.params.id     })     .then(obj => {         if (obj != null && obj != '') {             console.log(obj)             console.log(obj.category_id)             Category.findOne({                 _id: obj.category_id                 }).then(data => {                     if (data != null && data != '') {                         console.log(data)                         res.send({ response: true, message: 'Data fetched successfully', data:{category : data, subcategory : obj} })                         return                     } else {                         console.log('not found')                         res.send({ response: false, message: 'Server mmmencountered some error' })                     }                 }).catch(err => {                     console.log(err)                     res.send({                          response: false,                          message: 'Server mmmencountered some error !!!'                      })                     return                 })         } else {             res.send({ response: false, message: "Server mmmencountered some error !!!" })         }     }).catch(err => {         console.log(err)         res.send({ response: false, message: 'Server encountered some error !!!' })         return }); }; 

Here is the output

{ _id: 5c398cb7d301362158004fce, Title: 'dsgds', Description: 'gdsgsgsg', Slug: 'sgdsgdsg', category_id: '5c398ac7d301362158004fcd', UserId: '5c3796cad3013606e8001f9c', updated_at: 2019-01-12T06:44:07.000Z, created_at: 2019-01-12T06:44:07.000Z } undefined not found 

obj.category_id gives nothing,