PHP - Retrieving Results From Database To Generate A Graph.
Hello people, currently i ran into some problem.
Currently, i have a database called responses which have the fields of ID, Student_id, question_id, Answer. I had stored my results into the database which appeared to be 1 1 1 Agree 2 1 2 Disagree 3 3 4 Unsatisfied. So any recommendation on how should i do about in generating the result into a graph whereby the graph will show how many students choose "AGree" on that particular question THANKS Similar TutorialsCode: [Select] $query = mysql_query("SELECT a.*, b.* FROM friendlist a INNER JOIN friendlist b ON (a.friendemail=b.friendemail) INNER JOIN users c ON (b.friendemail = c.EmailAddress) WHERE a.email = 'asdf@gmail.com' AND c.Username LIKE '%carol%' GROUP BY a.id ORDER BY count(*) DESC"); Code: [Select] while ($showfriends = mysql_fetch_array($query)) { echo $showfriends['Username']; } and I would get nothing. It produces the correct number of <div> so i know it's getting through, but it's having trouble displaying the entries? Hey all, I've written a php search feature for a mysql database. The search returns a file name like sample.gif, how would I go about displaying the actual image instead? Since the images all have the same location could I have the search return the string into a variable then make the whole thing a link? Thanks. I have my database set to insert the current time stamp when an entry is made into the table, I am then trying to retrieve via the following code: $select_view_idea="SELECT * FROM $tbl_name5 WHERE message_number='$message_number'"; $result_view_idea=mysql_query($select_view_idea); while($row_view_idea=mysql_fetch_assoc($result_view_idea)){ extract($row_view_idea); } date_default_timezone_set('US/Eastern'); $date=date('l, F jS Y h:i:s A T', $date); echo $date; The above is outputting: Wednesday, December 31st 1969 07:33:31 PM EST the database contains: 2011-11-18 00:47:56 Hi all, This is something related with php as well as java script. If anyone can help me regarding this issue i would be very pleased. In a particular form, i have 2 fields namely customer id and Account type. Since there are many account types it is stored as a jump menu. There are seperate tables in my database to represent each of those accounts types. There is a seperate field in each table called account number which is auto incremented. If i select a particular account type in my form, i want to get the account number which is relevant to that account type. For an example if i click the submit button a message should appear like " A new ..........( relevant account type) has been successfully opened" Any idea of how this could be done? Thanks, Heshan. I am working on a kind of CMS for my own website which no one else will be using but me as a way of improving my php skills, and am having problems with retrieving data from the database that holds both text and php code. I have searched the web and found that i should be using eval() for the code to be executed before it is send to the browser but cannot get it to work and can't find my mistake(s). the php code will always be the same, and is supposed to retrieve the id number of a page to use in a link (and works fine when tested by loading the code directly without retrieving it from the database) this is an example of data stored in the database Code: [Select] The <a href="page_builder.php?id=<?php echo $page->id('mines_DwarvenMines') ?>">Dwarven Mines</a> have a great selection of Ores,... Of course when I leave it like this, hovering over the link in my page will show exactly that and lead to nowhere Code: [Select] localhost/page_builder.php?id=<?php echo $page->id('mines_DwarvenMines') ?> Most of these links appear in tips given at the end of the page and are processed as followed Code: [Select] $questtips = $quest->getQuestTips(); $tips = ""; if ($questtips == "none") { $tips = "/"; } else { foreach($questtips as $tip) { $tips .= "<li>"; $tips .= $tip->getTip(); $tips .= "</li>"; } } and finally put on screen by the presentation layer as followed Code: [Select] <h2>Tips & Extra Info</h2> <div class="tipsList"> <ul> <?php echo $tips ?> </ul> </div> I have tried all sorts to get the code to be executed when retrieved from the database before being send to the browser so that this particular link would say "localhost/page_builder.php?id=57" but I cannot get it to work, though I suspect it is fairly easy. I suspect I would have to store the data in a different format in the database? And how exactly do I use the eval() function in my case? Could someone please adjust my code so that it does work? Thanks Hi, I have managed to get the code working to store a .jpg file in the database under the longblob type. Now all i have left to do is to retrieve that image and display it. So far i have this: list.php Code: [Select] while($r = mysql_fetch_array($sql)) { //for each record ... echo " <img src= getoutside.php?id='".$r[apartmentId]. " '> "; getoutside.php Code: [Select] <?php header("Content-type: image/jpg"); // act as a jpg file to browser $nId = $_GET['id']; include 'dbase.php'; //connect to database $sqlo = "SELECT outside FROM apartment WHERE apartmentId = $nId"; $oResult = mysql_query($sqlo); $oRow = mysql_fetch_array($oResult); $sJpg = $oRow["outside"]; echo $sJpg; ?> The result from this is a box with a red cross in it. Can anyone find a problem with this code please? Thanks I have two tables. Table Name:Users Fields: User_name user_email user_level pwd 2.Reference Fields: refid username origin destination user_name in the users table and the username field in reference fields are common fields. There is user order form.whenever an user places an order, refid field in reference table will be updated.So the user will be provided with an refid Steps: 1.User needs to log in with a valid user id and pwd 2.Once logged in, there will be search, where the user will input the refid which has been provided to him during the time of order placement. 3.Now User is able to view all the details for any refid 3.Up to this we have completed. Query: Now we need to retrieve the details based on the user logged in. For eg: user 'USER A' has been provided with the referenceid '1234' during the time of order placement user 'USER B' has been provided with the referenceid '2468' during the time of order placement When the userA login and enter the refid as '2468' he should not get any details.He should get details only for the reference ids which is assigned to him. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=309239.0 I have two tables. Table Name:Users Fields: User_name user_email user_level pwd 2.Reference Fields: refid username origin destination user_name in the users table and the username field in reference fields are common fields. There is user order form.whenever an user places an order, refid field in reference table will be updated.So the user will be provided with an refid Steps: 1.User needs to log in with a valid user id and pwd 2.Once logged in, there will be search, where the user will input the refid which has been provided to him during the time of order placement. 3.Now User is able to view all the details for any refid 3.Up to this we have completed. Query: Now we need to retrieve the details based on the user logged in. For eg: user 'USER A' has been provided with the referenceid '1234' during the time of order placement user 'USER B' has been provided with the referenceid '2468' during the time of order placement When the userA login and enter the refid as '2468' he should not get any details.He should get details only for the reference ids which is assigned to him. Basically i have a folder with 100+ images they are NOT all the same extension, what im wanting to do is use PHP to find all the images and put them all in a database. how would i go about doing this? thanks This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=318312.0 hi!, is it possible to use rand() to generate unique number that will be saved in a database as a primary key? Since i dont want to have numbers like 00001 incrementing on the table. They dont look like real account numbers... i need something like 45642 or 95452 and the like. thanks in advance. Hi, What I'm trying to do is create a script that generates a random list of cars whenever it is run. I have a list of available cars in a MySQL database. I'm just not sure how to get php to generate a list of, say, 20 cars, that are randomly picked from the cars in the database. I may also want to add other statistics like MPG (also already in the database). Can anyone show me how to do this? And is it possible to format the returned data in a table or div format? Thanks in advance Unk The subject could be a bit vague, but my problem is simple. (I think so) So I made a php test site that is quite similar to a forum. Where you see a title or a subject and when you click on it you will see more details about that subject. I made my database and script for inserting data into my mySQL database. I also did my output aswell, so every topic is posted on a webpage "archive" where you can see all the subjects. But now I want to see the full details of that type of subject by clicking on it. I have no idea how to make that happen googled it but didn't find any results...just wondering if it's even possible to do that. I'm a new guy here! Hi Guys I have a product page in mysql as below: id itemnumber order_id 1 348939012 2 2 535432454 1 3 543253424 4 4 987698769 3 I need to order this in my PHP mysql_fetch_assoc by order id. What I mean is I need to list them by order_id: 1,2,3,4 I have used ORDER BY order_id but still it wont work, any ideas? Hoping someone can help me. I am trying to limit the number of results from a sql database and I assume that I should use pagination. How do I do this with the following code? Thanks in advance. Code: [Select] <?php if ($_GET[search] == 1) $qstring = "WHERE TITLE LIKE '%$_POST[search]%'"; if ($_GET[search] == 2) { $qstring = "WHERE CATEGORY LIKE '%-$_POST[search_cat]-%'"; $SQL3 = "SELECT * from CATEGORIES WHERE ID = '%-$_POST[search_cat]-%'"; $result3 = @mysql_query( $SQL3 ); $row3 = @mysql_fetch_array( $result3 ); } if ($_GET[search] == 3) { $qstring = "WHERE PACKAGE = '$_POST[search_package]'"; } $setpage = 'add_listings'; $return = 'manage_listings'; $table = "LISTINGS"; if (empty($qstring)) $qstring = 'ORDER BY TITLE ASC'; $qstring = "$qstring"; ?> <?php if ($rowxxx[HELPBOX] == $nil || $rowxxx[HELPBOX] == Show) { ?> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td class="td3" colspan="2"><b> Tool Tips</b></td> </tr> <tr> <td class="td4" valign="top"> <p><img src="../images/Help.png" width="64" height="64"></p> </td> <td class="td4" width="100%" valign="top"> <table width="100%" align="center" cellpadding="0" cellspacing="0" border="0"> <tr> <td> <div align="center"><img src="../images/edit_listing.jpg" border="0" alt="Edit this listing" width="22" height="22" /></div> </td> <td class="font1" width="100%"> Edit this listing.</td> </tr> <tr> <td> <div align="center"><img src="../images/delete-page-red.gif" alt="Delete this listing" border="0" width="14" height="14" /></div> </td> <td class="font1" width="100%"> Delete this listing.</td> </tr> <tr> <td> <div align="center"><img src="../images/user-group3.gif" width="14" height="14"></div> </td> <td class="font1" width="100%"> Duplicate this listing and edit its clone.</td> </tr> <tr> <td><a href="?page=add_photos&id=<?php echo $row[ID]; ?>"><img src="../images/Iphoto.png" width="22" height="22" border="0"></a></td> <td class="font1" width="100%"> Add photos.</td> </tr> <tr> <td> </td> <td class="font1" width="100%"> <?php $sql_active_accounts = "SELECT count(*) FROM LISTINGS"; $res_active_accounts = @mysql_query($sql_active_accounts); $row_active_accounts = @mysql_fetch_row($res_active_accounts); ?> <b> ( <?php echo " $row_active_accounts[0] "; if ($row_active_accounts == $nil) echo " 0 "; ?> ) </b>Listings in your database.</td> </tr> </table> </td> </tr> </table> <br> <?PHP } ?> <form action="?page=<?php echo $_GET[page]; ?>&search=2" method="post" name="form1" id="form1"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td class="td3"> <b>Find Listings by Category</b></td> </tr> </table> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td class="td4" nowrap width="100%"> Select Category</td> <td class="td4"> <select name="search_cat"> <option selected> <?PHP ECHO $row3[TITLE]; ?> </option> <?PHP $SQLcaT = "SELECT * from CATEGORIES ORDER BY TITLE ASC"; $resultcaT = @mysql_query( $SQLcaT ); while( $rowcaT = @mysql_fetch_array( $resultcaT ) ) { $sql2 = "SELECT count(*) FROM LISTINGS WHERE CATEGORY LIKE '%-$rowcaT[ID]-%'"; $res2 = @mysql_query($sql2); $row2 = @mysql_fetch_row($res2); ?> <option value = "<?php echo $rowcaT[ID]; ?>"> <?php echo "$rowcaT[TITLE]"; if (empty($row2[0])) echo ' [ 0 ]'; else echo " [ $row2[0] ]"; ?> </option> <?PHP } ?> </select> </td> <td class="td4"> <input type="submit" name="Submit" value="Search" /> </td> </tr> </table> </form> <br> <form action="?page=<?php echo $_GET[page]; ?>&search=3" method="post" name="form1" id="form1"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td class="td3"> <b>Find Listings by Package</b></td> </tr> </table> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td class="td4" nowrap width="100%"> Select Package</td> <td class="td4"> <select name="search_package" id="search_package"> <option selected value ="<?php echo $row[DEFAULTPACKAGE]; ?>"> <?PHP $SQLlu = "SELECT * from PACKAGES WHERE ID = '$row[DEFAULTPACKAGE]'"; $resultlu = @mysql_query( $SQLlu ); $rowlu = @mysql_fetch_array( $resultlu ); ?> <?PHP echo $rowlu[NAME]; ?> </option> <?PHP $SQL3 = "SELECT * from PACKAGES ORDER BY NAME ASC"; $result3 = mysql_query( $SQL3 ); while( $row3 = mysql_fetch_array( $result3 ) ) { ?> <option value="<?php echo $row3[ID]; ?>"> <?php echo $row3[NAME]; ?> </option> <?PHP } ?> </select> </td> <td class="td4"> <input type="submit" name="Submit" value="Search" /> </td> </tr> </table> </form> <br> <form action="?page=<?php echo $_GET[page]; ?>&search=1" method="post" name="form1" id="form1"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td class="td3"> <b>Find Listing by Name</b></td> </tr> </table> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td class="td4" nowrap width="100%"> Listing Title</td> <td class="td4"> <input type="text" name="search" value="<?php echo $_POST[search]; ?>" size="40" /> </td> <td class="td4"> <input type="submit" name="Submit" value="Search" /> </td> </tr> </table> </form> <br> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td class="td3"> <b>Last Listing Added</b></td> </tr> </table> <?php $SQL = "SELECT * from $table ORDER BY ID DESC LIMIT 1"; $result = @mysql_query( $SQL ); while( $row = @mysql_fetch_array( $result ) ) { $check = 1; ?> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <?PHP $filename = "$svr_rootscript/product_images/thumb/$row[IMAGENAME].jpg"; if (file_exists($filename)) { ?> <td nowrap class="td4" align="center" valign="top"> <a href="?page=add_photos&id=<?php echo $row[ID]; ?>"><img src="../product_images/thumb/<?php echo "$row[IMAGENAME]"; ?>.jpg" border="1" /></a> </td> <?PHP } ?> <td class="td4" colspan="2" width="100%"><b> <?php echo "<a href = \"?page=$setpage&id=$row[ID]&qt=update\">$row[TITLE]</a>"; ?> </b><br> <span class="font3">Category(s): <?PHP $pieces = explode("-", $row[CATEGORY]); foreach ($pieces as $cats => $value) { if ($value != $nil && $value != '-' && $value != '--') { $SQLCat = "SELECT * from CATEGORIES WHERE ID = '$value'"; $resultCat = @mysql_query( $SQLCat ); $rowCat = @mysql_fetch_array( $resultCat ); echo "$rowCat[TITLE], "; } } ?> </span></td> <td nowrap class="td4"><a href="?page=add_photos&id=<?php echo $row[ID]; ?>"><img src="../images/Iphoto.png" width="22" height="22" border="0"></a></td> <td class="td4"><a href="<?php echo "?page=$setpage&id=$row[ID]&qt=insert&clone=1"; ?>"> <img src="../images/user-group3.gif" border="0" alt="Edit this listing" width="14" height="14" /></a> </td> <td class="td4"><a href="<?php echo "?page=$setpage&id=$row[ID]&qt=update"; ?>"> <img src="../images/edit-comment-orange.gif" border="0" alt="Edit this listing" width="14" height="14" /></a> </td> <td class="td4"><a href="../library/delete.php?id=<?php echo $row[ID]; ?>&return=<?php echo $return; ?>&type=<?php echo "$table"; ?>"> <img src="../images/delete-page-red.gif" alt="Delete this listing" border="0" width="14" height="14" /></a> </td> </tr> </table> <?php } ?> <br> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td class="td3"> <b>Your Listings</b></td> </tr> </table> <?php $SQL = "SELECT * from $table $qstring"; $result = @mysql_query( $SQL ); while( $row = @mysql_fetch_array( $result ) ) { $check = 1; ?> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <?PHP $filename = "$svr_rootscript/product_images/thumb/$row[IMAGENAME].jpg"; if (file_exists($filename)) { ?> <td nowrap class="td4" align="center" valign="top"> <a href="?page=add_photos&id=<?php echo $row[ID]; ?>"><img src="../product_images/thumb/<?php echo "$row[IMAGENAME]"; ?>.jpg" border="1" /></a> </td> <?PHP } ?> <td class="td4" colspan="2" width="100%"><b> <?php echo "<a href = \"?page=$setpage&id=$row[ID]&qt=update\">$row[TITLE]</a>"; ?> </b><br> <span class="font3">Category(s): <?PHP $pieces = explode("-", $row[CATEGORY]); foreach ($pieces as $cats => $value) { if ($value != $nil && $value != '-' && $value != '--') { $SQLCat = "SELECT * from CATEGORIES WHERE ID = '$value'"; $resultCat = @mysql_query( $SQLCat ); $rowCat = @mysql_fetch_array( $resultCat ); echo "$rowCat[TITLE], "; } } ?> </span> </td> <td nowrap class="td4"><a href="?page=add_photos&id=<?php echo $row[ID]; ?>"><img src="../images/Iphoto.png" width="22" height="22" border="0"></a></td> <td class="td4"><a href="<?php echo "?page=$setpage&id=$row[ID]&qt=insert&clone=1"; ?>"> <img src="../images/user-group3.gif" border="0" alt="Edit this listing" width="14" height="14" /></a> </td> <td class="td4"><a href="<?php echo "?page=$setpage&id=$row[ID]&qt=update"; ?>"> <img src="../images/edit-comment-orange.gif" border="0" alt="Edit this listing" width="14" height="14" /></a> </td> <td class="td4"><a href="../library/delete.php?id=<?php echo $row[ID]; ?>&return=<?php echo $return; ?>&type=<?php echo "$table"; ?>"> <img src="../images/delete-page-red.gif" alt="Delete this listing" border="0" width="14" height="14" /></a> </td> </tr> </table> <?php } ?> <?PHP if (empty($check)) { ?> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td nowrap class="td4">No listings found.</td> </tr> </table> <?PHP } ?> Hello all, I am making a database with all the Boeing deliveries sorted by month. I made a index with all the months and when you click on a month you will get a full list of the type and quantity of aircraft that has been deliverd. I have two problems and I can't figure it out. The first problem I have, is that I want to show the visitors which airline has bougt which type of aircraft and how many. The second problem I have is a want to show them the total amount of deliveries, not just per type of aircraft, but a total number. Here are some shots of my problem and what I have: This is how my MYSQL-database lookes like. The columns I have a id, day, month, year, airline, aircraft, amount (just a simple translation of the Dutch words ). As you can see, there are some airlines that received one type of aircraft two times (TUI Travel PLC has received 2x Boeing 737-800). Keep this in mind, I will get back to this. This is the table on my website. The first column shows the type of aircraft. The secon column shows us how many of that type has been deliverd. In the last column I want to have all the airlines that has received that type of aircraft. As I mentioned above, TUI Travel PLC has received 2x B737-800, so in the row of B737-800 I want to have TUI Travel PLC (2x). If the airline received more then 1 aircraft, I would like to have (.....x) (and the amount on the dots --> TUI example: 2 aircraft, so 2x). So you will get TUI Travel PLC (2x). This is the code I have so far (sorry I am a real noobie in PHP/MYSQL so my programming ain't that great ) Code: [Select] <?php mysql_connect(".....", ".....", ".....") or die(mysql_error()); mysql_select_db(".....") or die(mysql_error()); $maand = $_GET['maand']; $jaar = $_GET['jaar']; $query = "SELECT aircraft, jaar, maatschappij, COUNT(maatschappij) FROM deliveries_orders_boeing WHERE maand = '$maand' AND jaar = '$jaar' GROUP BY aircraft"; $result = mysql_query($query) or die(mysql_error()); // Print out result echo "<br /><h3>Boeing deliveries ".$maand." ".$jaar."</h3><br /> <table border='0' width='700'>"; while($row = mysql_fetch_array($result)){ echo "<tr><td id='aircraft'>". $row['aircraft']. "</td><td id='aantal'>". $row['COUNT(maatschappij)'] ."</td><td id='maatschappijen'>different companies</td></tr>"; } echo "<tr><td id='totaal'>Totaal</td><td id='totaal_aantal'>....</td><td></td></tr></table>"; ?> </td> </tr> </table> Maybe a little confusing, but I hope someone can help me with this. Kind regards, Flyboeing Hi I have been given a task to create some SQL reports. One of the reports is to display all the customers who have purchased a certain product based on user selection and then have those results able to be extracted to a mailing list. So ive got the report done. Some drop down boxes allow a user to select a product and once submitted the results are then displayed. But i dont even know where to begin with extracting those results to a mailing list. Could someone help me please? What method should I use? and where do i begin? BTW im a rookie with PHP/Mysql ive just got my first job since leaving university and this is a task ive been given at work so any quick and helpful replies are greatly appreciated Thanks in advance. Hi, I'm currently learning PHP through tutorials and I am working on a webpage that filters statistics (crime records) from an SQL table and filters them by an option of years that the user has picked from a dropdown box. $desiredyear = $_POST['year'] is the year picked from the drop down box on a different page. I did not encounter any problems simply displaying the entire table until I tried to filter the crimes by year. I keep getting this error message. Warning: sqlsrv_fetch_array() expects parameter 1 to be resource, boolean given in C:\RDEUsers\NET\400792\1.php on line 40 Here is the error line. Code: [Select] while($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC)) And here is my code so far Code: [Select] <?php $server = 'SQL2008'; $connectionInfo = array( "Database"=>"rde_400792"); $conn = sqlsrv_connect($server,$connectionInfo); $desiredyear = $_POST['year']; $describeQuery='select year, force, homicide from crime where year = $desiredyear '; $results = sqlsrv_query($conn, $describeQuery); echo '<table border="1" BORDERCOLOR=Black>'; echo '<tr><th bgcolor = "LightBlue">Year</th><th bgcolor = "LightBlue" >Force</th><th bgcolor = "LightBlue">Homicide</th></tr>'; while($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC)) { echo '<tr>'; echo '<td >' .$row['year'].'</td>'; echo '<td>' .$row['force'].'</td>'; echo '<td>' .$row['homicide'].'</td>'; echo '</tr>'; } echo '</table>'; sqlsrv_close($conn); Please can somebody help me fix this? It's driving me mad and I've exhausted my limited knowledge on the subject. I just don't understand what I'm doing wrong. |