ryangrom Posted September 20, 2009 Share Posted September 20, 2009 I have a form setup to send data via SQL to an email. Everything works fine but my client would like the output in the email to be displayed in a more asthetic looking table. Here is the code that renders the email output: while ($row = mysql_fetch_object($query)) { $string .= "Store: ".$row->storenum."<br>"."Submitted Date: ".$row->created_at."<br>"."Transactions: ".$row->spacer."<br>"."11:00-11:30am: ".$row->Trans11."<br>"."11:30-12:00pm: ".$row->Trans1130."<br>"."12:00-12:30pm: ".$row->Trans12."<br>"."12:30-1:00pm: ".$row->Trans1230."<br>"."1:00-1:30pm: ".$row->Trans01."<br>"."1:30-2:00pm: ".$row->Trans0130."<br>"."Sales: ".$row->Spacer."<br>"."11:00-11:30am: ".$row->Sales11."<br>"."11:30-12:00pm: ".$row->Sales1130."<br>"."12:00-12:30pm: ".$row->Sales12."<br>"."12:30-1:00pm: ".$row->Sales1230."<br>"."1:00-1:30pm: ".$row->Sales01."<br>"."1:30-2:00pm: ".$row->Sales0130."<br>"."Scheduled Hours: ".$row->Spacer."<br>"."11:00-11:30am: ".$row->shedhr11."<br>"."11:30-12:00pm: ".$row->shedhr1130."<br>"."12:00-12:30pm: ".$row->shedhr12."<br>"."12:30-1:00pm: ".$row->shedhr1230."<br>"."".$row->shedhr01."<br>"."1:30-2:00pm: ".$row->shedhr0130."<br>"."Ideal Hours: ".$row->Spacer."<br>"."11:00-11:30am: ".$row->idhr11."<br>"."11:30-12:00pm: ".$row->idhr1130."<br>"."12:00-12:30pm: ".$row->idhr12."<br>"."12:30-1:00pm: ".$row->idhr1230."<br>"."1:00-1:30pm: ".$row->idhr01."<br>"."1:30-2:00pm: ".$row->idhr0130."<br>"."Actual Hours: ".$row->Spacer."<br>"."11:00-11:30am: ".$row->acthr11."<br>"."11:30-12:00pm: ".$row->acthr1130."<br>"."12:00-12:30pm: ".$row->acthr12."<br>"."12:00-12:30pm: ".$row->acthr1230."<br>"."1:00-1:30pm: ".$row->acthr01."<br>"."1:30-2:00pm: ".$row->acthr0130."<br>"."Difference: ".$row->Spacer."<br>"."11:00-11:30am: ".$row->diffhr11."<br>"."11:30-12:00pm: ".$row->diffhr1130."<br>"."12:00-12:30pm: ".$row->diffhr12."<br>"."12:30-1:00pm: ".$row->diffhr1230."<br>"."1:00-1:30pm: ".$row->diffhr01."<br>"."1:30-2:00pm: ".$row->diffhr0130."<br>"."Notes: ".$row->note."<br>"; } Its one huge line pulling from the SQL database. I've tried using standard html to make a table out of this long line of code but the email stops sending and it displays no error message. My question is how should i go about setting up a table for this data. if i do it with that line, then i have problems. how can I chop it up and make a table out of this output? I need the different time slots(1:30-2:00pm for instance) as the table headers, and I need the data to be in the same column as the data for the coresponding time slot.. see diagram:(data in blue is data that is sumitted in the form and displayed here via sql) Store number: 5003 | 11:00-11:30am | 11:30-12:00pm | 12:00-12:30pm |12:30-1:00pm | 1:00-1:30 pm |1:30-2:00pm | Transactions: | 20 | 12 | Sales: | 234 | 155 | Scheduled Hours: | 23 | 45 | Actual Hours: | 21 | 123 | Ideal Hours: | 17 | 123 | Difference: | 4 | 0 | This is how i need it to look when finished. -------------------------------------------------------------------------------------------------------------------------- The folowing is how it looks right now with the code as is: Store: 5001 Submitted Date: 2009-09-18 Transactions: 11:00-11:30am: 233 11:30-12:00pm: 12 12:00-12:30pm: 365 12:30-1:00pm: 325 1:00-1:30pm: 123 1:30-2:00pm: etc Sales: 11:00-11:30am: 11:30-12:00pm: 12:00-12:30pm: 12:30-1:00pm: 1:00-1:30pm: 1:30-2:00pm: Scheduled Hours: 11:00-11:30am: 11:30-12:00pm: 12:00-12:30pm: 12:30-1:00pm: 1:00-1:30pm: 1:30-2:00pm: Ideal Hours: 11:00-11:30am: 11:30-12:00pm: 12:00-12:30pm: 12:30-1:00pm: 1:00-1:30pm: 1:30-2:00pm: Actual Hours: 11:00-11:30am: 11:30-12:00pm: 12:00-12:30pm: 12:00-12:30pm: 1:00-1:30pm: 1:30-2:00pm: Difference: 11:00-11:30am: 11:30-12:00pm: 12:00-12:30pm: 12:30-1:00pm: 1:00-1:30pm: 1:30-2:00pm: Thank you in advance for any help in advance that you can give me on this. I normally get what i need via googling PHP/HTML help pages, but the help pages i have found have not helped me get it, and its over my head this time. Quote Link to comment Share on other sites More sharing options...
ozestretch Posted September 20, 2009 Share Posted September 20, 2009 can you provide the code you used to generate the table? Quote Link to comment Share on other sites More sharing options...
ryangrom Posted September 20, 2009 Author Share Posted September 20, 2009 its not in a table yet is the prob. i need to make it a table like the diagram i showed. if you meant the code i used to make the form i spoke of then it gets tricky because i used a form generator to make it. the code that handles how the form is organized and displayed is in a .swf file that is computer gibberish when opened up. other than that its 2 php files and an xml file but i dont see any other code other than what i posted that deals with the displaying of the data i need displayed into a table. im not looking for a copy/paste snippet. i just need to know how to take that really long line of code i posted and make it into a table. im not sure how to even start the table is the problem becuase it doesnt accept basic html table code in that line without causing the email to not send anymore. Quote Link to comment Share on other sites More sharing options...
raccoon Posted September 20, 2009 Share Posted September 20, 2009 If you don't want to use tables, one way to do it would be to use str_pad() [help: http://ca2.php.net/manual/en/function.str-pad.php ] str_pad (string $input , int $pad_length) $pad_length should be longer than the longest column (in characters) in each column. And then use one <br /> for each line. You would need to set the font to a fixed width typeface for it to work though. Tell me if you need an example. Quote Link to comment Share on other sites More sharing options...
ozestretch Posted September 21, 2009 Share Posted September 21, 2009 As line breaks seem to be ok with your email, this should be fine, add your data in first <?php $string .='<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="952"> <tr> <th bgcolor="#C0C0C0" width="154">Store number: '.$row->storenum.'<br />'.$row->created_at.'</th> <th bgcolor="#C0C0C0" width="133">11:00-11:30am</th> <th bgcolor="#C0C0C0" width="133">11:30-12:00pm</th> <th bgcolor="#C0C0C0" width="133">12:00-12:30pm</th> <th bgcolor="#C0C0C0" width="133">12:30-1:00pm</th> <th bgcolor="#C0C0C0" width="133">1:00-1:30 pm</th> <th bgcolor="#C0C0C0" width="133">1:30-2:00pm</th> </tr> <tr> <td width="154" align="right">Transactions:</td> <td width="133" align="center">'.$row->Trans11.'</td> <td width="133" align="center">you can put the rest in </td> <td width="133" align="center"> </td> <td width="133" align="center"> </td> <td width="133" align="center"> </td> <td width="133" align="center"> </td> </tr> <tr> <td width="154" align="right">Sales:</td> <td width="133" align="center">35</td> <td width="133" align="center"> </td> <td width="133" align="center"> </td> <td width="133" align="center"> </td> <td width="133" align="center"> </td> <td width="133" align="center"> </td> </tr> <tr> <td width="154" align="right">Scheduled Hours:</td> <td width="133" align="center">45</td> <td width="133" align="center"> </td> <td width="133" align="center"> </td> <td width="133" align="center"> </td> <td width="133" align="center"> </td> <td width="133" align="center"> </td> </tr> <tr> <td width="154" align="right">Actual Hours:</td> <td width="133" align="center">etc..</td> <td width="133" align="center"> </td> <td width="133" align="center"> </td> <td width="133" align="center"> </td> <td width="133" align="center"> </td> <td width="133" align="center"> </td> </tr> <tr> <td width="154" align="right">Ideal Hours:</td> <td width="133" align="center"> </td> <td width="133" align="center"> </td> <td width="133" align="center"> </td> <td width="133" align="center"> </td> <td width="133" align="center"> </td> <td width="133" align="center"> </td> </tr> <tr> <td width="154" align="right">Difference: </td> <td width="133" align="center"> </td> <td width="133" align="center"> </td> <td width="133" align="center"> </td> <td width="133" align="center"> </td> <td width="133" align="center"> </td> <td width="133" align="center"> </td> </tr> </table>'; ?> Quote Link to comment Share on other sites More sharing options...
ozestretch Posted September 21, 2009 Share Posted September 21, 2009 You could go on to make it like so throughout the above code <?php $string='<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="952">'; $string.=' <tr>'; $string.=' <th bgcolor="#C0C0C0" width="154">Store number: '.$row->storenum.'<br />'.$row->created_at.'</th>'; $string.=' <th bg etc... Can't be nukcered myself, but you should lol Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.