PHP - Formatting Output
Hi, I am trying to print my database records into a php page. I am able to succesfully print the values however the values are being duplicated. For example If I have two records in the employee_details, every these two records are being printed twice on my php page. can anyone tell me the reason why? The output that I see is as follows
7 7 3a7cf5162a9c0a5014c92021e7ca0bf0 3a7cf5162a9c0a5014c92021e7ca0bf0 Bryan Bryan 4111 4111 Admin Admin 6 6 6743c3d1519ab4f2cd9a78ab09a511bd 6743c3d1519ab4f2cd9a78ab09a511bd Raul Raul 601 W Yandell Dr, 601 W Yandell Dr, Admin Admin <html> <head> </head> <body> <?php mysql_connect("localhost","root",""); mysql_select_db("encryption") or die(mysql_error()); $query = mysql_query("select * from employee_details"); ?> <table> <?php for($counter = 0;$row=mysql_fetch_array($query); $counter++) { print ("<tr>"); foreach($row as $key=> $value) print ("<td>$value</td>"); print ("</tr>"); } ?> </table> </body> </html> Similar TutorialsHi, Has anyone come across an issue when saving DOM to a file and Code: [Select] $document->preserveWhiteSpace = false; $document->formatOutout = true; has no effect? I have a mysql database that has your typical data in it, ie. name address, etc. The problem I am having is with the address. The address is setup as a varchar with 200 as the length and the data is street, city, st, zip on 1 line. I need to format the output with street on 1 line and city, st, zip on another. I cannot change input format because of the way the program uses the address string to fetch the lat and lng before it writes it to the database. Is there a way to add a line break or <br> to the address before it is written or change it after it is written using sql or php script or possible as I format the output? The street, city, st, zip are separated by commas in the record. Thanks in advance for all the reply's Hi, I'm trying to achieve a special output of dates. I essentially have an array of dates like so: // dates in yyyy-mm-dd format $dates = array('2005-05-21', '2006-11-01', '2006-11-02', '2020-09-28', '2020-09-29', '2020-09-30', '2020-10-01'); I need to output theses dates like so: 05 may 2005 01, 02 november 2006 28, 29, 30 september 2020 01 october 2020
I'm really not sure how to go about this. I'm sure this must be possible. Any help would be great!! Thanks a bunch! Pat Hi all I have a PHP script with the following var print $date; at the moment it is formatting the date like 03-24-2010 is it possible to get PHP to switch the date and month, so it looks like 24-03-2010 Thanks I have this report that I have written and it looks fine on the screen but the printed output is to big for the page and very ugly. How would I reformat it so it prints better.
<html> <head> <title>Load Report</title> </head> <body> <h1>Load Report</h1> <?php $load=$_POST["Load_ID"]; $connect =odbc_connect("removed"); if(!$connect) { exit("Connection Failed: " . $connect); } $sql="SELECT m1_DC.dbo.SalesOrders.UOMPDROPSEQUENCE ,m1_DC.dbo.organizationlocations.cmlPhoneNumber ,m1_DC.dbo.organizationlocations.cmlName ,m1_DC.dbo.organizationlocations.UCMLSTOREHOURSTXT ,m1_DC.dbo.SalesOrders.OMPSHIPPINGMETHODID ,m1_DC.dbo.SalesOrders.UOMPTRUCKNUMBER ,m1_DC.dbo.SalesOrders.ompCustomerPO ,m1_DC.dbo.SalesOrders.UOMPTOTALBOXCOUNT ,m1_DC.dbo.SalesOrders.UOMPVOLUMETOTAL ,m1_DC.dbo.organizationlocations.CMLADDRESSLINE1 ,m1_DC.dbo.organizationlocations.CMLADDRESSLINE2 ,m1_DC.dbo.organizationlocations.CMLCITY ,m1_DC.dbo.organizationlocations.CMLSTATE ,m1_DC.dbo.organizationlocations.CMLPOSTCODE ,m1_DC.dbo.SalesOrders.OMPREQUESTEDSHIPDATE ,m1_DC.dbo.SalesOrders.ompSalesOrderID ,m1_DC.dbo.SalesOrders.ompOrderTotalBase ,convert(varchar(10),m1_DC.dbo.SalesOrders.uompbuilddate,110) as BuildDate FROM m1_DC.dbo.SalesOrders LEFT OUTER JOIN m1_DC.dbo.organizationlocations ON ompshiporganizationid = cmlorganizationid AND ompshiplocationid = cmllocationid WHERE m1_DC.dbo.SalesOrders.UOMPTRUCKNUMBER='$load' Union All SELECT m1_KF.dbo.SalesOrders.UOMPDROPSEQUENCE ,m1_KF.dbo.organizationlocations.cmlPhoneNumber ,m1_KF.dbo.organizationlocations.cmlName ,m1_KF.dbo.organizationlocations.UCMLSTOREHOURSTXT ,m1_KF.dbo.SalesOrders.OMPSHIPPINGMETHODID ,m1_KF.dbo.SalesOrders.UOMPTRUCKNUMBER ,m1_KF.dbo.SalesOrders.ompCustomerPO ,m1_KF.dbo.SalesOrders.UOMPTOTALBOXCOUNT ,m1_KF.dbo.SalesOrders.UOMPVOLUMETOTAL ,m1_KF.dbo.organizationlocations.CMLADDRESSLINE1 ,m1_KF.dbo.organizationlocations.CMLADDRESSLINE2 ,m1_KF.dbo.organizationlocations.CMLCITY ,m1_KF.dbo.organizationlocations.CMLSTATE ,m1_KF.dbo.organizationlocations.CMLPOSTCODE ,m1_KF.dbo.SalesOrders.OMPREQUESTEDSHIPDATE ,m1_KF.dbo.SalesOrders.ompSalesOrderID ,m1_KF.dbo.SalesOrders.ompOrderTotalBase ,convert(varchar(10),m1_KF.dbo.SalesOrders.uompbuilddate,110) FROM m1_KF.dbo.SalesOrders LEFT OUTER JOIN m1_KF.dbo.organizationlocations ON ompshiporganizationid = cmlorganizationid AND ompshiplocationid = cmllocationid WHERE m1_KF.dbo.SalesOrders.UOMPTRUCKNUMBER='$load' order by UOMPDROPSEQUENCE"; $result =odbc_exec($connect,$sql); if(!$result){ exit("Error in SQL"); } $data= ''; while (odbc_fetch_row($result)) { $UOMPDROPSEQUENCE=odbc_result($result,"UOMPDROPSEQUENCE"); $cmlName=odbc_result($result,"cmlName"); $cmlPhoneNumber=odbc_result($result,"cmlPhoneNumber"); $UCMLSTOREHOURSTXT=odbc_result($result,"UCMLSTOREHOURSTXT"); $ompCustomerPO=odbc_result($result,"ompCustomerPO"); $UOMPTOTALBOXCOUNT=odbc_result($result,"UOMPTOTALBOXCOUNT"); $UOMPVOLUMETOTAL=odbc_result($result,"UOMPVOLUMETOTAL"); $CMLADDRESSLINE1=odbc_result($result,"CMLADDRESSLINE1"); $CMLADDRESSLINE2=odbc_result($result,"CMLADDRESSLINE2"); $CMLCITY=odbc_result($result,"CMLCITY"); $CMLSTATE=odbc_result($result,"CMLSTATE"); $CMLPOSTCODE=odbc_result($result,"CMLPOSTCODE"); $ompSalesOrderID=odbc_result($result,"ompSalesOrderID"); $ompOrderTotalBase=odbc_result($result,"ompOrderTotalBase"); $uompbuilddate=odbc_result($result,"BuildDate"); { { if($UOMPDROPSEQUENCE % 2 == 0 ) {$style = '#FFFAFA';} else {$style = '#D3D3D3';}} } $data .= "<tr bgcolor=$style><th>$UOMPDROPSEQUENCE</th>"; $data .= "<th style='text-align:left' height='10'>$cmlName</th>"; $data .= "<td style='text-align:left' height='10'>$UCMLSTOREHOURSTXT</td>"; $data .= "<td style='text-align:center' height='10'>$ompCustomerPO</td>"; $data .= "<td style='text-align:center' height='10'>$UOMPTOTALBOXCOUNT</td>"; $data .= "<td style='text-align:center' height='10'> $UOMPVOLUMETOTAL</td>"; $data .= "<td style='text-align:center' height='10'> $CMLADDRESSLINE1</td>"; $data .= "<td style='text-align:center' height='10'> $CMLADDRESSLINE2</td>"; $data .= "<td style='text-align:center' height='10'> $CMLCITY</td>"; $data .= "<td style='text-align:center' height='10'> $CMLSTATE</td>"; $data .= "<td style='text-align:center' height='10'> $CMLPOSTCODE</td>"; $data .= "<td style='text-align:center' height='10'>$ompSalesOrderID</td>"; $data .= "<td style='text-align:center' height='10'>$ompOrderTotalBase</td>"; //$data .= "<td style='text-align:center'>$uompbuilddate</td>"; $data .= "<td style='text-align:center' height='10'>$cmlPhoneNumber</td></tr>"; } echo "<table><tr>"; echo "<th>Load $load</th><tr>"; echo "<th>Drop</th>"; echo "<th>Name</th>"; echo "<th>Note</th>"; echo "<th>PO</th>"; echo "<th>Box_count</th>"; echo "<th>Cubes</th>"; echo "<th>ADDRESSLINE</th>"; echo "<th>ADDRESS2</th>"; echo "<th>CITY</th>"; echo "<th>STATE</th>"; echo "<th>ZIP</th>"; echo "<th>Order_ID</th>"; echo "<th>Order_Total</th>"; //echo "<th>Build-Date</th>"; echo "<th> Phone </th></tr>"; echo $data; odbc_close($connect); ?> </body> </html> Well I have a script that executes a scan on a system set to run infinitely, and I need it to echo out a message each time it loops through, but I don't want it to echo out the message with the next loop message below it, and the next one below that etc... I've tried using the flush(); function and been messing around with that with no luck. For security reasons I don't want to release any of the processing code, but here is the basic construction of the script: <?PHP ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** $RepeatIt = -1; for($g=1; $g!=$RepeatIt+1; $g++) { ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** $ScanMessage = ":.:.: SCANNING THE HITLIST FOR MOBSTER: ".$MobName." (SCAN #$g) :.:.:"."<br/><br/>"; echo $ScanMessage; ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** } ?> At the moment it's returning: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #1) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #2) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #3) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #4) :.:.: So what I want it to do is just delete the scanning message and replace it with the next scan message so while running this script you would see just the number increment on the same line. Any suggestions? Thanks. Hi, I want to chenge the following statement so that numbers ending with ".00" are changed to blank. Many opinions but I haven't got any to work. Any help? <td align=right class="currency">$'.number_format($row['value1'],2).'</td> I'm not sure what I'm doing wrong. I have a date in a table which is formatted as: 2010-08-13 00:00:00. I am trying to change the date through PHP to display as 08-13-2010. The date is being formatted as 12-31-1969. Here's my code. if($registrant->StatusDate != '0000-00-00 00:00:00') { $formattedDate = date('m-d-Y', $registrant->StatusDate); $statusDate = ' as of ' . $formattedDate; } Can anyone advise me what I am doing wrong? Thanks! I am having a problem with what is probably encoding. I am pulling strings from a WordPress database. Below is a sample string: Code: [Select] Sed nec neque quis sapien scelerisque aliquet. In in est odio, ac auctor erat. Vestibulum fringilla dapibus sodales. Morbi facilisis egestas arcu, eu semper mi luctus vitae. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Suspendisse sollicitudin, metus sed hendrerit tristique, enim ante venenatis metus, ac consectetur mauris lorem et felis. Phasellus ac purus massa. Aliquam ligula mauris, iaculis et posuere vitae, pellentesque sit amet leo. Praesent at eros et lacus scelerisque feugiat. Aliquam non facilisis libero. Ut blandit leo ut tortor convallis porttitor. Aliquam erat volutpat. Aliquam rhoncus rutrum metus, tempor sollicitudin ante laoreet in. Sed tincidunt nibh a augue euismod sagittis. Fusce ullamcorper ultricies nisi, sit amet elementum mi scelerisque eget. Cras sed elit ligula, sit amet aliquam lectus. Nulla vel mollis nibh. Pellentesque ultricies, dui non aliquam eleifend, tortor ligula blandit dolor, quis interdum diam augue non eros. Nullam id molestie nunc. Integer id tempus est. When WordPress displays this text, it is formatted correctly, with spaces between paragraphs, etc. When I pull the string from the database, and echo it onto a page, the spaces between paragraphs are replaced by spaces, so in the end the output is as follows: Code: [Select] Sed nec neque quis sapien scelerisque aliquet. In in est odio, ac auctor erat. Vestibulum fringilla dapibus sodales. Morbi facilisis egestas arcu, eu semper mi luctus vitae. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Suspendisse sollicitudin, metus sed hendrerit tristique, enim ante venenatis metus, ac consectetur mauris lorem et felis. Phasellus ac purus massa. Aliquam ligula mauris, iaculis et posuere vitae, pellentesque sit amet leo. Praesent at eros et lacus scelerisque feugiat. Aliquam non facilisis libero. Ut blandit leo ut tortor convallis porttitor. Aliquam erat volutpat. Aliquam rhoncus rutrum metus, tempor sollicitudin ante laoreet in. Sed tincidunt nibh a augue euismod sagittis. Fusce ullamcorper ultricies nisi, sit amet elementum mi scelerisque eget. Cras sed elit ligula, sit amet aliquam lectus. Nulla vel mollis nibh. Pellentesque ultricies, dui non aliquam eleifend, tortor ligula blandit dolor, quis interdum diam augue non eros. Nullam id molestie nunc. Integer id tempus est. What can I do to follow WordPress' formatting? I'm going round in circles with this one, but I have a feeling that the answer is obvious. I have POST information that I want to use as a date and display it using date format, but I don't know how to The POST data outputs the following: 2011-9-23 Assuming I have defined $date as the posted data from the previous form, how do I write some code to tell it to output it as September 23, 2011, or just Sept 2011? Hi there, So I have data which I am fetching from two tables link in a one-to-many relationship using the following code: sql = "select authcourses.id as id, title, date_format(closingdate, '%d.%m.%y') as date, name from authcourses inner join authorities on authorityid = authorities.id order by authorityid"; $result = mysqli_query($link, $sql); if(!$result) { $error = 'Unable to get list of authorities'; include '../../error.html.php'; exit(); } while ($row = mysqli_fetch_array($result)) { $authcourses[] = array('name' => $row['name'], 'title' => $row ['title'], 'date' => $row['date'], 'id' => $row['id']); } I then output the data in a table like this: Code: [Select] <table> <thead><th>Title</th><th>Closing Date</th><th>Action</th></thead> <tbody> <?php foreach ($authcourses as $authcourse): ?> <tr> <form action="?" method="post"> <tr> <td><?php htmlout($authcourse['name']); ?></td> <!-- custom function htmlout($text) see helpers.inc.php --> <td><?php htmlout($authcourse['title']); ?></td> <td><?php htmlout($authcourse['date']); ?></td> <td> <input type="hidden" name="id" value="<?php echo $authcourse['id']; ?>" /> <input type="submit" name="action" value="Edit" /> <input type="submit" name="action" value="Delete" /> </td> </tr> </form> <?php endforeach; ?> </tbody> </table> The htmlout() is a custom function which is basically "echo htmlspecialchars($str)", and you can ignore the form stuff. I get an out put like this: York, Course 1, 2011-02-15 York, Course 2, 2011-03-01 Manchester, Course 3, 2011-06-17 Manchester, Course 4, 2011-08-12 Derby, Course 5, 2011-01-10 Barnet, Course 6, 2011-08-19 Barnet, Course 7, 2011-06-23 etc etc... What I want is something like this: York: Course 1, date Course 2, date Manchester: Course 3, date Course 4, date Derby: Course 5, date Barnet: Course 6, date Course 7, date etc.. I guess I'd like to load an array for each of the authorities (cities) with the course info, then I can output it in my form like this: Code: [Select] <?php foreach ($authcourses as $authcourse): ?> <h1><?php htmlout($authcourse['name'] ?>: </h1> <?php foreach ($courses as $course): ?> <p><?php htmlout($course['title'];?><p> <p><?php htmlout($course['date'];?></p> <?php endforeach; ?> <?php endforeach; ?> I hope that makes sense... Any help would be great. Cheers, Mike I've been wracking my brain trying to figure this simple problem out and I can't for the life of me figure out the best way to do it. I have the following array: $n = array('81.0', '80.5', '70.5', '67.0', '65.5'); I only want to display the numbers to one decimal place if it's not a whole number, like so. 81 80.5 70.5 67 65.5 I've tried looking for a solution with sprintf(), rtrim() and number_format(), but what's the best way to do it? Regards Rich Hi, When I do this the result is a date of zeros? $DateAndTime = date('d-m-y', strtotime($DateAndTime)); All I want is a date in format of DD0MM-YYY and the Time in HH:MM::SS Any help would be great! I know it is basic, Thanks in advance So I have this page that outputs a sql query for required courses (healthcare field) and creates an email based on user input (variable). The email sends and I receive the information but the format is jacked up. My markup in the email shows. As an example, I should be getting this. Course Date Mandt Recert 1/16/2011 AWMD Recert 9/15/2010 etc, etc. What I currently get in the email is this: <table width=100% class="style11"><th align="left"><u>Course</u></th><th align="left"><u>Complete By</u></th><th align="left"> <th><tr><td width=33%>Abuse Neglect and Exploitation</td><td width=10%>12-31-1997</td><td width=33%></td></tr><tr><td width=33%>BloodBorne Pathogens Video</td><td width=10%>04-18-2008</td><td width=33%></td></tr><tr><td width=33%>MANDT Recert</td><td width=10%>08-11-2010</td><td width=33%></td></tr><tr><td width=33%>AWMD Recert</td><td width=10%>06-28-2011</td><td width=33%></td></tr><tr><td width=33%>CPR/1st Aid Combo</td><td width=10%>07-16-2012</td><td width=33%></td></tr></table></body></html> <?php //connect to the database include 'dbcommon.php'; $conn = mysql_connect($dbhost, $username, $password) or die("Could not show the required classes." . mysql_error($conn)); mysql_select_db($dbname); //grab the classes that are required $query="SELECT course, date_last_taken, certification FROM course_completions WHERE employee_id='" . $_REQUEST['employid'] . "' order by date_last_taken asc"; $rs = mysql_query($query, $conn); $numrequired = mysql_num_rows($rs); $emailtext .= "<table width=100% class=\"style11\">"; $emailtext .= "<th align=\"left\"><u>Course</u></th><th align=\"left\"><u>Complete By</u></th><th align=\"left\"> <th>"; if ($numrequired == 0) { $emailtext .= "<html>\n"; $emailtext .= "<body>"; $emailtext .= "<tr><td colspan=3>No classes required</td></tr>"; } while ($results = mysql_fetch_array($rs)) { $emailtext .= "<tr>"; $emailtext .= "<td width=33%>"; $emailtext .= $results["course"]; $emailtext .= "</td>"; $emailtext .= "<td width=10%>"; $emailtext .= date("m-d-Y",strtotime($results["date_last_taken"])); $emailtext .= "</td>"; $emailtext .= "<td width=33%>"; $emailtext .= "</td>"; $emailtext .= "</tr>"; } $emailtext .= "</table>"; $emailtext .= "</body>"; $emailtext .= "</html>"; echo $emailtext; mysql_close($conn); $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n"; //email the results/ $email = $_REQUEST["email"]; $comment = "message1"; $subject = " ARCA Required Courses "; $message = $emailtext; mail($email, $subject, $message); if ($mail) { echo "Email sent, click <a href=displaycourses.php?" . SID . ">here</a> to return."; } else { echo "There was a problem sending the email."; } ?> I'm sure the syntax isn't correct somewhere but I need help with the output of the email formatting. Thanks! Hi everyone, I am having some odd issues with sending php generated emails. Essentially, what I'd like to know is how can I ensure they go into the inbox, and not get shunted to the junk mail folder. I assume this is s formatting issue, and it only happens sometimes. I am creating html emails. I have included my headers below: $headers = "From: <Real Money Help>\r\n"; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; Any help would be appreciated. Thanks. This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=346474.0 I want a little online users list at the bottom of my page and the color of the username is to match the color defined in the database. but how do i get them to align side by side? if i add them to a <p> they will all appear under neath each other. Heres my current code: $sql=mysql_query("SELECT * FROM ".DB_PREFIX."members WHERE online = 1"); while ($row = mysql_fetch_object($sql)) { echo '<p style="color: #'.$row->username_color.';">'.$row->username.'</p>'; } also i want a comma at the end of each but how do i stop it adding a comma to the end of the last one? Hi all, I have features on my website which require a time limit untill they can do the thing agian, but at the current mintue ive got the time in seconds. How can I make a function which will give the time in minutes instaid of seconds. Example: If it was a 2 mintue waiting time instaid of being 120 Seconds it will be 2min(s) 0sec(s). Example of my Current Code: $timewaiting = time() + 160; // Waiting time. (2min) if ($user->lasttime > time()){ $howlongleft = $user->lasttime - time(); echo ("You must wait $howlongleft"); Thanks for any help given. I always struggle with keeping my annotations pretty. Just about ever IDE beautifies PHP, there are many online PHP beautifiers, and notepad++ and other apps are available. None of them seem to work with annotations. Also, would like to validate them at the same time. Anyone know of any plugins or websites which do this? I would be fine with just cutting and pasting just the comment block and it need not format the entire PHP script (I probably wouldn't even use the PHP portions as git would probably see changes). If nothing is available, suppose I could create one myself. Before doing so, however, would like to better understand best practices. For instance, how many spaces for indentations, what is acceptable to put inline (i.e. the @ORM\Table item should definitely not be on a single line), etc. Thank! /** * @ORM\Entity() * @ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(name="unique_position_serie", columns={"test_chart_id", "position"}), @ORM\UniqueConstraint(name="unique_name_serie", columns={"test_chart_id", "name"})}) * @ApiResource( * collectionOperations={ * "get" = { * "method"="GET", * }, * "post" = { * } * }, * itemOperations={ * "get" = { * "openapi_context" = { * "parameters" = { * { * "name" = "nameOfQueryParameter", * "in" = "query", * "description" = "Description goes here", * "schema" = { * "type" = "string" * } * } * } * } * }, * "put" = { * }, * "patch" = { * }, * "delete" = { * } * } * ) */
Hi there, I need a PHP number format to match one and all of these sequence of numbers: 8500.00 9999.99 15.00 0.00 |