943,651 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 2578
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 13th, 2009
0

mysql_fetch_array Not working at all

Expand Post »
Hi,
I have this strange problem, I select some data from the database, there is no problem in the query and even when I use mysql_num_rows on the query it gives me the right number of entries in the table I'm selecting from, but when I try to echo every row it echos empty values... what is the problem??

PHP Syntax (Toggle Plain Text)
  1. $sql = "SELECT * FROM table";
  2. $query = mysql_query($sql) or die(mysql_error());
  3. $row_number = mysql_num_rows($query);
  4. while ($row = mysql_fetch_array($query))
  5. {
  6. echo "row= ".$row["id"];
  7. }
Last edited by theighost; Jul 13th, 2009 at 11:36 am.
Similar Threads
Reputation Points: 8
Solved Threads: 15
Junior Poster
theighost is offline Offline
103 posts
since Jan 2009
Jul 13th, 2009
0

Re: mysql_fetch_array Not working at all

is it Giving any Erro?
what if u try this
php Syntax (Toggle Plain Text)
  1. while ($row = mysql_fetch_array($query))
  2. {
  3. $id=$row['id'];
  4. echo "row= $id ";
  5.  
  6. }
Reputation Points: 17
Solved Threads: 8
Posting Whiz in Training
mrcniceguy is offline Offline
278 posts
since Mar 2008
Jul 13th, 2009
0

Re: mysql_fetch_array Not working at all

it is the same result, it writes "row=" as if the value is empty!
Reputation Points: 8
Solved Threads: 15
Junior Poster
theighost is offline Offline
103 posts
since Jan 2009
Jul 13th, 2009
1

Re: mysql_fetch_array Not working at all

what is ur table structure,i mean the fields?
Reputation Points: 17
Solved Threads: 8
Posting Whiz in Training
mrcniceguy is offline Offline
278 posts
since Mar 2008
Jul 13th, 2009
1

Re: mysql_fetch_array Not working at all

theighost,
Post complete source code.
Last edited by adatapost; Jul 13th, 2009 at 12:21 pm. Reason: Typo
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Jul 13th, 2009
0

Re: mysql_fetch_array Not working at all

PHP Syntax (Toggle Plain Text)
  1. mysql_connect('server','user','pass');
  2. mysql_select_db('database');
  3. $sql = "select * from table";
  4. $query = mysql_query($sql) or die(mysql_error());
  5. while($row = mysql_fetch_array($query))
  6. {
  7. $search_row = $row['id'];
  8. echo $search_row;
  9. }
Reputation Points: 8
Solved Threads: 15
Junior Poster
theighost is offline Offline
103 posts
since Jan 2009
Jul 14th, 2009
1

Re: mysql_fetch_array Not working at all

Try changing "$row['id']" to "$row[0]" and see if you still get nothing.
Reputation Points: 49
Solved Threads: 22
Junior Poster
Menster is offline Offline
175 posts
since Jun 2009
Jul 14th, 2009
0

Re: mysql_fetch_array Not working at all

I solved it in a really strange way guys.. wtf is this version of PHP that i'm using, that obliges me to declare the variables before using.

I just put $row=0; $search_row=0; before making the query and it worked, really strange!!!!

thanks anyway
Reputation Points: 8
Solved Threads: 15
Junior Poster
theighost is offline Offline
103 posts
since Jan 2009
Jul 14th, 2009
1

Re: mysql_fetch_array Not working at all

Thats good you solved it. But this $row is an array. So making it 0 is a bit strange. What other thing you can do is, you can declare it as an empty array:

php Syntax (Toggle Plain Text)
  1. $row = array();
  2.  
  3. $row = mysql_fetch_array();
  4. // Proceed with rest of the code
Reputation Points: 11
Solved Threads: 12
Junior Poster in Training
sikka_varun is offline Offline
94 posts
since Dec 2008
Jul 14th, 2009
0

Re: mysql_fetch_array Not working at all

Yes I used some arrays in my script and had to declare some of the variable as $variable = array();
Reputation Points: 8
Solved Threads: 15
Junior Poster
theighost is offline Offline
103 posts
since Jan 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: isert the value of javascript function to database
Next Thread in PHP Forum Timeline: PHP Installation on Shared Server





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC