How to skip counting null or empty cells inside MySQL? [closed] - php

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 1 year ago.
Improve this question
I have this database table where one column is email and in front of that have different other columns used to store data for that email. When I use mysqli_num_rows() function it counts the empty fields as well.
How should I modify this query such that I don't get empty cells counted
<?php
$query = "SELECT * FROM user_info WHERE email='$email'";
$data = mysqli_query($connec,$query);
$total = mysqli_num_rows($data);
echo "Registered for ". $total. " Modules";
?>
Thanking in anticipation

"SELECT * FROM user_info WHERE email='$email' and UID IS NOT NULL AND SENT_DATE IS NOT NULL AND TOTAL_BOUNCE_COUNT IS NOT NULL;"
For each column for which a NULL make the record invalid, put in that syntax to exclude records that have a null from the count. Of course I just made up column names in my answer. You'd put the column names in your table in place of SENT_DATE/TOTAL_BOUNCE_COUNT/UID.

Related

php code to delete value table 2 from value of table 1 [closed]

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 1 year ago.
Improve this question
I am php beginner.
I would like to read email contain in table 1 and with the value selected deleted the corresponding email of the table 2 ?
May you provide me some info to manage it ?
select email_table1 from table1.
delete from table2 where email = email_table1.
Thanks
Greg
There's little information to form an answer but you could use a sub select.
Something like this presuming you're using MySQL or similar.
DELETE FROM `table1` WHERE id = (
SELECT `referenceID` FROM `table2` WHERE `email` = 'the#email.com' LIMIT 1
) LIMIT 1;

how to get a unique record from select query in mysql each time [closed]

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 3 years ago.
Improve this question
I want to fetch random record from the table but repeated game id record is will become out only once at a time. I am sending a screenshot of my table
You need to use MySQL RAND() function.
Query:
SELECT * FROM lessons_game ORDER BY RAND() LIMIT 1
// Put proper fields instead of *
Explanation:
ORDER BY RAND() will shuffle records random records from DB Table.
And we will get random records after we execute the query result set.
We are putting LIMIT 1 so only one record will be pulled out.
Try the following command
SELECT * FROM lessons_game ORDER BY RAND() LIMIT 1

Return the latest 10 records from a mysql query [closed]

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 7 years ago.
Improve this question
Here's the link what I mean -
i.stack.imgur.com/yYQbu.png.
Query from 2 columns name and version.(may only with one column I'll put version in name column).
So , Wheres matches name from title or post from same column name and returns all lowest number from version(column).
Can anyone give me example of some query?
So far I have this query:
$name = substr($row[2],0,10);
$q = mysql_query("SELECT name from films WHERE name LIKE '$name'") or die(mysql_error());
I'm assuming your table has an id column as the primary key with auto increment.
In which case, you need to add an ORDER BY and LIMIT to your query.
$q = mysql_query("SELECT name from films WHERE name LIKE '$name' ORDER BY id DESC LIMIT 10") or die(mysql_error());
ORDER BY id DESC will make your query put the latest records first.
LIMIT 10 will ensure that you only grab 10 records.

Special keyword in mysql select statement [closed]

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
Consider the following script:
SELECT * FROM TABLE1 WHERE COLUMN1='$exb';
$exb is a PHP variable which is fed from an HTML select list with 3 values:0,1,2. Values 1 and 2 correspond to column1 values. In case of selecting value 0, I want to include all the values of COLUMN1. Is there a way to implement the above without changing the script? In other words is there any keyword to assign to $exb which will oblige the script to select all the rows of table TABLE1 in case the user selects 0 from HTML select list?
Thank you
It's a little unclear, but I think you are asking is there a special clause you can add to a where clause to return every single row from the database rather than specific criteria matched in a where clause.
You can put in a pretend where clause by saying col1=col1 which is effectively a bogus (though valid) syntax like this:
SELECT * FROM TABLE1 WHERE COLUMN1=column1;
Though it would have to be without the quotes to select every single row of the table.
Putting the quotes around the variable would be very simple in your php however.
Having said that, wouldn't it be much easier to simply omit the where clause entirely if the value selected is 0?
For this you require to build a dynamic query.
$query = "SELECT * FROM TABLE1";
$exb = isset($_GET['exb']) ? $_GET['exb'] : 0;
$goodParam = array(0,1,2);//array of allowed values
if($exb>0){
if (in_array($exb, $goodParam)) {
$query .= " WHERE COLUMN1 = '$exb'";
}
}
echo $query;
I don't think you can do that with MySql query only. You need to use php and ifelse statement where you can check for $exb value before executing query. For example:
if($exb == "0")
$query = "SELECT * FROM TABLE1";
else
$query = "SELECT * FROM TABLE1 WHERE COLUMN1='$exb'";

query="SELECT * FROM Table WHERE `VarCharCol1`= numeric" [closed]

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
I have a table with varchar column, this column contains both numeric records and AlphaNumeric records, but require only the ones that have no letters.
How can I achieve this?
Try this:
SELECT * FROM table WHERE `varcharcol1` RLIKE '^[0-9]+$'
tryed
SELECT column_name FROM table WHERE ISNUMERIC(column_name) = 1
select * from table where concat('', column * 1) = column;
Returns array of data, where column is numeric (contains only digits).

Categories