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. Link to comment https://forums.phpfreaks.com/topic/125878-solved-newbie-question-problem-with-mysql_fetch_array/ 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. Link to comment https://forums.phpfreaks.com/topic/125878-solved-newbie-question-problem-with-mysql_fetch_array/#findComment-651032 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). Link to comment https://forums.phpfreaks.com/topic/125878-solved-newbie-question-problem-with-mysql_fetch_array/#findComment-651440 Share on other sites More sharing options...
Fhwoarang Posted September 29, 2008 Author Share Posted September 29, 2008 Thank you very much. Link to comment https://forums.phpfreaks.com/topic/125878-solved-newbie-question-problem-with-mysql_fetch_array/#findComment-652735 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.