PHP - Moved: Creating Dynamic Images
This topic has been moved to Miscellaneous.
http://www.phpfreaks.com/forums/index.php?topic=342341.0 Similar TutorialsHello guys. I'm kinda new to PHP, I've been understanding everything so far. I have trouble with "imagestring" What I want is to query a row in MySQL. I want to display some of that info in the image. It's not working properly. Here's the code: <?php $imagepath="css/images/dog.jpg"; $image=imagecreatefromjpeg($imagepath); $imgheight=imagesy($image); $color=imagecolorallocate($image, 255, 255, 255); include("config.php"); $result = mysql_query("SELECT * FROM playerinfo WHERE Level > 0 ORDER BY Level DESC", $connect); while($myrow = mysql_fetch_row($result)) { // Not working properly. imagestring($image, 5, 50, $imgheight-50, $myrow[0], $color); } // This line works like it should: //imagestring($image, 5, 50, $imgheight-50, "Using it like this works!", $color); header('Content-Type: image/jpeg'); imagejpeg($image); ?> Any help will be GREATLY appreciated it. Thanks! This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=357949.0 Hi Everyone I found some code to decrease the writing of $_POST variables especially on big forms, but I cannot seem to get it to work: I am trying to get the $_POST variables from this: Code: [Select] <?php $callsign = $_POST['mf_callsign']; $surname = $_POST['mf_surname']; $firstnames = $_POST['mf_firstnames']; $knownas = $_POST['mf_knownas']; $rsaid = $_POST['mf_rsaid']; $birthdate = $_POST['mf_birthdate']; //more code [code] to this (see //Create $_POST Variables section) [code] <?php //Initailise Database first mysql_connect ("localhost", "***", "***") or die ('I cannot connect to the database because: ' .mysql_error()); mysql_select_db ("***"); ========================= //Create $_POST Variables foreach($_POST as $inputKey=>$inputValue): //find all form fields starting with 'mf_' if((strstr($inputKey,'mf_') === true)): $inputKey = mysql_real_escape_string($inputValue); endif; endforeach; ========================= //Then do the Insert into the Table $query="INSERT INTO personal_details (callsign, surname, firstnames, knownas, rsaid, birthdate)Values ('$mf_callsign', '$mf_surname', '$mf_firstnames', '$mf_knownas', '$mf_rsaid', '$mf_birthdate')"; mysql_query($query) or die ('Error Inserting Data into Database'); //If Insert Successful, Goto next Form header("Location: contactdetails.html"); die; ?> The //Create $_POST Variables section is not correct as it is not setting the variables correctly. If I go back to the old way and use that ($callsign = $_POST['mf_callsign'] it inserts no problem. What Am I doing wrong? Regards Allen Hello,
I have this very frustrating problem I'm trying to make a dynamic table with only 5 columns per row. So every 5 items, I need a new row. I have tried many different examples with no success. What is the best way to approach this? Here is what I am working with, this doesn't show what I have tried, just what I am working with at the moment which of course, just outputs it one column per row. http://www.mesquitew.../inc-legend.php // Lets parse the data $entries = simplexml_load_file($data); if(count($entries)): //Registering NameSpace $entries->registerXPathNamespace('prefix', 'http://www.w3.org/2005/Atom'); $result = $entries->xpath("//prefix:entry"); foreach ($result as $entry): $event = $entry->children("cap", true)->event; // Set the alert colors for the legend include ('../inc-NWR-alert-colors.php'); // Lets creat some styles for the list $spanStyle = "background-color:{$alertColor};border:solid 1px #333;width:15px;height:10px;display:inline-block;'> </span><span style='font-size:12px;color:#555;"; $legend .= "<table>"; $legend .= "<tr>"; $legend .= "<td> <span style='$spanStyle'> $event</span></td>"; $legend .= "</tr>"; $legend .= "</table>"; endforeach; endif; echo $legend;-Thanks! Hi there,
I have a table in a MySQL database where I keep a list of user privileges. I am trying to create variables where the name of variable matches the privileges in the table.
This is also known as variable variables (I think).
EDIT (17/07/2014 04:02 PM): This might be a better way to describe what I'd like, so if the value from the table is admin_panel I'd like to dynamically create a variable with that name.
I have created a code so far, but all I seem to be getting is a list of Notice errors telling me that the variable is undefined. (I have supplied a list of errors a bit further down the post).
Here is the code:
<?php $host = "localhost"; $account = "***"; $password = "****"; $dbname = "****"; $connect = mysql_connect($host,$account,$password) or die("Unable To Connect"); $db = mysql_select_db($dbname,$connect) or die("Unable To Select DB"); $perm_query = "SELECT * FROM `privileges`"; $permission_query = mysql_query($perm_query); while($row = mysql_fetch_array($permission_query)) { $rows[] = $row; } foreach($rows as $row) { ${$row['privilege']}; } ?>The list of errors: Notice: Undefined variable: admin_panel in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: create_user in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: edit_user in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: delete_user in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: create_group in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: edit_group in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: delete_group in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: view_log in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: log_settings in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: password_change in C:\xampp\htdocs\DynamicVariables.php on line 20 Thanks Edited by chrisrulez001, 17 July 2014 - 10:05 AM. i've to populate google charts with dynamic data. the data looks llike. +----+-------+---------+-------+-----------+---------+------+ | id | name | physics | maths | chemistry | biology | sst | +----+-------+---------+-------+-----------+---------+------+ | 1 | Name1 | 10 | 25 | 35 | 42 | 62 | | 2 | Name2 | 80 | 45 | 45 | 45 | 25 | | 3 | Name3 | 63 | 25 | 63 | 36 | 36 | | 4 | Name4 | 82 | 36 | 75 | 48 | 42 | | 5 | Name5 | 45 | 45 | 78 | 25 | 24 | | 6 | Name6 | 36 | 36 | 15 | 75 | 36 | | 7 | Name7 | 99 | 45 | 24 | 24 | 45 | | 8 | Name8 | 45 | 85 | 85 | 85 | 96 | +----+-------+---------+-------+-----------+---------+------+ i have to create google charts based on this such that # namewise - such that when i select a name it displays all subject marks of that particular name in a column chart #markswise - when i select a subject, it displays all the names with marks in that particular subject. conisdiering that data may be added and i've to accumulate that also, for namewise i did // chart.php <?php include("connection.php"); $query = "SELECT name FROM csv GROUP BY name DESC"; $statement = $connect->prepare($query); $statement->execute(); $result = $statement->fetchAll(); ?> <!DOCTYPE html> <html> <head> <title>Google charts</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> </head> <body> <br /><br /> <div class="container"> <div class="panel panel-default"> <div class="panel-heading"> <div class="row"> <div class="col-md-9"> <h3 class="panel-title">Student Wise Marks Data</h3> </div> <div class="col-md-3"> <select name="name" class="form-control" id="name"> <option value="">Select Student</option> <?php foreach($result as $row) { echo '<option value="'.$row["name"].'">'.$row["name"].'</option>'; } ?> </select> </div> </div> </div> <div class="panel-body"> <div id="chart_area" style="width: 1000px; height: 620px;"></div> </div> </div> </div> </body> </html> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <script type="text/javascript"> google.charts.load('current', {packages: ['corechart', 'bar']}); google.charts.setOnLoadCallback(); function load_student_data(name, title) { var temp_title = title + ' '+name+''; $.ajax({ url:"fetch.php", method:"POST", data:{name:name}, dataType:"JSON", success:function(data) { drawStudentwiseChart(data, temp_title); } }); } function drawStudentwiseChart(chart_data, chart_main_title) { var jsonData = chart_data; var data = new google.visualization.DataTable(); data.addColumn('number', 'Physics'); data.addColumn('number', 'Maths'); data.addColumn('number', 'Chemistry'); data.addColumn('number', 'Biology'); data.addColumn('number', 'SST'); $.each(jsonData, function(i, jsonData){ var Physics = jsonData.Physics; var Maths = jsonData.Maths; var Chemistry = jsonData.Chemistry; var Biology = jsonData.Biology; var SST = jsonData.SST; data.addRows([[Physics,Maths,Chemistry,Biology,SST]]); }); var options = { title:chart_main_title, hAxis: { title: "Subjects" }, vAxis: { title: 'Percentage' } }; var chart = new google.visualization.ColumnChart(document.getElementById('chart_area')); chart.draw(data, options); } </script> <script> $(document).ready(function(){ $('#name').change(function(){ var name = $(this).val(); if(name != '') { load_student_data(name, 'Student wise marks data'); } }); }); </script> and in order to fetch data // fetch.php <?php //fetch.php include('connection.php'); if(isset($_POST["name"])) { $query = " SELECT * FROM csv WHERE name = '".$_POST["name"]."' ORDER BY id ASC "; $statement = $connect->prepare($query); $statement->execute(); $result = $statement->fetchAll(); foreach($result as $row) { $output[] = array( 'Physics' => $row["Physics"], 'Maths' => $row["Maths"], 'Chemistry' => $row["Chemistry"], 'Biology' => $row["Biology"], 'SST' => $row["SST"], ); } echo json_encode($output); } ?> it diplays a blank page. however when i play with singular values i.e one subject at a time it displays fine Edited March 19, 2019 by zetastreakI want to create an image using pre-existing image files. I want to use more than one file, otherwise I would use the imagecreatefromjpg function. What function should I use to create an image using a for statement to determine how many of each image is being displayed in the new image? Hello all I have a requirement to create images mostly made up of rectangles circles and squares etc I have discovered imageline but is there anything a bit more exspansive? Hi All, i am trying to Generate a image dynamically. Up to here i am able to do it . But when i give any echo statement with this its not working.. Here is my code pls help me in this <?php // Create a 55x30 image $im = imagecreatetruecolor(79, 79); $unknow = imagecolorallocate($im, 0, 255, 255); $white = imagecolorallocate($im, 255, 255, 255); // Draw a white rectangle imagefilledrectangle($im, 4, 4, 75, 25, $unknow); imagefilledrectangle($im, 4, 29, 75, 50, $unknow); imagefilledrectangle($im, 4, 54, 75, 75, $unknow); // Save the image echo 'hi hello'; header("Content-type: image/png"); //imagepng($im, './imagefilledrectangle.png'); imagepng($im); imagedestroy($im); ?> Thanks in advance. So, We are trying to create a animation using the gifs in a directory by using the first 10 images. We just cannot figure out how to do the animation.. needs to have a 3 second delay between each frame Heres the code at the moment. Which creates the starting images and also sorts the images in the directory by time.. <?php $time = date("YmdHis"); $handle_data = file_get_contents('http://www.bungie.net/Stats/Halo3/Nightmap.ashx'); $img = new Imagick(); $img->readImageBlob($handle_data); $img->writeImage('nightmap/'.$time.'.gif'); foreach (glob('nightmap/*.gif') as $f) { # store the image name $list[] = $f; } sort($list);# sort is oldest to newest, $gif_0 = array_pop($list); $gif_1 = array_pop($list); $gif_2 = array_pop($list); $gif_3 = array_pop($list); $gif_4 = array_pop($list); $gif_5 = array_pop($list); $gif_6 = array_pop($list); $gif_7 = array_pop($list); $gif_8 = array_pop($list); $gif_9 = array_pop($list); ?> Hi all, Could someone help me add a thumbnail script to the below that works on scaling it down to 200px x 133px. I guess it is not that hard. <?php $destination='aircraft/'.$reg."1.jpg"; $temp_file = $_FILES['image']['tmp_name']; move_uploaded_file($temp_file,$destination); ?> Thanks This is so hard. :/ I have the following code: Code: [Select] <?php $signature = @imagecreate(350,60); $image_generate = imagecolorallocate($signature,84, 84, 84); $red = imagecolorallocate($signature,255,36,0); imagefilledrectangle($signature, 0, 1, 150, 30, $red); header("Content-type:image/png"); imagepng($signature); ?> How can I get the rectangle in the center? http://zchighscores.99k.org/image.php I don't really know what to change to get it in the right coordinates. :/ This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=306771.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=333152.0 This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=342882.0 This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=356776.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=333014.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=351100.0 This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=321416.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=342456.0 |