bioTIN Posted July 22, 2009 Share Posted July 22, 2009 I have tried understanding classes in PHP, but I am not even able to start writing a class for the below code: $fieldnames=mysql_list_fields(fcsubscription,regular); $fieldnames1=mysql_num_fields($fieldnames); for ($index=0; $index < $fieldnames1; ++$index) { $mysql_fields[mysql_field_name($fieldnames, $index)]=$cleantake[mysql_field_name($fieldnames, $index)]; } $subnames=mysql_list_fields(fcsubscription,sub_details); $subnames1=mysql_num_fields($subnames); echo "total number is ".$subnames1; for($index=0;$index<$subnames1;++$index){ $sub_fields[mysql_field_name($subnames,$index)]=$cleantake[mysql_field_name($subnames,$index)]; } as you can see, I call for the field names from the database and then take values from an array based on the earlier retrieved field names. Now how do I go about writing a class with variables changing? If you could explain how a class could be created for this one line :$sub_fields[mysql_field_name($subnames,$index)]=$cleantake[mysql_field_name($subnames,$index)]; } i think ill be able to manage with the others. thanks Link to comment https://forums.phpfreaks.com/topic/166901-php-classes/ Share on other sites More sharing options...
trq Posted July 22, 2009 Share Posted July 22, 2009 Classes aren't written to replace single lines of code. What makes you believe you even need a class? Link to comment https://forums.phpfreaks.com/topic/166901-php-classes/#findComment-880052 Share on other sites More sharing options...
bioTIN Posted July 22, 2009 Author Share Posted July 22, 2009 i have to extract a lot info from mysql so i thought i could give classes a shot at. Well i did end up getting the result, but now im not able to extract it. foreach($sub_details->mysql_fields as $key -> $value) { echo $key."->".$value; } throws an error, actually doesnt do anything, what should i do? Link to comment https://forums.phpfreaks.com/topic/166901-php-classes/#findComment-880346 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.