I'm trying to get a value from database using the following code
$request = Registrationrequest::where('course_id', $id)
->where('user_id', Auth::user()->id)
->where('registered', true)->count();
I'm using Laravel. I have a row with course_id = 4
, user_id=3
and registered=true
.
When I var_dump each values separately, I'm confirming it. But when I use this where condition together, I'm not getting the count value as 1, instead getting 0.
I have another query where I use
$request = Registrationrequest::where('course_id', $id)
->where('user_id', Auth::user()->id)
->where('registered', false)->first();
This works perfect when the registered value is false.
Can anybody tell me where am I wrong?
Here's Pseudocode of what I would like it to do: <? php //connect user //connect to database //v_query = $_GET['usrinput']; if(validate v_query == true){ echo "This query can be executed"; } else{ echo "This query can't be executed because the table does not exist."; } //disconnect ?> Something like this.
mysql_query() returns TRUE (non-zero) or FALSE to indicate whether or not the query succeeded. A return value of TRUE means that the query was legal and could be executed by the server. It does not indicate anything about the number of rows affected or returned.
Return Value: Returns an array of strings that corresponds to the fetched row. NULL if there are no more rows in result set. PHP Version: 5+
Its basic syntax is as follows: SELECT column1_name, column2_name, columnN_name FROM table_name; Let's make a SQL query using the SELECT statement, after that we will execute this SQL query through passing it to the PHP mysqli_query() function to retrieve the table data.
Change true
with 1
, and false
with 0
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With