Jump to content

mysql_fetch_array fetches nothing?


Densen

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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! :D

 

----------------------

 

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.  :(

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.