railanc4309 Posted March 13, 2009 Share Posted March 13, 2009 Being really really thick now... I have an SQL statement $query2 = "SELECT * from Answers where QID = '".$FormID[$count]."'"; $result2 = getResults($query2); while ($line2 = mysql_fetch_assoc($result2)) { extract($line2); echo("<span class='style2'>".$Answer." | </span>"); echo("<span class='style1'>".$Count." | </span><br>"); } The above code is returning out some information from a database. The table is called 'Answers', and looks like this: Answers table structure e.g. ------------------------ ID | QID | Answer | Count | Enabled 1 | 3 | Male | 7 | 1 2 | 3 | Female | 4 | 1 The above code is outputting something like this: Male | 7 | Female | 4 | This is fine. However, I now want to display a pie chart with these results. I'm using a php-pie chart i've used before and it needs the pie chart to look like this: <img src="pie2.php?data=1*2*3*4*5" width="260" height="163" /> pie2.php is where it's getting all the piechart colours / depth / label information from. Notice there's no * after the final value? That's what I can't do!! How do I get my 'Count' from out of the database, display each one apart from the last one with an * at the end of it, and then shove it all within an image tag?? Have tried several foreach loops, whileloops and I can't figure it out... Basically, in-short (only the wrong code - obviously!) $part1 = "<img src="pie2.php?data="; $part2 = loop through database. pull-out all values. separate each one with a *. remove the final * from the end. $part3 = "" width="260" height="163" />"; echo($part1.$part2.$part3); Please help!!! I'm going mad now and feel like a right fool!! Thanks in advance, Rachael Link to comment https://forums.phpfreaks.com/topic/149253-really-simple-for-non-thickos-like-me/ Share on other sites More sharing options...
MiCR0 Posted March 13, 2009 Share Posted March 13, 2009 in your while loop add $piearray .= $Count."*"; and then u have the string u want Link to comment https://forums.phpfreaks.com/topic/149253-really-simple-for-non-thickos-like-me/#findComment-783793 Share on other sites More sharing options...
railanc4309 Posted March 13, 2009 Author Share Posted March 13, 2009 Hi Micro, i'm afraid I don't get it... where should this sit? $query2 = "SELECT * from Answers where QID = '".$FormID[$count]."'"; $result2 = getResults($query2); while ($line2 = mysql_fetch_assoc($result2)) { extract($line2); echo("<span class='style2'>".$Answer." | </span>"); echo("<span class='style1'>".$Count." | </span><br>"); } I'm afraid it's still adding the * to the end of the numbers, but I want it to NOT add a * to the end of the last figure.. So, It would return 7*4 not 7*4* Any help would be greatly appreciated! Thanks, Link to comment https://forums.phpfreaks.com/topic/149253-really-simple-for-non-thickos-like-me/#findComment-783802 Share on other sites More sharing options...
MiCR0 Posted March 13, 2009 Share Posted March 13, 2009 ok then u just remove the last char of the string $piearray = substr($piearray, 0, -1); Link to comment https://forums.phpfreaks.com/topic/149253-really-simple-for-non-thickos-like-me/#findComment-783807 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.