JasonGreen Posted October 8, 2009 Share Posted October 8, 2009 I am not attempting to have the correct codes just thrown at me but I really need to understand why I’m having the problems I am. I have several books, but they are all the same in that they tell you what functions are but not really how to use them in an applied way. There are essentially three things wrong with my code. As you can see I am including another php file to pull all the information from ($petspa). I have the While with the format I need. But I am unable to insert a proper table. Also I want to take each breed and do a summary of total revenue from that breed as attempted once in the For (I should just be able to repeat that For While for each breed.) Finally I need a simple array to display the single breed that brings in the most revenue, showing only its breed type and total revenue. The while works, but I can’t do a simple table for it to appear organized. The for does not work at all. And I have no idea how to pull out an array for the single breed and total profits <?php Include 'petspainfo.php' $breed = rtrim(strtok($pet_spa, " \n")); $appointment = rtrim(strtok(" \n")); $day = rtrim(strtok(" \n")); $time = rtrim(strtok(" \n")); $charge = rtrim(strtok(" \n")); printf ("%9s\n", "Breed App. Day Time Charge"); while($breed){ echo $breed, " "; echo $appointment, " "; echo $day, " "; echo $time, " "; echo "\$" . number_format ($charge,2); $breed = rtrim(strtok(" \n")); echo date('M',mktime(12,0,0,$appointment,1,2009)) . " "; $day = rtrim(strtok(" \n")); $time = rtrim(strtok(" \n")); $charge = rtrim(strtok(" \n")); } for ($breed = Lab){ echo $breed; $charge = $charge + $charge; echo $charge } ?> Quote Link to comment https://forums.phpfreaks.com/topic/176992-looping-then-array-a-certain-breed-from-a-petspa/ Share on other sites More sharing options...
Garethp Posted October 8, 2009 Share Posted October 8, 2009 For one, can you show us how the array your working with is structured? This is done by using print_r($Array); where $Array is your array. Quote Link to comment https://forums.phpfreaks.com/topic/176992-looping-then-array-a-certain-breed-from-a-petspa/#findComment-933174 Share on other sites More sharing options...
lemmin Posted October 8, 2009 Share Posted October 8, 2009 Could you explain in more detail what the inputs are and what the expected output is? This would make your code easier to follow. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/176992-looping-then-array-a-certain-breed-from-a-petspa/#findComment-933176 Share on other sites More sharing options...
JasonGreen Posted October 8, 2009 Author Share Posted October 8, 2009 I haven't got to the array yet. i was hoping it would be more sefl explainatory after addressing the for problem and hopefully seeing what I was doing wrong with the tabel. I was up til 3 playing with that. I just included the need for an array because it seems asking about one detail at a time just gets more questions than comments. Ya know? I just noticed I made a typo in the code <?php Include 'petspainfo.php' $breed = rtrim(strtok($pet_spa, " \n")); $appointment = rtrim(strtok(" \n")); $day = rtrim(strtok(" \n")); $time = rtrim(strtok(" \n")); $charge = rtrim(strtok(" \n")); printf ("%9s\n", "Breed App. Day Time Charge"); while($breed){ echo $breed, " "; echo date('M',mktime(12,0,0,$appointment,1,2009)) . " "; echo $day, " "; echo $time, " "; echo "\$" . number_format ($charge,2); $breed = rtrim(strtok(" \n")); $appointment = rtrim(strtok(" \n")); $day = rtrim(strtok(" \n")); $time = rtrim(strtok(" \n")); $charge = rtrim(strtok(" \n")); } for ($breed = Lab){ echo $breed; $charge = $charge + $charge; echo $charge } ?> Quote Link to comment https://forums.phpfreaks.com/topic/176992-looping-then-array-a-certain-breed-from-a-petspa/#findComment-933179 Share on other sites More sharing options...
JasonGreen Posted October 8, 2009 Author Share Posted October 8, 2009 I haven't got to the array yet. i was hoping it would be more sefl explainatory after addressing the for problem and hopefully seeing what I was doing wrong with the tabel. I was up til 3 playing with that. I just included the need for an array because it seems asking about one detail at a time just gets more questions than comments. Ya know? Quote Link to comment https://forums.phpfreaks.com/topic/176992-looping-then-array-a-certain-breed-from-a-petspa/#findComment-933189 Share on other sites More sharing options...
mikesta707 Posted October 8, 2009 Share Posted October 8, 2009 well first of all. you dont do for loops like that. second of all, you probably want to use the comparison operator (==) not the assignment operator (=) for loops are structured (for the most part, of course there are some variations) like so for ($counter, $counter < $timesToLoop; $counter++){ i'm not sure what you are trying to even do, but I suggest you do study the basics of PHP a little more before you tackle this problem. It will be a lot less of a headache then.. But for your problem. Can you describe, exactly, what works and what doesn't, and what you expect to happen. Quote Link to comment https://forums.phpfreaks.com/topic/176992-looping-then-array-a-certain-breed-from-a-petspa/#findComment-933223 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.