Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have indexed a table which is giving me result like following
A
B
C
D
E
F
H
H
A
B
I want to sort result in such a manner that I get H first everytime and then rest should be sort by asc like
H
H
A
A
B
B
C
D
so on...
I am not finding a way for this. Please help.
This depends on the search query you are using in order to get the results. You could modify your query parameter so that it matches the exact result you want to be on the top, and pass the original query in q.alt parameter, and then apply the sorting you wish to use.
Note that in order to use q.alt, you need to use dismax or edismax query parser.
$alpha = array("A","B","C","D","E","F","H","H","A","B");
$first = array("H");
$alpha =array_diff($alpha, $first);
asort($alpha);
$alpha= $first + $alpha;
Demo
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
So how to detect which string are empty in the query? I mean:
I have few WHERE clause in one query
$query = SELECT var FROM table WHERE var = '$y';
and how can I detect which "$y" has no result?
I know I can use if($y), but how can I detect which was empty?
Declare an array of your Y variables:
var $myYs =array($y1, $y2, ... $yn);
Then make a loop to count the query results of each of your Y. Then check if the count of that particular query was equal to 0, still inside the loop.
foreach ($myYs as $checkThsYnow){
$query = SELECT COUNT(var) FROM table WHERE var = '$checkThsYnow';
if ($query =0) {echo $checkThsYnow." is empty"}
}
Based on your comments additionally you need to check all combinations of your Ys.. as it is possible, that every Y brings back a result, but Y1 and Y2 AND together resulting the 0 results. Its a mathematical combination issue. Need to check all combinations..Loop in a loop in a loop..etc.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Just as the title says, I need a query to count the rows until the condition is met. Here's my setup:
partnumber
-----------
b
e
d
a
c
So if I'm going to search for partnumber = d it will sort the part number and return 4 (since d is the 4th when you sort the partnumber).
I can do this inside a loop. I'm just wondering if there is a query for this.
Thanks in advance
SELECT COUNT(*) FROM THE_TABLE WHERE partnumber <= (SELECT ID FROM THE_TABLE WHERE partnumber <= 'd');
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a problem:
C. Clark's model of urban population densities indicating that population density varies with distance from the center of the city according to the equation Dx=D0e-bx where Dx is the population density at distance x from the center. D0 is the density at the center, e is the base of the natural logarithms, and b is a natural logarithm measuring the rate of change of density with distance.
How can I write this formula in php language?
Thanks!
What I have tried:
Dx = D/(x/b*b);
But I thinks this is wrong.
Not sure what's the problem here, so here's how I got it and you can say what did I get wrong. Afterwards, you can edit your question :)
Hence:
// this should be given
$d0 = 1.22;
$b = 0.37;
function dx($x = 0) {
global $d0, $b;
return $d0 /exp($b*$x);
}
echo dx(6.74); // d_{6.74}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I get one value like "13and45" and would like to know if there is a way so I can store these values separately like
$string="13and45";
$value1=13;
$value2=45;
Do you guys know how I can manipulate the string in order to get something like what I have above?
PHP - Explode () function
This will return an array with the two values.
Example:
$array = explode ("and", $string);
Returned array with strings:
$array[0] = 13
$array[1] = 45
You can use something like intval(substr($string, 0, 2) to get the first integer and intval(substr($string, 5, 2) for the second. intval will get the integer value from a string, and substr will get the portion of the string given by ($string, index, length).
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
040, 044P, 041BL, 041W, 041PB
^^ This is the order it is coming out in by using Order By clause.
I think this is how it should appear instead:
040, 041BL, 041PB, 041W, 044P
I know similar questions must have been asked before, but I still can't figure out anything!
Edit: After X.L.Ant's comment, I realized my mistake. Therefore, simple order by clause is working for the test case given above. However, the case is still complicated if the number of digits is not always going to be 3 as GolezTrol mentioned. What should one do in that case?
Try:
SELECT string,
#num := CONVERT(string, signed) AS num_part,
Substring(Trim(LEADING '0' FROM string), Length(#num) + 1) AS rest_of_string
FROM table1
ORDER BY num_part,
rest_of_string
This way, the numbers will still be ordered by their numerical value (the leading 0s not being taken into account).
See fiddle.
try LPAD() function - but remeber that LPAD trims digits.
http://sqlfiddle.com/#!2/d7281/3/0