Jump to content

Really simple for non-thicko's like me!!


railanc4309

Recommended Posts

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

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,

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.