pouncer Posted March 10, 2007 Share Posted March 10, 2007 $results = mysql_query("SELECT * FROM $cat WHERE item_id='$item_id'"); $num = mysql_num_fields($results); $row = mysql_fetch_row($results); $i = 0; while ($i < $num) { $name = mysql_field_name($results, $i); $data = $row[$name]; echo $name . " - " . $data; echo "<br>"; $i++; }; It just echos the field names, but not the data: item_id - image_URL - title - media - director - cast - description - why is this? Quote Link to comment Share on other sites More sharing options...
per1os Posted March 10, 2007 Share Posted March 10, 2007 I do not know why you don't just call the array by the column name, but this should help you on your way. $results = mysql_query("SELECT * FROM $cat WHERE item_id='$item_id'"); $i=0; while ($row = mysql_fetch_array($results)) { $num = count($row); while ($i < $num) { $name = mysql_field_name($results, $i); $data = $row[$name]; echo $name . " - " . $data; echo "<br>"; $i++; } } ?> --FrosT Quote Link to comment Share on other sites More sharing options...
pouncer Posted March 10, 2007 Author Share Posted March 10, 2007 ok thanks it prints the all now but i get error Warning: mysql_field_name() [function.mysql-field-name]: Field 7 is invalid for MySQL result index 7 in Warning: mysql_field_name() [function.mysql-field-name]: Field 7 is invalid for MySQL result index 8 in etc.. etc.. up to index 12 line 214 which is $name = mysql_field_name($results, $i); ? Quote Link to comment Share on other sites More sharing options...
pouncer Posted March 10, 2007 Author Share Posted March 10, 2007 i just went back to my code and used $row = mysql_fetch_assoc($results); 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.