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.
Related
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 3 days ago.
Improve this question
I'm trying to find the sum of numbers by querying a database using PHP and MYSQL. I need a while loop or any other solution that can add numbers that are >= 40 from a sequence of numbers. I'm only able to make the query but don't know how to go about the rest.
$selectMARK="SELECT mark FROM resultstbl WHERE mark >= 40";
$queryMARK=mysqli_query($dbCon, $select);
$sum=0;
while($rowz=mysqli_fetch_assoc($queryMARK))
{
// need some code to add the numbers here
}
You maybe need an
$iterator = 0;
outside the loop, that you can increment inside of it.
$sum += $rowz[$iterator];
$iterator++:
Then do your condition around it by checking $rowz[$iterator] <= 40
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
I have a table "selled" which has three column id, qty, code how to sum all the values in qty column where code = X, I know how to count the number of rows in this column but I want to get the sum of the values inside these rows.
I am sorry guys i am still beginner and i really appreciate it ,This is the code i am using and it still not working
$query="SELECT SUM (qty) as sum_of_qty from selled WHERE code='$code'";
$result=mysqli_query($connection,$query);
$row=mysqli_fetch_assoc($result);
echo $row['sum_of_qty'];
Use the SUM function. Docs:
https://dev.mysql.com/doc/refman/5.7/en/group-by-functions.html#function_sum
SELECT SUM(qty) as sum_of_qty FROM selled WHERE code = x
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 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
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 8 years ago.
Improve this question
I'm trying to obtain a column name EmailId from the table named Users. But it returns only the first string and nothing else?
PHP:
$sql="SELECT EmailId FROM Users;";
$result =mysqli_query($conn,$sql);
$col=mysqli_fetch_array($result);
The database has 3 email-ids but count($col) returns only 1. Why so?
Thanks in advance.
The database has 3 email-ids but count($col) returns only 1. Why so?
Because
$col=mysqli_fetch_array($result);
only fetch the first row according to the internal pointer of the dataset, and therefore
count($col)
returns 1 because $col is an array having 1 item.