Densen Posted June 13, 2007 Share Posted June 13, 2007 Hi all, I am having a lot of trouble figuring out what's going wrong with a query im trying to perform. If anyone could help me out, i'd really appreciate it! I have some SQL experience and am having no problems with any other queries but this one in particular is just not working. I'm trying to get information from a sql table. There are 34 columns, and im fetching one row. Each of the values in the row is just a 1 or 0. After the query, I use mysql_fetch_array to put that one row into an array. Usually, I can just call any associated number of the array and pull the corresponding value, but in this instance, it's not giving me anything. I have checked the query over and over, it's definitely correct. I have added code to check for any SQL errors, there are none. I have used the exact same code elsewhere with a different table (and different data) and had no problems. The variable that mysql_fetch_array is run in returns as nothing, it does not return as "array" like it should. Here's the code: $query = mysql_query("SELECT * FROM availability WHERE c_id='1'"); if (!$query) { echo 'Could not run query: ' . mysql_error(); exit; } $array = mysql_fetch_row($query); $array returns nothing $array[0] returns nothing $array[33] returns nothing Yet, if I run the query directly in mysql, I DO get a result. What's going on? Is there a limit to how much I can be requesting from the database? Quote Link to comment Share on other sites More sharing options...
Nhoj Posted June 13, 2007 Share Posted June 13, 2007 Try doing the following: $query = mysql_query("SELECT * FROM availability WHERE c_id='1'"); if (!$query) { echo 'Could not run query: ' . mysql_error(); exit; } $array = mysql_fetch_row($query); echo '<pre>'; print_r($array); echo '</pre>'; The last little bit will print out all of the information stored in your array variable Quote Link to comment Share on other sites More sharing options...
Densen Posted June 13, 2007 Author Share Posted June 13, 2007 Thanks for the suggestion, however, that also prints nothing. It's so strange, I can't seem to get any information out of the query, yet there's no query error, and there's data in there. I don't think the array even gets made, however, when I define the variable for the array BEFORE the mysql_fetch_array line, it's wiped by the time it gets past the query. So obviously something is trying to happen there, but I just can't understand where the problem is coming from exactly. This is so frustrating! If you have any more suggestions, please fire away and i'll give them a go. Quote Link to comment Share on other sites More sharing options...
Nhoj Posted June 13, 2007 Share Posted June 13, 2007 Try adding LIMIT 1 into your query... $query = mysql_query('SELECT * FROM `availability` WHERE `c_id` = 1 LIMIT 1'); Quote Link to comment Share on other sites More sharing options...
Densen Posted June 13, 2007 Author Share Posted June 13, 2007 Another good suggestion, but that also did nothing. It seems as though there's still nothing contained in the array. Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted June 13, 2007 Share Posted June 13, 2007 try this: $query = mysql_query("SELECT * FROM availability WHERE c_id='1' limit 1"); if (!$query) { echo 'Could not run query: ' . mysql_error(); exit; } $array = mysql_fetch_array($query); Quote Link to comment Share on other sites More sharing options...
Nhoj Posted June 13, 2007 Share Posted June 13, 2007 IF mmarif4u's doesn't work post an exerpt from your database, (export & paste the create table statement) Quote Link to comment Share on other sites More sharing options...
neel_basu Posted June 13, 2007 Share Posted June 13, 2007 1.Run this Query on MySQL CLI or PHPMyAdmin And see what are the Results there. 2 I cant see your mysql_connect() Assuming your link Identifier resourse variable is $conn $query = mysql_query("SELECT * FROM availability WHERE c_id='1'", $conn); //Bla Bla Bla $array = mysql_fetch_row($query, $conn); //Bla Bla Bla Hope this Works. Quote Link to comment Share on other sites More sharing options...
Densen Posted June 13, 2007 Author Share Posted June 13, 2007 Just what I was about to do Ok, the this particular table is large, so im going to post a snippet. TABLE `availability` ( `c_id` int(11) NOT NULL default '0', `a_aust` smallint(6) NOT NULL default '0', `a_belg` smallint(6) NOT NULL default '0', `a_braz` smallint(6) NOT NULL default '0', etc... etc... (the fields missing here are identical in type but differ in name) etc... PRIMARY KEY (`c_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; There are 35 fields in total, only ONE entry in the database and c_id in that entry is 1. I am trying to empty the numbers from all 35 fields, an array is fine, but it's not even getting that far. Does that provide any clues? It doesn't look too complicated. By the way, thanks to all the people trying to help me out! ---------------------- I have already run the query in phpMyAdmin. It returns everything I expect it to. One whole row with all the values. I will try your #2 suggestion in the meantime. EDIT: Still no go with suggestion #2. Couldn't get anything out of it. Quote Link to comment Share on other sites More sharing options...
neel_basu Posted June 13, 2007 Share Posted June 13, 2007 2 I cant see your mysql_connect() Assuming your link Identifier resourse variable is $conn $query = mysql_query("SELECT * FROM availability WHERE c_id='1'", $conn); //Bla Bla Bla $array = mysql_fetch_row($query, $conn); //Bla Bla Bla Hope this Works. YOU ran this Code ?? Whats its output. Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted June 13, 2007 Share Posted June 13, 2007 Please post ur complete code including db connection Quote Link to comment Share on other sites More sharing options...
Densen Posted June 13, 2007 Author Share Posted June 13, 2007 Hmm, I think I know the problem. I am connecting through an SDK script which is interfacing with the forum on my site. I think it might be interfering with some of my SQL queries as everything passes through there first. Since you mentioned db connection I will see if I can track down if that's the problem. I'll dig deeper and see what I can find. Thanks everyone. 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.