loveamit Posted April 20, 2014 Share Posted April 20, 2014 i got an error said Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in and my code is $result = mysql_query("SELECT * FROM friendlist WHERE firstname='".$_SESSION['SESS_FIRST_NAME'] ."' and status='pending' ORDER BY firstname ASC"); while($row=mysql_fetch_array($result)) please somebody help me Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted April 20, 2014 Share Posted April 20, 2014 Your query has most likely encountered an error. Use mysql_error() to find out what the error is. Also you should stop using mysql_* functions these are deperecated and could soon be removed from future versions of PHP. I'd advise you to use either mysqli or PDO from now on. Quote Link to comment Share on other sites More sharing options...
loveamit Posted April 20, 2014 Author Share Posted April 20, 2014 okk bro the error after including mysql_error is query is empty Quote Link to comment Share on other sites More sharing options...
loveamit Posted April 20, 2014 Author Share Posted April 20, 2014 i guess it means there is no value returning through select query but database is correct and also columns are correct Quote Link to comment Share on other sites More sharing options...
loveamit Posted April 20, 2014 Author Share Posted April 20, 2014 please write code of mysqli and where should i write down and how here is my code...... $result = mysql_query("SELECT * FROM friendlist WHERE firstname='".$_SESSION['SESS_FIRST_NAME'] ."' and status='pending' ORDER BY firstname ASC"); while($row=mysql_fetch_array($result)) { $add=$row['addby']; } $numberOfRows = MYSQL_NUMROWS($result); Quote Link to comment Share on other sites More sharing options...
bsmither Posted April 20, 2014 Share Posted April 20, 2014 In my experience with some versions of the MySQL database engine, status is a reserved word. Please try your query using backticks to delineate table and column names: AND `status` = 'pending' (The backtick character is on the key just above the TAB key on the keyboard.) Quote Link to comment Share on other sites More sharing options...
loveamit Posted April 20, 2014 Author Share Posted April 20, 2014 i am sure there is no prob with this one i have use select queries with while($row=mysql_fetch_array($result)) { each time its giving same error and said query is empty please help me i got so irritated of it Quote Link to comment Share on other sites More sharing options...
loveamit Posted April 20, 2014 Author Share Posted April 20, 2014 i have used this code in diff 2 ways everywwhere but the result is same Quote Link to comment Share on other sites More sharing options...
bsmither Posted April 20, 2014 Share Posted April 20, 2014 Let's try finding the problem by removing some things and testing. Then add them back one at a time: Test, and if it works, do the next: $result = mysql_query("SELECT * FROM friendlist"); Test, and if it works, do the next: $result = mysql_query("SELECT * FROM friendlist ORDER BY firstname ASC"); Test, and if it works, do the next: $result = mysql_query("SELECT * FROM friendlist WHERE status='pending' ORDER BY firstname ASC"); Test. $result = mysql_query("SELECT * FROM friendlist WHERE firstname='".$_SESSION['SESS_FIRST_NAME'] ."' and status='pending' ORDER BY firstname ASC"); If the last test does not work, then we can say there is no record that has the value assigned to $_SESSION['SESS_FIRST_NAME']. Quote Link to comment Share on other sites More sharing options...
loveamit Posted April 20, 2014 Author Share Posted April 20, 2014 common u r acting like child .....i have already checked and echoed the value of session variable and it is working .....i just wanted to know why is it giving error that query is empty although all fields are correct Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 20, 2014 Share Posted April 20, 2014 (edited) the query and php code you have posted CANNOT have produced a query is empty error. the query is empty error does NOT mean that the query didn't match any rows. means that the actual sql query statement supplied as a parameter to the mysql_query() statement was empty. either that's not the actual code or the query with a problem is somewhere else in your code. Edited April 20, 2014 by mac_gyver Quote Link to comment Share on other sites More sharing options...
loveamit Posted April 20, 2014 Author Share Posted April 20, 2014 please i dont want to listen anythng i m so sad just please if u cn write the correct code of two lines i will be haapy then Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 20, 2014 Share Posted April 20, 2014 no one here is going to write code for you. as i stated above, the error you reported cannot be coming from the posted code. Quote Link to comment Share on other sites More sharing options...
loveamit Posted April 20, 2014 Author Share Posted April 20, 2014 jst tell me wat to do if it is giving this kind of error wat will u suggest Quote Link to comment Share on other sites More sharing options...
ginerjm Posted April 20, 2014 Share Posted April 20, 2014 (edited) What a horrible attitude you have!! People are literally giving you step by step debugging advice and you are too much of an idiot to let them help you. And why don't you learn how to write full words instead of your jibberish misspelled words and abbreviations? Edited April 20, 2014 by ginerjm Quote Link to comment Share on other sites More sharing options...
loveamit Posted April 20, 2014 Author Share Posted April 20, 2014 (edited) u have written that means that the actual sql query statement supplied as a parameter to the mysql_query() statement was empty. i nt able to understand these lines wat does it mean Edited April 20, 2014 by loveamit Quote Link to comment Share on other sites More sharing options...
ginerjm Posted April 20, 2014 Share Posted April 20, 2014 It means that perhaps you are looking at the wrong section of code Do you have some other queries going on in this script? Put an echo before this query and after it and be sure that you are getting the error there. And show us the new code after you have made these changes (with the MySQL_error call too) Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 20, 2014 Share Posted April 20, 2014 (edited) there is a way that your posted mysql_fetch_xxxxx() statement can produce the posted error, but that would require that the code inside your loop is running a query that's overwriting the $result variable. Edited April 20, 2014 by mac_gyver Quote Link to comment Share on other sites More sharing options...
loveamit Posted April 20, 2014 Author Share Posted April 20, 2014 sorry bt i didnt think tat while loop is causing any prob the prob is occuring due to the select query when i used mysql_error() then it is giving error of query is empty now tell me wat to do Quote Link to comment Share on other sites More sharing options...
ginerjm Posted April 20, 2014 Share Posted April 20, 2014 sory - tyred of reding yur bad writing. gud bye Quote Link to comment Share on other sites More sharing options...
loveamit Posted April 20, 2014 Author Share Posted April 20, 2014 sorry but i didnt think that while loop is causing any problem the problem is occuring due to the select query when i used mysql_error() then it is giving error of query is empty now tell me what to do Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 20, 2014 Share Posted April 20, 2014 you have been told that the posted query and posted code cannot produce the errors you are reporting. there's nothing technically wrong with that query. you were also told it's possible that the code inside your loop can be causing one of the errors you are reporting. since you doubt that's the case, there's nothing more that we can tell you because this process of remotely debugging what is going on in your code requires that you have the ability to question and to investigate what your code is doing in order to find where and what the problem is. Quote Link to comment Share on other sites More sharing options...
DavidAM Posted April 20, 2014 Share Posted April 20, 2014 Let's try this again. Your original post said: i got an error said Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in and my code is $result = mysql_query("SELECT * FROM friendlist WHERE firstname='".$_SESSION['SESS_FIRST_NAME'] ."' and status='pending' ORDER BY firstname ASC"); while($row=mysql_fetch_array($result)) please somebody help me You have cutoff the error message. PHP error messages give the name of the file and the line number in that file where the error occurred. Sometimes, the actual problem is a couple of lines BEFORE the line number given. This error message "... boolean given ..." indicates that the parameter passed to the mysql_fetch_array function is the (boolean) value FALSE. It is expected to be a query resource returned by mysql_query. So, the problem is a couple of lines BEFORE there error. Read the error message, find the file and line number in the error message. Post code from that file starting 5 or 10 lines BEFORE the line number in the error message, and continuing through 5 or 10 lines AFTER the error message. SURROUND THE CODE WITH TAGS. ALSO Post the FULL ERROR MESSAGE (you can X-out the path if you feel it is a security risk). If we need to see more code, we will ask. When we provide a suggestion, and it does not work; post the NEW CODE as you tried it, and tell us what EXACTLY happened. If you get ANY error messages, POST THE FULL TEXT OF THE MESSAGE. We are not sitting there looking at your screen, we have NO IDEA what is happening, so you must provide us with as much pertinent detail as possible. mac_gyver is correct. The code you posted can NOT produce the "query is emtpy" message. So either you posted the wrong code, or you put the mysql_error call in the wrong place, or something. Again, you did not post the NEW CODE so we can't tell what is happening. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.