Jump to content

Echo * the number of rows a query returns?


br3nn4n

Recommended Posts

Just making some changes to my Ajax poll, doing some stuff with GD to create bars.

 

Here's where I'm stuck: I want to echo out an asterisk (*) the number of times a choice has votes. From there I can just replace each one with a small image or whip up something using GD to create a bar to show the results.

 

I can't figure out how I would have it output a character a certain number of times though. I'm thinking possibly do while($r = mysql_fetch_array($q) {

for ($i=0,$i < mysql_num_rows($q),$i++) { echo "*"; }}

 

Would this work? Or else how should it be done?

Link to comment
https://forums.phpfreaks.com/topic/139087-echo-the-number-of-rows-a-query-returns/
Share on other sites

Here are two ways of creating a string containing a specified number of the same character:

<?php
$votes = range(10,50);
shuffle($votes);
$rnd = array_slice($votes,0,10);
foreach ($rnd as $num)
     echo $num . ': '. str_pad('',$num,'*') . "\n";
echo "------------------------\n";
foreach ($rnd as $num)
   echo $num . ': ' . implode('',array_fill(0,$num,'*')) . "\n";
?>

 

Ken

 

 

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.