PHP - Display Query Result In A User Friendly Format, With Each Class In Its Own Table
OK, Here is the code
$sql = "SELECT TrialListing.listingID AS Trial, TrialClass.classID AS Class, place.place_name AS Place, CONCAT_WS( ' ', pedigree.pretitle, pedigree.`Name`) AS Hound, CONCAT_WS( ' ', ped2.pretitle, ped2. NAME )AS Sire, CONCAT_WS( ' ', ped3.pretitle, ped3. NAME )AS Dam, pedigree.Breeder, pedigree.`Owner`, CASE WHEN placement.place_id < 5 THEN TRUNCATE(TrialClass.number_of_entrants / placement.place_id,2) WHEN placement.place_id = 5 THEN '' ELSE 0 END AS Score FROM TrialListing Left Join TrialClass ON TrialListing.listingID = TrialClass.listingID JOIN placement ON placement.event_id = TrialClass.trialClassID JOIN pedigree ON pedigree.PedigreeId = placement.hound_id LEFT OUTER JOIN pedigree AS ped2 ON pedigree.SireId = ped2.PedigreeId LEFT OUTER JOIN pedigree AS ped3 ON pedigree.DamId = ped3.PedigreeId LEFT JOIN place ON place.place_id = placement.place_id WHERE TrialListing.listingID = 11 ORDER BY Class, FIELD(place.place_id, '1', '2', '3', '4', '0') "; // Database Query $result = mysql_query("$sql"); // Database Query result $num_rows = mysql_num_rows($result); // Starts the table echo "<table class=\"clubList\">\n <tr> <th>trialID</th> <th>ClassID</th> <th>Place</th> <th>Hound</th> <th>Sire</th> <th>Dam</th> <th>Score</th> </tr>"; // Create the contents of the table. for( $i = 0; $i < $row = mysql_fetch_array($result); $i++){ echo "<tr>\n" ."<td>".$row["Trial"]."</td>\n" ."<td>".$row["Class"]."</td>\n" ."<td>".$row["Place"]."</td>\n" ."<td>".$row["Hound"]."</td>\n" ."<td>".$row["Sire"]."</td>\n" ."<td>".$row["Dam"]."</td>\n" ."<td>".$row["Score"]."</td>\n" ."</tr>";} echo "</TABLE>"; Here is the output, I added the TrialID & ClassID for informational purposes, they do not need to be displayed in the live table. trialID ClassID Place Hound Sire Dam Score 11 1 1st Eaton Brook Tug Hill Tatonka Eaton Brook Hickety Hawk Eaton Brook Gunner's Beulah 43.00 11 1 2nd FC North Bend Igloo FC DFJ Murphy White IFC Brad-Ju's Bella Donna 21.50 11 1 3rd FC North Bend Igloo FC DFJ Murphy White IFC Brad-Ju's Bella Donna 14.33 11 1 4th Rail Road Spike VI Elwell's Mike Elwell's Hannah 10.75 11 1 NBQ FC Fish Creek Spike Fish Creek Bull II Fish Creek Susie [H849395] 11 2 1st Enman Hill Sweet Poppy FTCH Straight Arrow Lucky of Coos 32.00 11 2 2nd Fishflakes Penny At Harehaven FTCH Jill's Fair-Isle Spud FTCH Millbridge Brownie 16.00 11 2 3rd Line Elm Flakers IFC Flakers Rex IFC Line Elm Ginger 10.66 11 2 4th FTCH Fareast Mookie FTCH Mellowrun Sly FTCH Cape Breton Maude 8.00 11 2 NBQ FTCH Mellowrun Sly Mellowrun Skylighter FTCH Mellowrun Becka 11 3 1st Bojangle V Lee Otworth Half Acre's Cocoa Candy 23.00 11 3 2nd Gay Doll Gay Roll II Gay Idol 11.50 11 3 3rd Bruce's Blue Lady FC Kilsock's Blue Creek Bart Bishopville's Zippy 7.66 11 3 4th FC Pearson Creek Barbin FC Pearson Creek Barbarian FC B-Line Stubby 5.75 11 3 NBQ Sims Creek Cricket Ronnie Joe Sims Creek Tiny 11 4 1st FTCH Fareast Mookie FTCH Mellowrun Sly FTCH Cape Breton Maude 26.00 11 4 2nd FTCH Mellowrun Sly Mellowrun Skylighter FTCH Mellowrun Becka 13.00 11 4 3rd Fishflakes Penny At Harehaven FTCH Jill's Fair-Isle Spud FTCH Millbridge Brownie 8.66 11 4 4th Enman Hill Sweet Poppy FTCH Straight Arrow Lucky of Coos 6.50 11 4 NBQ Line Elm Flakers IFC Flakers Rex IFC Line Elm Ginger Below is what I would like to generate. How do I word or nest the proper PHP code/loops to accomplish this? ClassID Place Hound Sire Dam Score 1st Eaton Brook Tug Hill Tatonka Eaton Brook Hickety Hawk Eaton Brook Gunner's Beulah 43.00 2nd FC North Bend Igloo FC DFJ Murphy White IFC Brad-Ju's Bella Donna 21.50 3rd FC North Bend Igloo FC DFJ Murphy White IFC Brad-Ju's Bella Donna 14.33 4th Rail Road Spike VI Elwell's Mike Elwell's Hannah 10.75 NBQ FC Fish Creek Spike Fish Creek Bull II Fish Creek Susie [H849395] ClassID Place Hound Sire Dam Score 1st Enman Hill Sweet Poppy FTCH Straight Arrow Lucky of Coos 32.00 2nd Fishflakes Penny At Harehaven FTCH Jill's Fair-Isle Spud FTCH Millbridge Brownie 16.00 3rd Line Elm Flakers IFC Flakers Rex IFC Line Elm Ginger 10.66 4th FTCH Fareast Mookie FTCH Mellowrun Sly FTCH Cape Breton Maude 8.00 NBQ FTCH Mellowrun Sly Mellowrun Skylighter FTCH Mellowrun Becka ClassID Place Hound Sire Dam Score 1st Bojangle V Lee Otworth Half Acre's Cocoa Candy 23.00 2nd Gay Doll Gay Roll II Gay Idol 11.50 3rd Bruce's Blue Lady FC Kilsock's Blue Creek Bart Bishopville's Zippy 7.66 4th FC Pearson Creek Barbin FC Pearson Creek Barbarian FC B-Line Stubby 5.75 NBQ Sims Creek Cricket Ronnie Joe Sims Creek Tiny ClassID Place Hound Sire Dam Score 1st FTCH Fareast Mookie FTCH Mellowrun Sly FTCH Cape Breton Maude 26.00 2nd FTCH Mellowrun Sly Mellowrun Skylighter FTCH Mellowrun Becka 13.00 3rd Fishflakes Penny At Harehaven FTCH Jill's Fair-Isle Spud FTCH Millbridge Brownie 8.66 4th Enman Hill Sweet Poppy FTCH Straight Arrow Lucky of Coos 6.50 NBQ Line Elm Flakers IFC Flakers Rex IFC Line Elm Ginger Similar TutorialsFirst off, let me say that this will not be a public use site. We want to create a site that allows us to run queries in our database; this way we don't need to log into the MySQL server when ever we want to run a query. Basically, I am trying to create something as simple as a form with a text-input and a submit button. In this text-input, we will write a query (such as SELECT * FROM xxxx). When we hit submit, we would like to have the MySQL table printed out in a large textbox below. Our database has multiple tables, so something that works across the entire database seamlessly is key. Has anyone ever made anything like this? Is there another way to go about this? We really just want an easy way to run queries on the go. Thanks in advance to anyone who replies! Hi, I've always used PHP code in my websites in a procedural manner as I come from a html/css background. Now that I want to do projects with more complexity I'm thinking I need to approach development in a more Object Oriented fashion. My question is more a theoretical one. I'm creating a User class and I'm not sure on what is the best practise for putting my functions etc. and where to call them. My project will have 2 different users (Admin & End User) so is it correct to say that the User class should encapsulate all the functions of both of these users ? By that I mean create/delete/modify user, login & change password/forgotten password functionality rather than having a seperate Login class Should I only call the database functions within these methods of the user class as opposed to calling them on the php page where the form data is posted ? For example, if a user logins in and when the form data is posted I currently open a connection, validate data, run the query. In an OO approach would I have just one User class method thats relevant to a particular page functionality ? Say, in pseudo code, for handling a login request loginRequest.php Code: [Select] include User class try { create new user User(); User::login(); } catch Exception() and should my User class look something like this class.User.php Code: [Select] include DBase class class User { var name, var email, var password, function validateInput (email, password) { if (!valid input) throw Exception else return true } function login (email, password){ try { database connection validateInput(); sql to see if user exists and login } catch Exception } } Apologies for this being a bit long winded! thanks tmfl Sorry for the beginner question, here I'm trying to retrieve data from the database and display it in the table format. But only table headers are printed, and not the actual values. The count variable is echoing 2 saying that data is present and correctly retrieved. Can anyone help?
<?php include 'connect.php'; error_reporting(E_ALL ^ E_DEPRECATED); error_reporting(E_ERROR | E_PARSE); $sql="SELECT * FROM `resources` as r INNER JOIN `project_resources` as pr ON r.res_id =pr.res_id WHERE project_id='$_POST[project_id]'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($result === FALSE) { die(mysql_error()); } echo "$count"; echo '<table> <tr> <th>Resource ID</th> <th>Resource Name</th> <th>Email</th> <th>Phone Number</th> <th>Reporting Manager</th> <th>Role</th> <th>Designation</th> </tr>'; while ($row = mysql_fetch_array($result)) { echo ' <tr> <td>'.$row['res_id'].'</td> <td>'.$row['res_name'].'</td> <td>'.$row['email'].'</td> <td>'.$row['phone_number'].'</td> <td>'.$row['reporting_manager'].'</td> <td>'.$row['role'].'</td> <td>'.$row['designation'].'</td> </tr>'; } echo ' </table>'; ?> Edited by mac_gyver, 22 September 2014 - 07:25 AM. code tags please I´ve reached to
<?php require_once('Connections/conexxion.php'); ?> <?php mysql_select_db($database_conexxion, $conexxion); $query_consulta = "SELECT venta,compra,taller,regula_mas,regula_menos,movimiento.id_item,sum(compra+regula_mas-venta-taller-regula_menos) as stock, cilindro, esfera FROM movimiento join item on item.id_item=movimiento.id_item join rx on rx.id_rx=item.id_rx join cilindro on cilindro.id_cil=rx.id_cil join esfera on esfera.id_esf=rx.id_esf GROUP BY movimiento.id_item ORDER BY esfera desc, cilindro desc"; $consulta = mysql_query($query_consulta, $conexxion) or die(mysql_error()); $row_consulta = mysql_fetch_assoc($consulta); $totalRows_consulta = mysql_num_rows($consulta); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>test</title> </head> <body> <?php echo "<table align=center>"; $columnes = 10; # Número de columnas (variable) if (($rows=mysql_num_rows($consulta))==0) { echo "<tr><td colspan=$columnes>No hay resultados en la BD.</td></tr> "; } else { echo "<tr><td colspan=$columnes>$rows Resultados </td></tr>"; } for ($i=1; $row = mysql_fetch_row ($consulta); $i++) { $resto = ($i % $columnes); # Número de celda del <tr> en que nos encontramos if ($resto == 1) {echo "<tr>";} # Si es la primera celda, abrimos <tr> echo "<td>$row[1]</td>"; if ($resto == 0) {echo "</tr>";} # Si es la última celda, cerramos </tr> } if ($resto <> 0) { # Si el resultado no es múltiple de $columnes acabamos de rellenar los huecos $ajust = $columnes - $resto; # Número de huecos necesarios for ($j = 0; $j < $ajust; $j++) {echo "<td> </td>";} echo "</tr>"; # Cerramos la última línea </tr> } mysql_close($connexion); echo "</table>"; ?> </body> </html> <?php mysql_free_result($consulta); ?>it "works", but results doesn´t start at number 1 but number 2 anyways, The intent of this table is to show the stock of a product, a lens, that has a range of Rx, we use to see this range this way, and show the stock this way would be very productive, but I can´t figure out how to achive it, any sugestion?? Edited by gralfitox, 16 December 2014 - 06:45 AM. Hello,
I am trying to display the data from two tables with proper format. But Its not happening
Here is my 1st table - orders
2.PNG 10.12KB
0 downloads
and my 2nd table - order_line_items
1.PNG 14.92KB
0 downloads
I want to display like this
3.PNG 4.03KB
0 downloads
Here is my code
$query = $mysqli->query("SELECT orders.order_id, orders.company_id, orders.order_for, order_line_items.order_id, order_line_items.item, order_line_items.unit,SUM(order_line_items.unit_cost * order_line_items.quantity) AS 'Total', order_line_items.tax from orders INNER JOIN order_line_items ON orders.order_id = order_line_items.order_id where orders.order_quote = 'Order' GROUP BY order_line_items.id"); ?> <table id="dt_hScroll" class="table table-striped"> <thead><tr> <th>Order ID</th> <th>Company</th> <th>Contact Person</th> <th>Products</th> <th>Total</th> </tr> </thead> <tbody> <?php while($row = $query->fetch_array()) { ?> <tr> <td><?php echo $row['order_id']; ?></td> <td><?php echo $row['company_id']; ?></td> <td><?php echo $row['contact_person'] ?></td> <td><?php echo $row['item']; ?></td> <td><?php echo $row['Total']; ?> %</td> </tr> <?php }But here order ID, Company ID, Contact Person are also repeating thrice with item in order_line_items table Please suggest me how to do this can anione help me to display imageid along wid each image in table format...here is my code which takes image from user....n d id can b anithing i mean its ur choice u can start wid first image by giving it imageid 1 n can continue til d image ends <?php mysql_connect("localhost","root",""); @mysql_select_db(proj) or die( "Unable to select database"); $query="SELECT * FROM form"; $result=mysql_query($query); //define a maxim size for the uploaded images in Kb define ("MAX_SIZE","100"); //This function reads the extension of the file. It is used to determine if the file is an image by checking the extension. function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } //This variable is used as a flag. The value is initialized with 0 (meaning no error found) //and it will be changed to 1 if an errro occures. //If the error occures the file will not be uploaded. $errors=0; //checks if the form has been submitted if(isset($_POST['Submit'])) { //reads the name of the file the user submitted for uploading $image=$_FILES['image']['name']; //if it is not empty if ($image) { //get the original name of the file from the clients machine $filename = stripslashes($_FILES['image']['name']); //get the extension of the file in a lower case format $extension = getExtension($filename); $extension = strtolower($extension); //if it is not a known extension, we will suppose it is an error and will not upload the file, //otherwise we will do more tests if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { //print error message echo '<h1>Unknown extension!</h1>'; $errors=1; } else { //get the size of the image in bytes //$_FILES['image']['tmp_name'] is the temporary filename of the file //in which the uploaded file was stored on the server $size=filesize($_FILES['image']['tmp_name']); //compare the size with the maxim size we defined and print error if bigger if ($size > MAX_SIZE*1024) { echo '<h1>You have exceeded the size limit!</h1>'; $errors=1; } //we will give an unique name, for example the time in unix time format $image_name=time().'.'.$extension; //the new name will be containing the full path where will be stored (images folder) $newname="upload/".$image_name; //we verify if the image has been uploaded, and print error instead $copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied) { echo '<h1>Copy unsuccessfull!</h1>'; $errors=1; }}}} //If no errors registred, print the success message if(isset($_POST['Submit']) && !$errors) { $sql=mysql_query("INSERT INTO image (img) VALUES('$newname')"); if($sql) { echo "<h1>File Uploaded Successfully! Try again!</h1>"; } } ?> <!--next comes the form, you must set the enctype to "multipart/frm-data" and use an input type "file" --> <form name="newad" method="post" enctype="multipart/form-data" action=""> <table> <tr><td><input type="file" name="image"></td></tr> <tr><td><input name="Submit" type="submit" value="Upload image"></td></tr> </table> <p><a href="resizeimg.php">resize the images </a></p> </form> <p> </p> here is my code for displaying d images I am retrieving a rowfrom a table and when I post the row variable it doesnt read it. ___ $query = "SELECT * FROM $tbl_name"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['name']; echo "<br />"; $postinfo = 'p_doctor_name=' . $row .'&p_name_type=A&p_search_type=BEGINS'; __ This outputs p_entity_name=&p_name_type=A&p_search_type=BEGINS Note that it is missing $row Do I need to put it in an array? I have a simple mysql database holding information about an image upload including its 'name' and 'date uploaded' [current_timestamp()] to a folder 'image' I then display it into a table using the php ‘foreach’ facility. I want the date to be displayed in the ‘dd/mm/yyyy’ format. not the default yyyy/mm/dd. Here is the relevant code <?php $conn = mysqli_connect("localhost", "root", "", "dbname"); $results = mysqli_query($conn, "SELECT * FROM tablename"); $image = mysqli_fetch_all($results, MYSQLI_ASSOC); ?> <?php foreach ($image as $user): ?> <td><p>NAME</p><?php echo $user['name']; ?></td> <td><p>COMMENT</p><?php echo $user['comment']; ?></td> <td><p>DATE</p><?php echo $user['date']; ?></td> What do I need to do? THANKS- Warren Alright, I looked though the read me's, went over the FAQ's... Think it is time to post...
So, this lump is what I got from going though google and piecing together the bits that looked good.
<?php $db_host = "****"; $db_user = "****"; $db_pwd = "****"; $database = "****"; $table = "****"; $query = "SELECT * FROM {$table}"; $conn = mysqli_connect($db_host, $db_user, $db_pwd, $database); $result = mysqli_query($conn,$query) or trigger_error($query . ' - has encountered an error at:<br />' . mysqli_error($conn)); $fields = mysqli_fetch_fields($conn); $field_count = mysqli_num_fields($conn); echo '<table border="1" style="width:100%">' . "\n" . '<tr>'; $i = 0; foreach($fields as $field) { if(++$i == 1) { echo '<th colspan="' . $field_count . '">' . $field->table . '</th></tr><tr>'; } echo "\n" . '<th>' . $field->name . '</th>'; } echo '</tr>'; while($row = mysqli_fetch_row($result)) { echo '<tr><td>' . implode('</td><td>' , $row) . '</td></tr>'; } echo '</table>'; ?>The goal is to display the table and conditionally format the contents. Let's forget about the conditional part (thinking if/than but don't know how I'm going to do that yet) and focus on the key problem: displaying the table. I have tested this code. It works...to a point. it displays the table and its contents but no headers. I know my issue is in line 20 and 22 but I can not for the life of me figure it out. If it is stupidly easy (for you) please remember that I am not a coder. At best I am a scripter when it comes to linux. I am over my head on this stuff. Thank you all for any help you can give me Edited by TheAlmightyOS, 18 November 2014 - 03:30 PM. Dear everyone, I am reasonably new to php, so there is a chance that what I am asking for may exceed my grasp. Nevertheless I'd like to try: Is it possible to let the user choose (by using a drop down listbox for instance) which table from a database to display on a page? And/or which database to display on a page? Background information: I'm working on a website for my chess club. I've already got a working page (html,css) with a table of the standings (mysql, php) of the latest round (with position number, name, points, wins, losses, etc). By clicking on the column header, it sorts the respective column. What I'd finally like to do is let the user choose to display a different round (table), or even a different season (database). I could make a seperate page for each round, but I'd like to know if there's a more elegant way to do this by using only one page and one or more databases. Thanks in advance for any tips and best wishes from The Netherlands, Wouter. Hello, I know this should be pretty simple to figure out, but everything I try is giving me absolutely no results. I have a mysql query selecting columns from my database and returning results. I have the results printing out right now, so I can see that this part is working. All I want to do is take the results and put them into a table to display on my page. Basically, take what's in the database table and copy it to a table I can put on the web. FYI I am using sourcerer so the "connect" code is taken care of for me in the "JFactory" bit of code. Here is the first part of my code, selecting the information from the database. {source} <?php $db = JFactory::getDbo(); $query = $db -> getQuery(true); $query -> SELECT($db -> quoteName(array('first_dept_name', 'last_name', 'dept', 'position', 'phone_num'))); $query -> FROM ($db -> quoteName('#__custom_contacts')); $query -> ORDER ('first_dept_name DESC'); $query -> WHERE ($db -> quoteName('contact_category')."=".$db -> quote('YTown Employees')); $db -> setQuery($query); $results = $db -> loadObjectList(); print_r($results); Here is where I am trying to print the results into a table. I got this code directly from a PHP book, but I am getting nothing at all returned back to me. I get table headers, but no data. <?php echo "<table><tr><th>Name</th><th>Department</th></tr>"; while ($row = mysqli_fetch_array ($result)){ echo "<tr>"; echo "<td>".$row['last_name']."</td>"; echo "<td>".$row['dept']."</td>"; echo "</tr>"; } echo "</table>"; ?> {/source} I have a 3-tables I have the following code that searches my database and displays results in a table: $fields = array("field1", "field2", "field3") $cols = implode (', ', $fields); $result= mysql_query (" SELECT $cols FROM tablename WHERE ................... "); if (!$result) {die('Could not search database: ' . mysql_error());} if($result) { if(mysql_num_rows($result) == 0) { return "Sorry. No records found in the database"; } else { $table = "<table border='1' cellpadding='5' cellspacing='5'>"; while($arr = mysql_fetch_array($result, MYSQL_ASSOC)) { $table .= "\t\t<tr>\n"; foreach ($arr as $val_col) { $table .= "\t\t\t".'<td>'.$val_col.'</td>'."\n"; } $table .= "\t\t</tr>\n"; } $table .= "</table>"; echo $table; } mysql_free_result($result); } As you can see each of the MySQL table fields specified by $fields is displayed in a new column in the html table. I want to change this so that e.g. "field3" is displayed in a new row instead. So, instead of the html table looking like: | "field1-result1" | "field2-result1" | "field3-result1" | | "field1-result2" | "field2-result2" | "field3-result2" | | "field1-result3" | "field2-result3" | "field3-result3" | I want it to look like: | "field1-result1" | "field2-result1" | | "field3-result1" | | | "field1-result2" | "field2-result2" | | "field3-result2" | | | "field1-result3" | "field2-result3" | | "field3-result3" | | I guess this is quite straightforward, but I can't work it out! Pls help! Thanks. What are some common standards to writing a php class? One thing I think is a standard is using "Camel Case" (example): public function myFunctionName instead of using: public function my_function_name Is that true, and are there any others that you know about? I would like to hear what they are! Thanks! hi, i have made a website where people resgister their details of them and products. they have to enter the following details in form Name of company name of the product company address email id password mobile number contact and brief details about their company
user can then login with email id and pwd. now after login ..user will get a page where he can upload the photos of products images and their price, so now my question is that when he finishes uploading (|by clicking on upload button) the product images and price text box ..then on final uploaded webspage it should show all other things which he registerd before (company name , mobile number etc) along with images and price...hence the main question that user does not need to enter mobile and address while uploading images and filling proce ..but on the final page it should show mobile and address along with price and images..as user is not going to enter mobile and address again and again as he will have multiple products to upload.
Hello, I am using a tutorial script for generating a basic bar graph. I have attempted to convert this script into an object-oriented script. However, upon attempting to define the graph, it is not successfully generated. Here is my code: Code: [Select] <? class Graph { var $values; var $image; var $image_width = 450; var $image_height = 300; var $margin = 20; var $bar_size = 20; var $horizontal_lines = 20; var $bar_colour; var $border_colour; var $background_colour; var $line_colour; function CreateGraph() { $this->image = imagecreate($this->image_width, $this->image_height); } function SetSize($width, $height) { $this->image_width = $width; $this->image_height = $height; } function SetMargin($size) { $this->margin = $size; } function SetBarSize($size) { $this->bar_size = $size; } function SetHorLines($size) { $this->horizontal_lines = $size; } function HexConvert($rgb) { return array( base_convert(substr($rgb, 0, 2), 16, 10), base_convert(substr($rgb, 2, 2), 16, 10), base_convert(substr($rgb, 4, 2), 16, 10), ); } function SetColours($bars, $background, $border, $line) { // This is hex based, similar to CSS, it is converted by HexConvert $bars = $this->HexConvert($bars); $background= $this->HexConvert($background); $border= $this->HexConvert($border); $line = $this->HexConvert($line); $this->bar_colour = imagecolorallocate($this->image, $bars[0], $bars[1], $bars[2]); $this->background_colour = imagecolorallocate($this->image, $background[0], $background[1], $background[2]); $this->border_colour = imagecolorallocate($this->image, $border[0], $border[1], $border[2]); $this->line_colour =imagecolorallocate($this->image, $line [0], $line [1], $line [2]); } function DrawBorders() { imagefilledrectangle($this->image,1,1,$this->image_width-2,$this->image_height-2,$this->border_colour); imagefilledrectangle($this->image,$this->margin,$this->margin,$this->image_width-1-$this->margin,$this->image_height-1-$this->margin,$this->background_colour); } function DrawHorLines($horizontal_gap, $ratio) { for($i=1;$i<=$this->horizontal_lines;$i++) { $y = $this->image_height - $this->margin - $horizontal_gap * $i ; imageline($this->image, $this->margin, $y, $this->image_width - $this->margin, $y, $this->line_colour); $v = intval($horizontal_gap * $i / $ratio); imagestring($this->image, 0, 5, $y-5, $v, $this->bar_colour); } } function DrawBars($graph_height, $gap, $ratio) { for($i=0;$i< $total_bars; $i++) { list($key,$value)=each($this->values); $x1= $this->margin + $gap + $i * ($gap+$this->bar_size) ; $x2= $x1 + $this->bar_size; $y1 = $this->margin +$graph_height- intval($value * $ratio) ; $y2 = $this->image_height-$this->margin; imagestring($this->image,0,$x1+3,$y1-10,$value,$this->bar_colour); imagestring($this->image,0,$x1+3,$this->image_height-15,$key,$this->bar_colour); imagefilledrectangle($this->image,$x1,$y1,$x2,$y2,$this->bar_colour); } } function DrawGraph() { $graph_width=$this->image_width - $this->margin * 2; $graph_height=$this->image_height - $this->margin * 2; $total_bars = count($values); $gap = ($graph_width- $total_bars * $this->bar_width ) / ($total_bars +1); $this->DrawBorders(); $max_value=max($values); $ratio = $graph_height / $max_value; $horizontal_gap = $graph_height / $horizontal_lines; $this->DrawHorLines($horizontal_gap, $ratio); $this->DrawBars($graph_height, $gap, $ratio); } function OutputGraph() { header("Content-type:image/png"); imagepng($this->image); } } ?> I expect this to be my misunderstanding of how object orientated codes work. I'm also open to any suggestions for improvement. Edit: Here is the script where I use the class. Code: [Select] <? include "bargraph.class.php"; $graph = new Graph; $graph->SetSize(450, 300); $graph->CreateGraph(); $graph->SetMargin(20); $graph->SetBarSize(20); $graph->SetHorLines(20); $graph->SetColours("FFFFFF", "C0C0C0", "000000", "000000"); $graph->DrawGraph(); $graph->OutputGraph(); ?> Hello, I am creating a class which contains one private function that deals with connecting to a SQL Server and executing the sql that is passed in to that function. I have defined a class variable which is assigned the value of sqlsrv_query like so. $this->QueryResult = sqlsrv_query($conn,$sql); I have placed private $QueryResult at the top of my class. The other public methods call this private function to assign the result set to the class variable, the private method returns and then the public methods loop through the results array like so. while($row = sqlsrv_fetch_array($this->QueryResult)) .. but the while loop never gets entered. If I declare everything in the same method then it works, however there are going to be several public methods that will use this private method and I don't want to duplicate all the database coding. Hope someone can help Hello all. I am using a premade login script which has some very powerful function built in, the one I am looking at using is as follows:
/** * query - Performs the given query on the database and * returns the result, which may be false, true or a * resource identifier. */ function query($query){ return mysqli_query( $this->connection, $query); }The issue is, displaying the results. I call is via the following code: $database->query('SELECT LastName, Firstname FROM Patrons WHERE LastName = "Delude"');But I have no idea how to display it. I have attempted to echo it out, but I get the following error in the logs: PHP Catchable fatal error: Object of class mysqli_result could not be converted to string For some reason the line commented // executes unexectedly does exactly that Any ideas why? if ($_POST['user'] == null){ $errors[] = 'An Interviewer ID is Required'; }elseif ($_POST['task'] != 'receipting' || $_POST['task'] != 'dataentry'){ $errors[] = 'Invalid Task'; // EXECUTES UNEXPECTEDLY } if (!empty($errors)){ print_LoginForm($errors); } Code: [Select] echo "</b><select name='task'>\n"; echo "<option value='receipting'>Receipting</option>\n"; echo "<option value='dataentry'>Data Entry</option>\n"; echo "</select>\n"; I would appreciate your assistance, there are tons of login scripts and they work just fine. However I need my operators to login and then list their activities for the other operators who are logged in to see and if desired send their clients on the desired activity. I have the login working like a charm and the activities are listed just beautifully. How do I combine the two tables in the MySQL with PHP so the operator Logged in can only make changes to his listing but see the others. FIRST THE ONE script the member logges in here to the one table in MSQL: <?php session_start(); require_once('config.php'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } $login = clean($_POST['login']); $password = clean($_POST['password']); if($login == '') { $errmsg_arr[] = 'Login ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'Password missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: login-form.php"); exit(); } $qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'"; $result=mysql_query($qry); if($result) { if(mysql_num_rows($result) == 1) { session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['member_id']; $_SESSION['SESS_FIRST_NAME'] = $member['firstname']; $_SESSION['SESS_LAST_NAME'] = $member['lastname']; session_write_close(); header("location: member-index.php"); exit(); }else { header("location: login-failed.php"); exit(); } }else { die("Query failed"); } ?> ................................................. ................................ Now I need the person who logged in to the table above to be able to make multiple entries to the table below <? $ID=$_POST['ID']; $title=$_POST['title']; $cost=$_POST['cost']; $activity=$_POST['activity']; $ayear=$_POST['aday']; $aday=$_POST['ayear']; $seats=$_POST['special']; $special=$_POST['seats']; mysql_connect("xxxxxx", "xxx350234427", "========") or die(mysql_error()); mysql_select_db("xxxx") or die(mysql_error()); mysql_query("INSERT INTO `activity` VALUES ('ID','$title', '$cost','$activity', '$aday', '$ayear', '$special', '$seats')"); Print "Your information has been successfully added to the database!" ?> Click <a href="member-profile.php">HERE</a> to return to the main menu <?php ?> |