Fhwoarang Posted September 26, 2008 Share Posted September 26, 2008 Hi, everybody. I recently started to with with PHP5 and I'm kinda liking it. However, as usual, I'm having some troubles, and this time is about MySQL. I use mysql_fetch_array to convert into an array a given query. I don't know why, but if I do this: SELECT * FROM table WHERE GivenField = "GivenText"; If my table has 5 couls, I get a size 10 ten array, I mean, it doubles my array with null or blank spaces, I don't know why. So I have to use mysql_fetch_row instead, which works fine. Now, I want this table to be printed on a HTML table, but I want to exclude the first row in the table (which contains each field's name). I was reading that when you use: $row = mysql_fetch_array(); You can print it with something like this: while ($row=mysql_fetch_array()) { $row[Field1] $row[Field2] } Do I have to use "=" or "==" for " $row=mysql_fetch_array()" inside the "while"? It still works if I just use only one "=". When I use: "echo "$row[Field1]; It prints the name of the field on the first iteration, it doesn't skip it (and the goes through the next rows). What am I doing wrong or what's the best way to do this? Seems like a very common task. Thanks in advice. Quote Link to comment Share on other sites More sharing options...
Fhwoarang Posted September 26, 2008 Author Share Posted September 26, 2008 Whoops, nevermind about printing or not the first field. fetch_array automatically skips the fields names. Still I don't know why fetch_array doubles my arrays, while fetch_row keeps them normal. Quote Link to comment Share on other sites More sharing options...
Barand Posted September 26, 2008 Share Posted September 26, 2008 fetch_row gives you a numerically index array fetch_assoc gives array indexed by fieldnames fetch_array (default arguments) gives array containing both. You can add an optional second arg to fetch_array to give either numeric or associative indexed array (but then IMO you may as well use one of the other two functions). Quote Link to comment Share on other sites More sharing options...
Fhwoarang Posted September 29, 2008 Author Share Posted September 29, 2008 Thank you very much. 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.