Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot get the value from database in PHP

Tags:

sql

php

laravel-4

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?

like image 936
user1012181 Avatar asked Dec 15 '14 04:12

user1012181


People also ask

How to check SQL query is correct or not in php?

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.

What does mysql_ query return?

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.

What does $row mean in PHP?

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+

How to write query in php?

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.


1 Answers

Change true with 1, and false with 0.

like image 51
Sverri M. Olsen Avatar answered Oct 15 '22 08:10

Sverri M. Olsen