Notes
![]() ![]() Notes - notes.io |
//Database connection
$config['base_url']='http://localhost/AWEc7181439/';
$db['hostname'] = 'localhost';
$db['username'] = 'root';
$db['password'] = '';
$db['database'] = 'mybaseofdata';
$db['dbdriver'] = 'mysql';
$mysqli = new mysqli($db['hostname'],$db['username'],$db['password'], $db['database']);
//Tell the browser what kind of file is come in
header("Content-Type: image/jpeg");
//execute the SQL query and return records
$result = mysqli_query($mysqli, "SELECT * FROM graph_results");
$num_poller = mysqli_num_rows($result);
$total_votes = 0;
//fetch the data from the database
while ($row = mysqli_fetch_assoc($result)) {
$total_votes += $row{'num_votes'};
//calculating total number of votes
}
//nulling the pointer $result
mysqli_data_seek($result, 0);
$font = 'arial.ttf';
//Set starting point for drawing
$y = 50;
//Specify constant values
$width = 700;
//Image width in pixels
$bar_height = 20;
//Bars height
$height = $num_poller * $bar_height * 1.5 + 70;
//Calculating image height
$bar_unit = ($width - 400) / 100;
//Distance on the bar chart standing for 1 unit
//Create the image resource
$image = ImageCreate($width, $height);
//We are making four colors, white, black, blue and red
$white = ImageColorAllocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 0, 0, 0);
$red = ImageColorAllocate($image, 255, 0, 0);
$blue = ImageColorAllocate($image, 0, 0, 255);
//Create image background
ImageFill($image, $width, $height, $white);
//Draw background shape
ImageRectangle($image, 0, 0, $width - 1, $height - 1, $black);
//Output header
ImageString($image, 16, $width / 3 + 50, $y - 20, 'Poll Results', $black);
while ($row = mysqli_fetch_object($result)) {
if ($total_votes > 0)
$percent = intval(round(($row -> num_votes / $total_votes) * 100));
else
$percent = 0;
//Output header for a particular value
imagestring($image, 12, 10, $y + ($bar_height / 2), $row -> book_type, $black);
//Output percentage for a particular value
imagestring($image, 12, 170, $y + ($bar_height / 2), $percent . '%', $red);
$bar_length = $percent * $bar_unit;
//Draw a shape that corresponds to 100%
imagerectangle($image, $bar_length + 221, $y - 2, (220 + (100 * $bar_unit)), $y + $bar_height, $black);
//Output a bar for a particular value
imagefilledrectangle($image, 220, $y - 2, 220 + $bar_length, $y + $bar_height, $blue);
//Output the number of votes
imagestring($image, 12, 250 + 100 * $bar_unit, $y + ($bar_height / 2), $row -> num_votes . ' votes cast.', $black);
//Going down to the next bar
$y = $y + ($bar_height * 1.5);
}
//Output the newly created image in jpeg format
imagejpeg($image);
//Free up resources
imagedestroy($image);
?>
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team