PHP - Displaying Grouped Data Correctly
Ok I have some data that I would like to have grouped by date. There are dates that have multiple entries for the same date. I would like to have that data listed under one date. I would like it to look like this
Date Location Weather Location Weather Date Location Weather Here is the code I have so far and it lists the data by date but only the data for first date in the table. If there is data listed for the same date but different location it will not list that data. What am I missing. Any help would be great. ! <?php // Connect to server and select database. include ("opendb.php"); $tbl_name="dbnwaterfowl"; $sql="SELECT huntDate, huntLocation, huntWeather, waterfowlSpecies, waterfowlNumberKilled, waterfowlBandedNumber, DATE_FORMAT(huntDate,'%m %d, %Y') FROM dbnwaterfowl GROUP BY `huntDate` ORDER BY `huntDate` ASC"; $result=mysql_query($sql); ?> <td> <p> </p> <table width="100%" border="2" cellpadding="1" cellspacing="0" bordercolor="#FA6103" bgcolor="#FFFFFF"> <tr> <td colspan="7"><div align="center"> <p><img src="images/hl-logo.jpg" /></p> <p align="center"><strong><a href="login.php">Login</a> | <a href="insert.php">Log Hunt</a> | <a href="logout.php">Logout</a></strong></p> </div></td> </tr> <tr> <td align="center" bordercolor="#FA6103" ><span class="style4">Hunting Date</span></td> <td align="center" bordercolor="#FA6103" ><span class="style4">Hunting Location</span></td> <td align="center" bordercolor="#FA6103"><span class="style4">Weather</span></td> <td align="center" bordercolor="#FA6103"><span class="style4">Waterfowl Species</span></td> <td align="center" bordercolor="#FA6103"><span class="style4">Number Killed</span></td> <td align="center" bordercolor="#FA6103"><span class="style4">Number of Bands</span></td> <td align="center"> </td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td><? echo $rows['huntDate']; ?></td> <td><? echo $rows['huntLocation']; ?></td> <td><? echo $rows['huntWeather']; ?></td> <td><? echo $rows['waterfowlSpecies']; ?></td> <td><? echo $rows['waterfowlNumberKilled']; ?></td> <td><? echo $rows['waterfowlBandedNumber']; ?></td> <td align="center"><a href="update.php?id=<? echo $rows['id']; ?>">update</a></td> </tr> <?php } ?> </table> </td> </tr> </table> <?php mysql_close(); ?> Similar Tutorialsok so im sure this is only a small problem but still here it is: im making a shopping list app where users can create a list...when they view the list they can populate it with categories such as frozen food, fruit, veg etc etc...they can then populate categories with items such as apples, potatoes or ice cream etc etc. now i have some data in the database already...and i wanted to display it on the page like this. ASDA SHOPPING LIST fruit apples bananas plums veg potatoes carrots frozen burgers chips ice cream however at the moment with my code it displays like this: ASDA SHOPPING LIST fruit apples bananas plums potatoes carrots burgers chips ice cream veg frozen here is my code: include_once("config_class.php"); $db = new db(); // open up the database object $db->connect(); // connect to the database //getting id of the data from url $id = $_GET['id']; $sql=mysql_query("SELECT listname FROM list WHERE listid=$id") or die("cannot select: ".mysql_error()); $sql2=mysql_query("SELECT catid, category FROM cat WHERE listid=$id") or die("cannot select: ".mysql_error()); $sql3=mysql_query("SELECT items.itemname, items.itemid, cat.catid FROM items, cat WHERE cat.catid=items.catid") or die("cannot select: ".mysql_error()); $temp_cat = ""; $res=mysql_fetch_array($sql); echo "<b>" . $res['listname'] . "</b>" . "<br><br>"; echo "<form action='addcat.php?id=$id' method='post'>"; echo "<input type='text' id='addcat' name='addcat'>"; echo "<input type='submit' value='Add Category'>"; echo "</form>"; while($res2=mysql_fetch_array($sql2)) { echo "<table cellpadding='2' cellspacing='2' width='800'>"; echo "<tr>"; if($res2['category'] != $temp_cat ) { echo "<td width='20%'>"; echo "<b>" . $res2['category'] . "</b>" . "</td>"; echo "<td width='20%'><a href='delcat.php?id=$res2[catid]&id2=$id'>Delete Category</a></td>"; echo "<form action='additem.php?id=$res2[catid]&id2=$id' method='post' name='form1'>"; echo "<td width='20%'>"; echo "<input type='text' name='itemname'></td>"; echo "<td width='20%'>"; echo "<input type='submit' name='Submit' value='Add Item'></td>"; echo "</form>"; echo "</tr>"; $temp_cat=$res2['category']; } while($res3=mysql_fetch_array($sql3)) { echo "<tr>"; echo "<td width='20%'>"; echo "$res3[itemname]" . "</td>"; echo "<td width='20%'>"; echo "<a href='delitem.php'>Delete Item</a>" . "</td>"; echo "</tr>"; } echo "</table>"; } could someone please help me display this correctly? thanks in advance Here is my database: receipt_id | item_id | something_here 21 1 2 29 1 10 30 1 3 31 2 9 What i would like to do is display the above data from my database in a table looking like this: receipt_id | item_id | total_something_here 21 1 15 31 2 9 in short, i want to show only different item_id with the sum of something_here field for all records where item_id is the same ie 10 + 3 + 2 = 15 in the above example please help me right now it displays the first column of the array as a header for each foreach loop then i've got the data displayed under each header and it has 4 columns or a number of my choosing with data displayed under the Table Headings. I am trying to make it display 4 or so columns but with the each group having a certain number of grouped table (data/header) in each column. a different amount for each column that i can choose IF Possible i'd like the choice of being able to remove the headers eg. Z when there is no data in them. This is an example of how it is being displayed right now Any Help would be greatly appreciated Quote A Airlie Beach Andergrove Alexandra Armstrong Beach Alligator Creek B Bucasia Blacks Beach Beaconsfield Bakers Creek Balberra Bloomsbury Breadalbane Ball Bay Belmunda C Cannonvale Calen Crystal Brook Cremorne Chelona Campwin Beach Cape Hillsborough Conway Heres The Code i have so far. Code: [Select] <?php $file = "widget.csv"; @$fp = fopen($file, "r") or die("Could not open file for reading"); $outputArray = array(); $count = 0; while(($shop = fgetcsv($fp, 1000, ",")) !== FALSE) { $outputArray[array_shift($shop)] = array_filter($shop); } echo "<table>"; foreach ($outputArray as $alphabetical=>$value){ echo "<th colspan='4'><b>" . $alphabetical ."</b></th>"; echo "<tr>"; foreach ($value as $key){ $afterkey=preg_replace('/\s+/','-',$key); if ($count == 4){ echo '</tr><tr><td><a href="map.php?mapaddress='.$afterkey.'-qld&mapname='.$key.'">'.$key.'</a></td>'; $count = 0; }else{ echo '<td><a href="map.php?mapaddress='.$afterkey.'-qld&mapname='.$key.'">'.$key.'</a></td>'; } $count++; } echo "</tr>"; $count = 0; } echo "</table>"; echo "\n<br />"; ?> Heres an example of what i am trying to do. A D K N S AlexandraHeadlands DickyBeach KingsBeach Nambour SandstonePoint Aroona Diddillibah KielMountain Ninderry ShellyBeach Doonan KundaPark NoosaHeads SippyDowns B Dulong Kuluin Ningi SunriseBeach Beachmere DeceptionBay Kilcoy NorthArm SunshineBeach BanksiaBeach Noosaville Scarborough Beerburrum E L Beerwah EerwahVale Landsborough O T Bellara Elimbah Tanawha Bellmere Eudlo M P TowenMountain Birtinya Eumundi Maleny Petrie Tewantin Bongaree Mapleton Palmview TwinWaters Bokarina F Marcoola Palmwoods BribieIslandArea Flaxton MarcusBeach Parklands U Buddina ForestGlen MaroochyRiver Parrearra UpperCaboolture Burnside Maroochydore PeregianBeach Buderim G Minyama Pinbarren V Burpengary GlassHouseMountains MoffatBeach PointArkwright Valdora BliBli Mons PelicanWaters H Montville PacificParadise W C Highworth Mooloolaba WeybaDowns CoolumBeach Hunchy Mooloolah Q Warana Caboolture MountainCreek WestWoombye CabooltureSouth I MountCoolum R Woombye Caloundra ImageFlat Morayfield Rosemount Woorim CastawaysBeach Mudjimba Redcliffe WamuranBasin Chevallum J Woodford CoesCreek WoodyPoint Cooroy Wamuran Currimundi Wurtulla X Y YandinaCreek Yandina Z Hi, I think my problem is a mixture of MODREWRITE and PHP. I have the following .htaccess located in the web root. Code: [Select] RewriteEngine On RewriteRule ^about/(([^/]+/)*[^/.]+)$ /about/index.php?p=$1 [L] RewriteRule ^(([^/]+/)*[^/.]+)$ index.php?p=$1 [L] The index.php example below is located in the folder "about". Just for your info I also have an index at the web root too serving other files. <?php $page = isset($_GET['p']) ? $_GET['p'] : '/about/about'; switch($page) { /*----------------------- PAGES -----------------------------------*/ case 'about/profiles': $title = 'My Title'; $keyword = 'A few keywords'; $description = 'A good description.'; break; default: $title = 'My Title'; $keyword = 'A few keywords'; $description = 'A good description.'; break; } include($_SERVER['DOCUMENT_ROOT']. '/include/header.php'); include($_SERVER['DOCUMENT_ROOT']. 'about/'.$page.'.php'); include($_SERVER['DOCUMENT_ROOT']. "/include/footer.php"); ?> This is my problem: When I click on the link http://mysite.co.uk/about/ it throws the errors out below. When I click on the link http://mysite.co.uk/about/profiles/ it works fine and for the life of me I cant understand what I have done wrong. Warning: include(/var/www/mysite/about//about/about.php) [function.include]: failed to open stream: No such file or directory in /var/www/mysite/about/index.php on line 22 Warning: include() [function.include]: Failed opening '/var/www/mysite/about//about/about.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/mysite/about/index.php on line 22 I am a kinda of newbie so any help/guidance will be gratefully received I have set up this website and there's a problem in displaying it. Can anybody help me out? I'm using PHP version 5.3. www.pchl.org Hi I appreciate everyone who helped me with my other problem trying to call my Array() I had issues with. Heres what that looks like http://crafted.horizon-host.com/ff/ Code from the above Code: [Select] <html> <head> <title>FINAL FANTASY XIV - Item Database</title> <style type="text/css"> a:link {text-decoration: none; color: #FFFFFF} a:visited {text-decoration: none; color: #FFFFFF} a:hover {text-decoration: none; color: #FFFFFF} a:active {text-decoration: none; color: #FFFFFF} p.title { font-size: medium; font-family: Verdana; color: #FFFFFF; } p.items { font-size: small; font-family: Verdana; color: #FFFFFF; } </style> <script src="http://static.yg.com/js/exsyndication.js" type="text/javascript"> </script> <script type="text/javascript"> YG.UserSettings.Syndication = { removeClasses: ['extern'], defaultClass: 'yg-iconsmall yg-name', clearTitle: true } </script> </head> <body background="../images/testbg.jpg" marginwidth=60 marginheight=60> <table align="center" id="Table_01" width=520 height=393 border=0 cellpadding=0 cellspacing=0> <tr> <td width=520 height=14 colspan=5 background="../images/test_01.gif"></td> </tr> <tr> <td width=20 height=23 background="../images/test_02.gif"></td> <td colspan=3 background="../images/test_03.gif" align="center" valign="middle"> <p class='title'>FINAL FANTASY XIV - Item Database</p> </td> <td width=14 height=23 background="../images/test_04.gif"></td> </tr> <tr> <td width=520 height=7 colspan=5 background="../images/test_05.gif"></td> </tr> <tr> <td background="../images/test_06.gif"></td> <td colspan=3 background="../images/test_07.gif" align="center" valign="top"> <p class='items'> <?php function grabdata($site){ $page_contents = file_get_contents($site); $pattern = '/\/item\/([a-z,-]+[^gil])\?id\=([0-9,]+)/'; preg_match_all($pattern, $page_contents, $matches); $arrRetList = array(); if(!empty($matches)){ foreach($matches as $item) { foreach($item as $pos => $row){ $arrRetList[$pos][] = $row; } } foreach($arrRetList as $row){ echo "<p class='items'><a href='http://ffxiv.yg.com" . $row[0] . "'>Unknown Item</a> - " . $row[1] . " - " . $row[2] . "<BR>"; } } } grabdata("http://ffxiv.yg.com/items?l=50:50;trd=0;cl=30"); ?> </p> </td> <td background="../images/test_08.gif"></td> </tr> <tr> <td colspan=2 width=23 height=17 background="../images/test_09.gif"></td> <td background="../images/test_10.gif"></td> <td colspan=2 width=17 height=17 background="../images/test_11.gif"></td> </tr> <tr> <td> <img src="../images/spacer.gif" width=20 height=1></td> <td> <img src="../images/spacer.gif" width=3 height=1></td> <td> <img src="../images/spacer.gif" width=480 height=1></td> <td> <img src="../images/spacer.gif" width=3 height=1></td> <td> <img src="../images/spacer.gif" width=14 height=1></td> </tr> </table> </body> </html> Heres the code im trying to run, has some added stuff to the above <?php ?> code but its not viewing at all, just shows a white page.. and would like to get some advice on what im doing wrong Code: [Select] <?php function grabdata($site){ $page_contents = file_get_contents($site); $pattern = '/\/item\/([a-z,-]+[^gil])\?id\=([0-9,]+)/'; preg_match_all($pattern, $page_contents, $matches); $arrRetList = array(); if(!empty($matches)){ foreach($matches as $item) { foreach($item as $pos => $row){ $arrRetList[$pos][] = $row; } } foreach($arrRetList as $row){ echo $row[1] . " - " . $row[2] . "<BR>"; echo "<table align='center' border='0' cellpadding='0' cellspacing='0' width='80%'><td align='left'><p class='items'>Item</td><td align='center'><p class='items'>NPC Price</td><tr><td align='left'><p class='items'><a href='http://ffxiv.yg.com" . $row[0] . "'>Unknown Item</a></td></td><td align='center'><p class='items'>"; $page_contents2 = file_get_contents("http://ffxiv.yg.com" . $row[0] . ""); $matches2 = array(); preg_match_all('/<td class=\"lefttd\">Normal<\/td><td align=\"right\">([0-9,]+)<\/td><\/tr>/', $page_contents2, $matches2); if ($matches2[1][0] == ""){ echo "0g - "; } else { print_r($matches2[1][0] . "g - "); } preg_match_all('/<td class=\"lefttd\">\+1<\/td><td align=\"right\">([0-9,]+)<\/td><\/tr>/', $page_contents2, $matches2); if ($matches2[1][0] == ""){ echo "0g - "; } else { print_r($matches2[1][0] . "g - "); } preg_match_all('/<td class=\"lefttd\">\+2<\/td><td align=\"right\">([0-9,]+)<\/td><\/tr>/', $page_contents2, $matches2); if ($matches2[1][0] == ""){ echo "0g - "; } else { print_r($matches2[1][0] . "g - "); } preg_match_all('/<td class=\"lefttd\">\+3<\/td><td align=\"right\">([0-9,]+)<\/td><\/tr>/', $page_contents2, $matches2); if ($matches2[1][0] == ""){ echo "0g"; } else { print_r($matches2[1][0] . "g"); } echo "</td></tr>"; } echo "</table><BR><BR><BR>"; } } grabdata("http://ffxiv.yg.com/items?l=50:50;trd=0;cl=30"); ?> To give you a idea of what im looking for, it already grabs each item and list it from grabdata(""); function, i wanna take that further by it grabs the item, and then uses that data to grab the item sell price (normal, +1, +2, +3 quality) for each display it out, something like.. Code: [Select] ITEMNAME1 132g - 145g - 165g - 198g ITEMNAME2 50g - 0g - 0g - 0g ITEMNAME3 63g - 78g - 90g - 110g etc etc from the first $page_contents from $site $row[0] will output: item url variables $row[1] will output: item name $row[2] will output: item # from the second $page_contents from "http://ffxiv.yg.com" . $row[0] . "" $matches2[1][0] will be numerical output of the prices for each preg_match_all These scripts work separately just need them to work together I am having a slight problem with my dynamic form working in Internet Explorer 8. It functions properly in all browsers on Mac and Windows machines. I have a reservations form and when you choose a month in a drop down list, it dynamically creates another drop down with a list of reservation dates for that month. Well, in Internet Explorer it allows me to choose the month, but the second drop down never appears. All other browsers work fine. Anyone have any ideas?? Here is the pertinent code for index.php page... Code: [Select] <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#wait_1').hide(); $('#drop_1').change(function(){ $('#wait_1').show(); $('#result_1').hide(); $.get("func.php", { func: "drop_1", drop_var: $('#drop_1').val() }, function(response){ $('#result_1').fadeOut(); setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400); }); return false; }); }); function finishAjax(id, response) { $('#wait_1').hide(); $('#'+id).html(unescape(response)); $('#'+id).fadeIn(); } </script> <p align="left"> </p> <p align="left" class="home">Booking Form</p> <p align="left"><font size="2" face="Arial" color="#006600">Reservation Month:</font> <form action="resersend.php" method="post"> <select name="drop_1" id="drop_1"> <option value="" selected="selected" disabled="disabled">Choose One</option> <?php getTierOne(); ?> </select> <span id="wait_1" style="display: none;"> <img alt="Please Wait" src="ajax-loader.gif"/> </span> <span id="result_1" style="display: none;"></span> <br> <?php if(isset($_POST['submit'])){ $drop = $_POST['drop_1']; $tier_two = $_POST['tier_two']; echo "You selected "; echo $drop." & ".$tier_two; } ?></form> And here is the func.php page that works with index... Code: [Select] <?php //************************************** // Page load dropdown results // //************************************** function getTierOne() { $result = mysql_query("SELECT DISTINCT MONTH FROM daterange") or die(mysql_error()); while($tier = mysql_fetch_array( $result )) { echo '<option value="'.$tier['MONTH'].'">'.$tier['MONTH'].'</option>'; } } //************************************** // First selection results // //************************************** if($_GET['func'] == "drop_1" && isset($_GET['func'])) { drop_1($_GET['drop_var']); } function drop_1($drop_var) { include_once('db.php'); $result = mysql_query("SELECT * FROM daterange WHERE DEND > DATE(NOW()) AND STATUS='A' AND MONTH='$drop_var' ORDER BY DATE, SITE") or die(mysql_error()); echo '<select name="RID"> <option value=" " disabled="disabled" selected="selected">Choose a Reservation</option>'; while($drop_2 = mysql_fetch_array( $result )) { echo '<option value="'.$drop_2['RID'].'">'.$drop_2 ['DATE']. ', '.$drop_2 ['SITE']. ', '.$drop_2 ['PRICE'].'</option>'; } echo '</select> '; echo "</p>"; echo "<p align=left>"; echo "<br>"; echo "</select><p align=left><label><font size=\"2\" face=\"Arial\">First Name: <input type=\"text\" name=\"FNAME\" size=\"50\" maxlength=\"50\" tabindex=\"1\"<br>"; echo "<p align=left><label>Last Name: <input type=\"text\" name=\"LNAME\" size=\"50\" maxlength=\"50\" tabindex=\"2\"<br>"; echo "<p align=left><label>Address Line 1: <input type=\"text\" name=\"ADDR1\" size=\"50\" maxlength=\"50\" tabindex=\"3\"<br>"; echo "<p align=left><label>Address Line 2: <input type=\"text\" name=\"ADDR2\" size=\"50\" maxlength=\"50\" tabindex=\"4\"<br>"; echo "<p align=left><label>City: <input type=\"text\" name=\"CITY\" size=\"50\" maxlength=\"50\" tabindex=\"5\"<br>"; echo "<p align=left><label>State (abbrev.): <input type=\"text\" name=\"STATE\" size=\"2\" maxlength=\"2\" tabindex=\"6\"<br>"; echo "<p align=left><label>Zip Code: <input type=\"text\" name=\"ZIP\" size=\"5\" maxlength=\"5\" tabindex=\"7\"<br>"; echo "<p align=left><label>Contact Phone Number: (<input type=\"text\" name=\"PHONE1\" size=\"3\" maxlength=\"3\" tabindex=\"8\""; echo "<label>)<input type=\"text\" name=\"PHONE2\" size=\"3\" maxlength=\"3\" tabindex=\"9\""; echo "<label>-<input type=\"text\" name=\"PHONE3\" size=\"4\" maxlength=\"4\" tabindex=\"10\"<br>"; echo "<p align=left><label>Email: <input type=\"text\" name=\"EMAIL\" size=\"50\" maxlength=\"50\" tabindex=\"11\"<br>"; I've got a simple internal messaging system that I'm trying to get the text to display the way it was entered when a message was sent. The messages are inserted into the database using variables generated through this function: Code: [Select] <?php function safe($value){ return mysql_real_escape_string($value); } $staffid=form($_POST['staffid']); $from=safe($_POST["from"]); $category=form($_POST['category']); $subject=safe($_POST["subject"]); $message=safe($_POST["message"]); $grade=form($_POST['grade']); ?> when the text is inserted, there are back slashes automatically inserted behind certain punctuation marks. For example, is someone sends a message that says, "Someone's using phpfreaks forums." It would be inserted as, "Someone\'s using phpfreaks forums." How can I stop this from happening? Or how can I remove the "\" when displaying the string on the web page? Any help is greatly appreciated. I am building a website out that shows videos. I would like to show the videos three up on a row, but it is instead stacking the videos one on top of the other. Check out the page here to get an understanding of what I am talking about http://theblusky.com/HOSTEDSITES/NOWSEASON/index.php?option=com_ttvideo&view=videolist&id=0&Itemid=107 The php file that is controlling the layout is attached. The site this is on is built using Joomla if that helps anyone. Any help is VERY MUCH APPRECIATED!!!! I'm trying to create a list that groups information by username. Only part of it is working. The first query ($get_item_sql) is grouping the information perfectly but the second query ($get_sold) is lumping the $item_price and $item_amount_due as one total for each one and outputting the same amounts into every username. I'm stuck on this and would appreciate your help. For example: Username item fees image fees item sales item price total due Jim 2 $0.40 $100.00 $3.00 $3.40 Kelly 5 $1.00 $100.00 $3.00 $4.00 This example shows the columns in red as being the problem where Kelly didn't sell anything so her "item sales" and "item price" should be $0.00 but is carrying Jim's totals into hers. Hope this helps! Thank you! $get_item_sql = mysql_query("SELECT id, username, date, ROUND(price,2) AS price, SUM(item_fee) AS fee, item_fee, SUM(sold) AS sales, SUM(ROUND(price,2)) AS total FROM product WHERE MONTH(date) = MONTH(DATE_ADD(CURDATE(),INTERVAL -1 MONTH)) GROUP BY username" ) or die(mysql_error()); if (mysql_num_rows($get_item_sql) < 1) { //invalid item $display_block .= "<p><em>Invalid item selection.</em></p>"; } else { //valid item, get info while ($item_info = mysql_fetch_array($get_item_sql)) { $item_username = $item_info['username']; $item_date = $item_info['date']; $item_price = $item_info['price']; $item_fee = $item_info['fee']; $image_fees = $item_fee * .20; $item_sold = $item_info['sales']; $get_sold = mysql_query("SELECT SUM(ROUND(price,2)) AS total, SUM(ROUND(sold,2)) AS sales, date, username FROM product WHERE sold = '1' AND MONTH(date) = MONTH(DATE_ADD(CURDATE(),INTERVAL -1 MONTH)) GROUP BY username") or die(mysql_error()); if (mysql_num_rows($get_sold) < 1) { //invalid item $display_block .= "<p><em>Invalid item selection.</em></p>"; } else { //valid item, get info while ($item_sold2 = mysql_fetch_array($get_sold)) { $item_sales = $item_sold2['total']; $item_price = ($item_sold2['total']) * .03; $item_amount_due = $image_fees + $item_price; $content .= "<form action=\"add_artist.php\" method=\"post\"><table class=\"anotherfont\" width=\"670\" border=\"0\"> <tr><td width=\"201\">{$item_username}</td> <td width=\"109\">{$item_fee}</td> <td width=\"109\">{$image_fees}</td> <td width=\"109\"> {$item_sales}</td> <td width=\"109\"> {$item_price}</td> <td width=\"109\"><input name=\"balance_due\" type=\"text\" value=\"{$item_amount_due}\" /></td> </tr><br /></table></form>"; } } } } Hi! I'm a total stupid newbie. Please humor me. So, I'm trying to make a guestbook, just as practice. So far I have a form that writes entries to a file, each entry on a new line. Entries look like this: Code: [Select] 11:11 am, Oct 12th, 2010|name|website|message My dividing character between parts of the entries is the vertical bar. I don't know if that's a bad idea. As I said, I'm a newb. I should probably find out how to make a code that makes it so people can't use that character in the form. Anyway, this is my code so far trying to display the entries. So far, I just want to show the date of the first entry. $file = fopen("posts.txt", 'rb'); while(!feof($file) && fgetc($file) != "|"){ $date = $date.fgetc($file); } echo $date; fclose($file); I already have a problem. The code does stop at the vertical bar, but instead of showing the date as "11:11 am, Oct 12th, 2010" it shows "11 m c 2h 00". I'm just super confused, and I don't know what to do. Thanks. (: This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=352551.0 Hi there,
I'm a bit of a noobie, and I have a class which will allow me to send an email in html.
However when I send an email with a link such as <a href="http://www.google.com">link</a> using the html() function
The email is sent and everything is displayed corrected.
However the link isn't clickable.
Here is the code for the class.
<? class eMail { var $to = array(); var $cc = array(); var $bcc = array(); var $attachment = array(); var $boundary = ""; var $header = ""; var $subject = ""; var $body = ""; function eMail($name,$mail) { $this->boundary = md5(uniqid(time())); $this->header .= "From: $name <$mail>\n"; } function to($mail) { $this->to[] = $mail; } function cc($mail) { $this->cc[] = $mail; } function bcc($mail) { $this->bcc[] = $mail; } function attachment($file) { $this->attachment[] = $file; } function subject($subject) { $this->subject = $subject; } function text($text) { $this->body = "Content-Type: text/plain; charset=ISO-8859-1\n"; $this->body .= "Content-Transfer-Encoding: 8bit\n\n"; $this->body .= $text."\n"; } function html($html) { $this->body = "Content-Type: text/html; charset=ISO-8859-1\n"; $this->body .= "Content-Transfer-Encoding: quoted-printable\n\n"; $this->body .= "<html><body>\n".$html."\n</body></html>\n"; } function send() { // CC $max = count($this->cc); if($max>0) { $this->header .= "Cc: ".$this->cc[0]; for($i=1;$i<$max;$i++) { $this->header .= ", ".$this->cc[$i]; } $this->header .= "\n"; } // BCC $max = count($this->bcc); if($max>0) { $this->header .= "Bcc: ".$this->bcc[0]; for($i=1;$i<$max;$i++) { $this->header .= ", ".$this->bcc[$i]; } $this->header .= "\n"; } $this->header .= "MIME-Version: 1.0\n"; $this->header .= "Content-Type: multipart/mixed; boundary=$this->boundary\n\n"; $this->header .= "This is a multi-part message in MIME format\n"; $this->header .= "--$this->boundary\n"; $this->header .= $this->body; // Attachment $max = count($this->attachment); if($max>0) { for($i=0;$i<$max;$i++) { $file = fread(fopen($this->attachment[$i], "r"), filesize($this->attachment[$i])); $this->header .= "--".$this->boundary."\n"; $this->header .= "Content-Type: application/x-zip-compressed; name=".$this->attachment[$i]."\n"; $this->header .= "Content-Transfer-Encoding: base64\n"; $this->header .= "Content-Disposition: attachment; filename=".$this->attachment[$i]."\n\n"; $this->header .= chunk_split(base64_encode($file))."\n"; $file = ""; } } $this->header .= "--".$this->boundary."--\n\n"; foreach($this->to as $mail) { mail($mail,$this->subject,"",$this->header); } } } ?> Hi i am trying to order data however i get a problem. The problem is that it orders the data but only by the first number! Example: (Place 1) Freid001: 981 (Place 2) mark: 90000 (Place 3) Tom: 5 (Place 4) Ash 1000 Here is the code i am using: $query = "SELECT * FROM Game ORDER BY XP"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); echo "<table border='0'>"; echo "<tr> <th>User</th> <th>XP</th> </tr>"; while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "</td><td>"; echo $row['User'] ; echo "</td><td>"; echo $row['XP']; } echo "</table>"; ?> Thanks in my mysql query, after the results have been grouped is there any way to count the results? i have a end result like this: 784 | x.x.x.x 754 | x.x.x.x 784 | x.x.x.x so how can i count the first column after its been grouped by IPs? here is my query: SELECT * FROM `hits`GROUP BY ip Currently we have a Microsoft Access database which we use to display a report, we are rolling over to PHP/SQL online for greater control e.t.c. So far we have the report pulling all the information from the database however we need to group this information by Day followed by Employee, sorted by time and then totaled for each Employee for each day. Below is the code we have so far which only prints columns how do we go about displaying it like the access screenshot. Attached is an example of the Microsoft Access report we have. Code: [Select] <?php $username='admin'; $password='password'; $database='planner'; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM reservations ORDER BY start_date, machid, starttime"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <?php $i=0; while ($i < $num) { $f0=mysql_result($result,$i,"machid"); $f1=mysql_result($result,$i,"start_date"); $f2=mysql_result($result,$i,"end_date"); $f3=mysql_result($result,$i,"starttime"); $f4=mysql_result($result,$i,"endtime"); $f5=mysql_result($result,$i,"first_name"); $f6=mysql_result($result,$i,"last_name"); $f7=mysql_result($result,$i,"company"); $f8=mysql_result($result,$i,"phone_number"); $f9=mysql_result($result,$i,"site_address"); $f10=mysql_result($result,$i,"site_suburb"); $f11=mysql_result($result,$i,"site_postcode"); $f12=mysql_result($result,$i,"postal_address"); $f13=mysql_result($result,$i,"postal_suburb"); $f14=mysql_result($result,$i,"postal_postcode"); $f15=mysql_result($result,$i,"job_type"); $f16=mysql_result($result,$i,"payment_type"); $f17=mysql_result($result,$i,"payment_status"); $f18=mysql_result($result,$i,"quote_outcome"); $f19=mysql_result($result,$i,"quote_amount"); $f20=mysql_result($result,$i,"quote_employee"); $f21=mysql_result($result,$i,"job_income"); $f22=mysql_result($result,$i,"job_materials"); $f23=mysql_result($result,$i,"invoice_number"); $f24=mysql_result($result,$i,"job_notes"); /* START TIME */ $stime = $f3; $shour = floor($stime/60); $smin = str_pad($stime % 60,2,0,STR_PAD_LEFT); //echo $hour.':'.$min; //echo '<br><br>'; // For AM/PM $shalf = 'am'; if( $shour > 12 ) { $shalf = 'pm'; $shour -= 12; } $stime = $shour.':'.$smin.' '.$shalf; /* END TIME */ $etime = $f4; $ehour = floor($etime/60); $emin = str_pad($etime % 60,2,0,STR_PAD_LEFT); //echo $hour.':'.$min; //echo '<br><br>'; // For AM/PM $ehalf = 'am'; if( $ehour > 12 ) { $ehalf = 'pm'; $ehour -= 12; } $etime = $ehour.':'.$emin.' '.$ehalf; ?> <table width="3500px" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="125px"><?php echo $f0; ?></td> <td width="80px"><?php echo date('d-m-y', "$f1"); ?></td> <td width="50px" style="text-align:right;"><?php echo $stime; ?></td> <td width="50px" style="text-align:right; padding-right:20px;"><?php echo $etime; ?></td> <td width="100px"><?php echo $f5; ?></td> <td width="100px"><?php echo $f6; ?></td> <td width="100px"><?php echo $f7; ?></td> <td width="100px"><?php echo $f8; ?></td> <td width="100px"><?php echo $f9; ?></td> <td width="100px"><?php echo $f10; ?></td> <td width="100px"><?php echo $f11; ?></td> <td width="100px"><?php echo $f12; ?></td> <td width="100px"><?php echo $f13; ?></td> <td width="100px"><?php echo $f14; ?></td> <td width="100px"><?php echo $f15; ?></td> <td width="100px"><?php echo $f16; ?></td> <td width="100px"><?php echo $f17; ?></td> <td width="100px"><?php echo $f18; ?></td> <td width="100px"><?php echo $f19; ?></td> <td width="100px"><?php echo $f20; ?></td> <td width="100px"><?php echo $f21; ?></td> <td width="100px"><?php echo $f22; ?></td> <td width="100px"><?php echo $f23; ?></td> <td width="100px"><?php echo $f24; ?></td> <?php $i++; } ?> Once again thanks everyone at phpfreaks! Hi. I have the following code where I grab the names and average overall rating from my database and group by the name. Code: [Select] $sql="SELECT name, AVG(overall) AS overall FROM $tbl_name GROUP BY name ORDER BY AVG(overall) DESC"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ Does anybody know how I can count the number of names that have been grouped together? For instance: Name Overal ratingl John 2 Pete 5 John 8 It should group the john's, calculate the average rating (8+2)/2=5, and then show that there have been 2 johns making up the 5 rating? I've tried using the code below and messed around with it loads but cant get it to work: Code: [Select] $sql="SELECT name, AVG(overall) AS overall FROM $tbl_name COUNT name GROUP BY name ORDER BY AVG(overall) DESC"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ echo $rows['Count name']; Thanks in advance. Hello im working on a project which involves marking attendance via an RFID tag and saving the time into an sql file. Everything seems to be working fine and the time stamp is successfully punched into the SQL but something is wrong with the php code thats supposed to display this data. Please if any one can take a look and help.
MY CODE for displaying the data (ViewAttendance.php): <?php include_once("header.php"); $attData = array(); $totDays = 0; if(isset($_REQUEST['submit'])){ $totDays = cal_days_in_month(CAL_GREGORIAN,$_REQUEST['month'],$_REQUEST['year']); $attData = $commonObj->getAttendanceData($_REQUEST['month'],$_REQUEST['year']); //print_r($attData); //print_r(date("d",strtotime($attData[0]['punch_time']))); } ?> <div class="container"> <div class="row"> <div class="col-sm-12"> <h4>Showing Attendance</h4> <form name="showAtt" method="post"> <div class="col-sm-4"><label>Select Month</label> <select name="month" class="form-control"> <?php for($i=1;$i<=12;$i++){?> <option value="<?php echo $i;?>"><?php echo $i;?></option> <?php }?> </select> </div> <div class="col-sm-4"><label>Select Year</label> <select name="year" class="form-control"> <?php for($i=date("Y");$i>=2010;$i--){?> <option value="<?php echo $i;?>"><?php echo $i;?></option> <?php }?> </select> </div> <div class="col-sm-4"> <p> </p> <input type="submit" value="Show" name="submit" class="btn btn-primary"> </div> </form> </div> </div> <div class="row"> <div class="col-sm-2"> <label class="btn btn-success btn-sm">Month:<?php echo @$_REQUEST['month'];?></label> </div> <div class="col-sm-2"><label class="btn btn-info btn-sm">Year: <?php echo @$_REQUEST['year'];?></label></div> </div> <div class="row"> <div class="col-sm-12" style="overflow: scroll;"> <?php if($totDays>0){?> <table class="table table-striped"> <tr> <th> Employee Name </th> <?php for($i=1;$i<=$totDays;$i++){?> <th> <?php echo $i;?> </th> <?php }?> <?php foreach($attData as $attk=>$attv){ $punchin = $commonObj->getTimeOfDate($attData[$attk]['punchin']); $punchout = $commonObj->getTimeOfDate($attData[$attk]['punchout']); ?> <tr> <th class="danger"> <?php echo $attv['name'];?> </th> <?php for($i=1;$i<=$totDays;$i++){?> <?php if($commonObj->getDayOfDate($attData[$attk]['punch_time']) == $i){ echo "<td class='success' id='att_$i'>".$punchin.'-'.$punchout;?> <table class="table table-responsive"style="display: none; position:relative;min-width:100px;max-width:200px; margin-top: -40px;" id="<?php echo "det_att_".$i;?>"> <tr> <td>Total hours:</td> <td><?php echo $commonObj->getHoursBetweenDates($attData[$attk]['punchin'],$attData[$attk]['punchout']);?> </td></tr> <tr> <td>UID:</td> <td><?php echo $attData[$attk]['rfid_uid'];?></td> </tr> </table> <?php }else {echo "<td class='info'>#na";}?> </td> <?php }?> </tr> <?php }?> </tr> </table> <?php }?> </div> </div> </div> </body> </html> <script> $(document).ready(function(){ $("td").hover( function () { var id = "#det_"+this.id; $(id).css({"display":"block"}); }, function () { var id = "#det_"+this.id; $(id).css({"display":"none"}); //console.log(id); //$(id).css("display","block"); }); }); </script> Display of (ViewAttendance.php):
MY SQL TABLE :
Howdy, I'm trying to display text from a table in a database. It's a list of quotes, so I just need to pull out the quote and the author name. However, the quote and name are not fields in the same record; they are separate records. Example data: Code: [Select] quoteid name value 1 content You guys are great! Thanks for being awesome. 1 author John Jackson 2 content Gosh you're amazing! Always been so darn helpful! 2 author Peter Davis So, I just need to rip out the data from 'content' and 'author', and then group them together based on the quoteid. This is my code thus far: $testimonial_resource = mysql_query("SELECT name, value FROM quotes GROUP BY quoteid ORDER BY author ASC") or die(mysql_error()); while ($testimonial = mysql_fetch_assoc($testimonial_resource)) { echo '<p>'.$testimonial['value']'.<br /><strong>'.$testimonial['value'].'</strong></p>'; } Any help would be greatly appreciated for this novice. Cheers. |