How to Create a: :Before for Multiple #Id

How to create a ::before for multiple #id

use :is()

:is(#ps4,#ps3)::before {
content:"OK";
}
<div id="ps4"></div>
<div id="ps3"></div>

Can an HTML element have multiple ids?

No. From the XHTML 1.0 Spec

In XML, fragment identifiers are of
type ID, and there can only be a
single attribute of type ID per
element. Therefore, in XHTML 1.0 the
id attribute is defined to be of type
ID. In order to ensure that XHTML 1.0
documents are well-structured XML
documents, XHTML 1.0 documents MUST
use the id attribute when defining
fragment identifiers on the elements
listed above. See the HTML
Compatibility Guidelines for
information on ensuring such anchors
are backward compatible when serving
XHTML documents as media type
text/html.

Use multiple IDs for divs in CSS

You have to put

#box-left a, #box-middle a, #box-right a {
text-decoration:none;
color:#000000;
}

Each value on the comma separator list is a selector on its own, it is not combined with the next elements:

#foo, .class p, #bar p:first-child a {
something;
}

is equivalent to

#foo {
something;
}

.class p {
something;
}

#bar p:first-child a {
something;
}

How to add '' and , for multiple ID in SQL Server

Here is a conceptual example for you. It will work in SQL Server 2012 onwards.

It is a three step process:

  1. Convert input string into XML.
  2. Convert XML into a relational resultset inside the CTE.
  3. Join with a DB table.

SQL

-- DDL and sample data population, start
DECLARE @tbl TABLE (ID INT IDENTITY PRIMARY KEY, Code VARCHAR(10), City VARCHAR(50));
INSERT INTO @tbl (Code, City) VALUES
('10T', 'Miami'),
('45L', 'Orlando'),
('50Z', 'Dallas'),
('70W', 'Houston');
-- DDL and sample data population, end

DECLARE @Str VARCHAR(100) = '22C,45L,50Z,105M'
, @separator CHAR(1) = ',';

DECLARE @parameter XML = TRY_CAST('<root><r><![CDATA[' +
REPLACE(@Str, @separator, ']]></r><r><![CDATA[') +
']]></r></root>' AS XML);

;WITH rs AS
(
SELECT c.value('.', 'VARCHAR(10)') AS Code
FROM @parameter.nodes('/root/r/text()') AS t(c)
)
SELECT t.*
FROM @tbl AS t INNER JOIN
rs ON t.Code = rs.Code;

Handling multiple IDs in jQuery

Yes, #id selectors combined with a multiple selector (comma) is perfectly valid in both jQuery and CSS.

However, for your example, since <script> comes before the elements, you need a document.ready handler, so it waits until the elements are in the DOM to go looking for them, like this:

<script>
$(function() {
$("#segement1,#segement2,#segement3").hide()
});
</script>

<div id="segement1"></div>
<div id="segement2"></div>
<div id="segement3"></div>

Getting result from db for multiple id for different ranges

You can simply use a combination of logical operators AND/OR:

SELECT id, timestamp FROM table 
WHERE (id = 2 AND
timestamp >= '2018-11-14 10:01:00' AND
timestamp <= '2018-11-14 10:02:00')
OR
(id = 3 AND
timestamp >= '2018-11-14 10:02:00' AND
timestamp <= '2018-11-14 10:04:00')

A neater way of writing it could be using BETWEEN .. AND ..:

SELECT id, timestamp FROM table 
WHERE (id = 2 AND
timestamp BETWEEN '2018-11-14 10:01:00' AND '2018-11-14 10:02:00')
OR
(id = 3 AND
timestamp BETWEEN '2018-11-14 10:02:00' AND '2018-11-14 10:04:00')

EDIT (based on your edit): In order to build your query dynamically, you simply need to use your application code to prepare the query string (eg: in PHP, C++, Java, etc)

How to select multiple ids in CSS?

Use an attribute selector
on the id attribute:

[id^='test_id_'] { color: red; }

Description:

[attr^=value] represents an element with an attribute name of attr and whose first value is prefixed by "value".

Deal with multiple ID's in document

I've been there before: I've had to deal with applications that do weird things, where changing them to be "correct" causes more grief than just dealing with it and moving on. You know duplicate IDs are bad, I know duplicate IDs are bad; let's sort the problem. (Yes, they're bad. Yes, they shouldn't be there. Unfortunately, there they are.)

You can treat IDs just like any other attribute on an element: they're attributes, albeit special ones. Code like this will work to select all elements with the same ID: $('[id=wl-7050]').

Now, we need to bind a click event to them. We'll do the same thing as we always do:

var lis = $('[id=wl-7050]').click(function(e){
console.log(this);
});

Here's the trick, and it would happen even if these elements all had different IDs: when you're clicking in a child LI, that click event will bubble up to the parent. We'll need to shut off event propagation so we don't trigger our click event twice:

var lis = $('[id=wl-7050]').click(function(e){
e.stopPropagation();
console.log(this);
});

Now we're in business and can work to figure out which type of LI we're working with: top-level or child.

var lis = $('[id=wl-7050]').click(function(e){
e.stopPropagation();
if ($(this).children('li').length > 0) {
// Top-level LI
}
else {
// Child-level LI
}
});

That should get you where you need to be. Let's all agree to never speak of those duplicate IDs again.

MySQL select multiple id at the same time with optional id with php

You can do it with aggregation and RANK() window function.

This query:

SELECT idUser
FROM skills
WHERE idSkill IN (9, 4, 7)
GROUP BY idUser
HAVING SUM(idSkill IN (9, 4)) = 2 -- for the 2 mandatory skills

returns all the users with at least the 2 mandatory skills 9 and 4.

If you use an ORDER BY clause with LIMIT like this:

SELECT idUser
FROM skills
WHERE idSkill IN (9, 4, 7)
GROUP BY idUser
HAVING SUM(idSkill IN (9, 4)) = 2 -- for the 2 mandatory skills
ORDER BY COUNT(*) DESC
LIMIT 1

you will get from all the users with at least the 2 mandatory skills 9 and 4, only 1 user: the one with the largest number of skills (mandatory and optional).

If you want ties returned, use RANK() window function:

SELECT idUser
FROM (
SELECT idUser, RANK() OVER (ORDER BY COUNT(*) DESC) rnk
FROM skills
WHERE idSkill IN (9, 4, 7)
GROUP BY idUser
HAVING SUM(idSkill IN (9, 4)) = 2 -- for the 2 mandatory skills
) t
WHERE rnk = 1

See the demo.



Related Topics



Leave a reply



Submit