Select the opposite of the union data - javascript

I had product, vendor, vendor's available day and booking tables. Currently, my search function only can search through vendor available day, but not search through booking table. I used left joins between vendor and vendor available day and compare with the selected day, time and hour. The search result works. How do I search through booking table?
Product Table
id | vendor_id | title | description
Vendor Table
id | name
Vendor Available Table
id | vendor_id | d_day | d_start_hour | d_start_minute | d_end_hour | d_end_minute
Booking Table
id | vendor_id | d_date | d_day | d_start_hour | _start_minute
Below is how I select product based on the selected day, start_hour and start_minute:
SELECT * FROM product
LEFT JOIN ( SELECT * FROM vendor GROUP BY id ) vendor
ON vendor.id = product.vendor_id
LEFT JOIN ( SELECT * FROM vendor_available GROUP BY id) vendor_available
ON vendor_available.vendor_id = product.vendor_id
WHERE ( d_day = '4'
AND (CONCAT(d_start_hour, '.' , d_start_minute) + 0.0) <= '12.15'
AND (CONCAT(d_end_hour, '.', d_end_minute) + 0.0) >= '12.15')
4 is the selected day and 12.15 is the selected hour and selected minute on the client side.
When the user selects 12.15 which is 12.15pm, the query will check which product is available between the vendor available time.
How do I use opposite union with booking table, so that the product which already booked doesn't display to users?

When using LEFT JOIN tbl, it is normal to add this to the WHERE clause (not the ON clause)
AND tbl.id IS NULL
This says that you want to return results only when the is no row in tbl.

Related

Use Javascript to Scrape table by selecting some other elements and clicking on button

I'm working with financial data and i want to scrape data from this site web using javascript and add the sript.js to my index.html file (https://www.sikafinance.com/marches/historiques?s=BRVMAG).
I want to scrape the data of a table from above site that takes four arguments
•Ticker who is BRVMAG in the minimal example
•dlPeriod
•datefrom
•dateto
And finally click on the button
btcChange ="OK".
After trying the code below with R I get the table but how can a achieve the same script with fetch?
I would like to be able to get the other tables when I change the start and end date using now javascript in Visual Studio Code.
Since yersterday i'm looking for a reponse searching every here but now result.
Does anyone have any idea how to recover the whole table and return table in of html?
The bottom images show what I noticed when i inspected their site.
I think either the whole table is available and it does a filter for the dates(gap between dates must not exceed 3 months)
library(httr)
library(rvest)
first_date<-as.Date("2022-02-01")
end_date <- as.Date("2022-03-29")
query_params <- list(dlPeriod = "Journalière",
datefrom = first_date,
dateto = end_date,
btnChange = "OK")
parameter_response <- GET("https://www.sikafinance.com/marches/historiques?s=BRVMAG", query_params)
parameter_response1<- httr::content(parameter_response, as = "text", encoding = "UTF-8")
parameter_response2 <- read_html(parameter_response1)%>%
html_node('#tblhistos')%>%
html_table()
parameter_response2
# Date Clôture `Plus bas` `Plus haut` Ouverture `Volume Titres` `Volume FCFA` `Variation %`
# <chr> <chr> <chr> <chr> <chr> <chr> <int> <chr>
# 1 29/04/2022 312,09 312,09 312,09 312,09 - 0 2,53%
# 2 28/04/2022 304,38 304,38 304,38 304,38 - 0 0,00%
# 3 27/04/2022 304,38 304,38 304,38 304,38 - 0 2,69%
# 4 26/04/2022 296,42 296,42 296,42 296,42 - 0 0,81%
# 5 25/04/2022 294,05 294,05 294,05 294,05 - 0 1,34%
# 6 22/04/2022 290,17 290,17 290,17 290,17 - 0 0,36%

How can I read the checked state of a checkbox within the cell of a dynamically created HTML table

I am using JS to determine the checked state of checkboxes which are contained within cells of a table which has been loaded dynamically into a web page.
The page comprises 2 fieldsets:-
+-SelectFieldset-----------------------------+
| <param1> <param2> { Load button } |
| {Update button} |
+--------------------------------------------+
+-ResultFieldset id=resultFS-----------------+
| Ref_ID Description Ready |
| +-resultTable id=outTable----------------+ |
| | 123 chair [ ] | |
| | 167 dresser [ ] | |
| | 231 sofa [ ] | |
| | ... etc... | |
| +----------------------------------------+ |
+--------------------------------------------+
Notes "[ ]" above depicts a table cell containing an input with type = checkbox;
param1, param2 are dropdown selectors
Initially the ResultFieldset is empty; and is loaded when the "Load" button is clicked (using a JQuery post statement) after the select parameters have been specified.
$.post("../listProducts.php", {
AccName: account,
From: startDate}, function(data){
$("#resultFS").after(data);
});
Once the resultTable is displayed, the user checks the checkboxes as relevant in the table rows.
Subsequently, when the "Update" button is clicked I need to loop through each table row, read that row's Ref_ID value and then, depending on the checked status of the associated checkbox, post an Update to the specified row of a MySQL table.
The code to loop through the table is:-
$("#btnUpdate").on('click', function() {
for (var i=0, row; row = outTable.rows[i]; i++) {
var rowRef = row.cells[1].textContent;
console.log( "Ref_ID = " + rowRef);
var isChecked = 0;
if (row.cells[2].firstChild.checked = true){
isChecked = 1;
// update MySQL table using rowRef;
};
console.log( "Ref_ID = " + rowRef + " Ready = " + isChecked);
};
};
This code logs the Ref_ID values as expected but I'm unable to determine the checkbox state in any row. (The checkboxes are behaving as expected on the webpage - clicking sets & unsets them.)
Please advise on how I should code for this (using either JS or JQuery). Thanks..

Sort Columns on Angularjs DataTable

I want to sort my table columns by angular-dataTables. However, it sort the productCurrency because of 'ng-if' first then only to sort the productType. Any suitable function of dataTable can sort the table correctly? Check my output:
My Output:
|Product |
|CHN Product1|
|USD Product1|
|ABC |
|BBC |
|BBC |
|ZBC |
Expected Output:
|Product |
|ABC |
|BBC |
|BBC |
|CHN Product1|
|USD Product1|
|ZBC |
You can see it was supposed to sort product by alphabet, but it sort by currency 1st then the product type.
(Edited) PS: USD & CHN is productCurrency; Product1, ABC, BBC, ZBC is productType.
Here are my code:
ViewUserType.html
<td>
<span ng-if="ctrl.productType='ABC'" translate="ctrl.productCurrency.translateKey"> {{ctrl.productCurrency}}</span>
<span translate="ctrl.product.type.translateKey">{{ctrl.productType}}</span>
</td>
Controller.js
ctrl.dtOptions = DTOptionsBuilder.newOptions().withOption('aaSorting', [[2, 'desc'], [1, 'desc']]).withOption('pageLength', 25);

Joining recent database rows in PHP loop

Let's assume I have a MySQL structure like this...
+--------------+--------------------+-------------------+
| tdate | tuser | tvalue |
+--------------+--------------------+-------------------+
| 11:16:48 | John | 10 |
+--------------+--------------------+-------------------+
| 11:16:38 | John | 40 |
+--------------+--------------------+-------------------+
| 11:16:28 | Lisa | 50 |
+--------------+--------------------+-------------------+
| 10:16:48 | Lisa | 20 |
+--------------+--------------------+-------------------+
and a php query like this:
<?php
$username = 'test';
$sql=mysqli_query($db,"SELECT * FROM t ORDER BY tid DESC LIMIT 20");
while($row=mysqli_fetch_array($sql))
{
$tuser= $row['tuser'];
$tvalue= $row['tvalue'];
$tdate= $row['tdate'];
?>
<div id="<?php echo $tvalue; ?>" class="message_box">
<?php echo $tdate; ?> -
<?php echo $tvalue; ?> -
<?php echo $tuser; ?>
</div>
<?php
}
?>
This currently lists the mysql table by each row like this:
2016-02-22 11:16:48 - 10 - John
2016-02-22 11:16:38 - 40 - John
2016-02-22 11:16:28 - 50 - Lisa
2016-02-22 10:16:48 - 20 - Lisa
I would like to see it like this:
2016-02-22 11:16:48 - 50 - John
2016-02-22 11:16:28 - 50 - Lisa
2016-02-22 10:16:48 - 20 - Lisa
Meaning that loop would have to sum up values in cases where the new row was created within 60 seconds (for the same user).. Lisa has two rows, but since there is one hour timestamp difference it would have to be listed as usual... It would need it to update automaticaly, meaning that it would show value of 40 for John initially, but after 10 seconds when the new row would be added it would have to update to 50 accordingly. There is also the issue of MYSQL QUERY LIMIT of 20 which could break up rows that were inserted within 60 seconds and give false total value calculation.. I know it's a hard one, but does anyone has a simple solution for this?
Thanks to Asur I currently have this:
SELECT ROUND(UNIX_TIMESTAMP(tdate) DIV 60) AS time,tuser,SUM(tvalue)
FROM t
GROUP BY EXTRACT(DAY_HOUR FROM tdate),tuser
ORDER BY tid DESC
LIMIT 20;
but the problem is that if the last database row is JOHN, he will not be listed out last if there is already one John row above that in the same hour..
IF I HAVE:
JOHN 10
GEORGE 10
GEORGE 10
JOHN 10
It will list:
JOHN 20
GEORGE 20
And it should be the other way arround, where the last row counts:
GEORGE 20
JOHN 20
I would recommend you to do it directly in the sql query as follows:
SELECT ROUND(UNIX_TIMESTAMP(tdate) DIV 60) AS time,tuser,SUM(tvalue)
FROM t
GROUP BY time,tuser
ORDER BY tid DESC
LIMIT 20;
This is long way better in terms of optimization and spent time.
replace this query:
SELECT * FROM t ORDER BY tid DESC LIMIT 20
with this:
SELECT tdate , sum(tvalue), tuser FROM t
group by tuser, DATE_FORMAT(tdate , '%Y-%m-%d %h:%i')
ORDER BY tid DESC LIMIT 20

How to get name of the dropdown selected item in jquery?

If i have the bookd_ids and book_titles as follows in the database:
id | title
---------------
1 | abc
2 | xyz
3 | pqr
I have the books dropdownlist as show below:
<%= select("books", "book_id", Book.all.collect {|b|
[ b.title, b.id ] }, {:include_blank => 'Select Book'})%>
i can get the id of the books thru query this way:
var id = $("#books_book_id").val();
How to get the abc, xyz pqr titles using jquery?
var text = $("#books_book_id option:selected").text();
Have put some space between :selected
var value = jQuery("#edit-system-name :selected").text();

Categories