mysql_fetch_array Not working at all

Thread Solved

Join Date: Jan 2009
Posts: 33
Reputation: theighost is an unknown quantity at this point 
Solved Threads: 1
theighost theighost is offline Offline
Light Poster

mysql_fetch_array Not working at all

 
0
  #1
Jul 13th, 2009
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??

  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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 217
Reputation: mrcniceguy is an unknown quantity at this point 
Solved Threads: 4
mrcniceguy mrcniceguy is offline Offline
Posting Whiz in Training

Re: mysql_fetch_array Not working at all

 
0
  #2
Jul 13th, 2009
is it Giving any Erro?
what if u try this
  1. while ($row = mysql_fetch_array($query))
  2. {
  3. $id=$row['id'];
  4. echo "row= $id ";
  5.  
  6. }
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 33
Reputation: theighost is an unknown quantity at this point 
Solved Threads: 1
theighost theighost is offline Offline
Light Poster

Re: mysql_fetch_array Not working at all

 
0
  #3
Jul 13th, 2009
it is the same result, it writes "row=" as if the value is empty!
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 217
Reputation: mrcniceguy is an unknown quantity at this point 
Solved Threads: 4
mrcniceguy mrcniceguy is offline Offline
Posting Whiz in Training

Re: mysql_fetch_array Not working at all

 
1
  #4
Jul 13th, 2009
what is ur table structure,i mean the fields?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,612
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 461
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: mysql_fetch_array Not working at all

 
1
  #5
Jul 13th, 2009
theighost,
Post complete source code.
Last edited by adatapost; Jul 13th, 2009 at 12:21 pm. Reason: Typo
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 33
Reputation: theighost is an unknown quantity at this point 
Solved Threads: 1
theighost theighost is offline Offline
Light Poster

Re: mysql_fetch_array Not working at all

 
0
  #6
Jul 13th, 2009
  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. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 171
Reputation: Menster is an unknown quantity at this point 
Solved Threads: 22
Menster's Avatar
Menster Menster is offline Offline
Junior Poster

Re: mysql_fetch_array Not working at all

 
1
  #7
Jul 14th, 2009
Try changing "$row['id']" to "$row[0]" and see if you still get nothing.
$me = new Person();
if (isset($_COOKIE)){
$me->eat($_COOKIE);
} else { $me->starve(); }
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 33
Reputation: theighost is an unknown quantity at this point 
Solved Threads: 1
theighost theighost is offline Offline
Light Poster

Re: mysql_fetch_array Not working at all

 
0
  #8
Jul 14th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 94
Reputation: sikka_varun is an unknown quantity at this point 
Solved Threads: 11
sikka_varun's Avatar
sikka_varun sikka_varun is offline Offline
Junior Poster in Training

Re: mysql_fetch_array Not working at all

 
1
  #9
Jul 14th, 2009
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:

  1. $row = array();
  2.  
  3. $row = mysql_fetch_array();
  4. // Proceed with rest of the code
VâRûN
---Happy to Help---
sikka_varun@yahoo.com
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 33
Reputation: theighost is an unknown quantity at this point 
Solved Threads: 1
theighost theighost is offline Offline
Light Poster

Re: mysql_fetch_array Not working at all

 
0
  #10
Jul 14th, 2009
Yes I used some arrays in my script and had to declare some of the variable as $variable = array();
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC