Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I group rows with same time from mysql query?
    text
    copied!<p>I have the following code:</p> <pre><code>//set $message and run database query $message .= '&lt;body style="margin: 0;"&gt;'; $message .= '&lt;div style="padding: 0 20px;"&gt;'; $message .= '&lt;span style="display: block; font-size: 22px; font-weight: bold; margin: 25px 0 -15px 0;"&gt; User Activity on ' . $website . ' for ' . $yesterday . '&lt;/span&gt;'; //query the database for today's history $result = mysql_query("SELECT * FROM user_history WHERE date = '$yesterday' ORDER by name, time, title") or die(mysql_error()); $old_user = ''; while($row = mysql_fetch_array( $result )) { $new_user = $row['uid']; if ($new_user != $old_user) { $message .= '&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;' . '&lt;span style="font-size: 18px; font-weight: bold;"&gt;' . $row['name'] . '&lt;/span&gt;' . '&lt;br /&gt;' . $row['company'] . '&lt;br /&gt;' . $row['email'] . '&lt;br /&gt;' . $row['phone'] . '&lt;br /&gt;&lt;br /&gt;'; $old_user = $new_user; } $message .= '&lt;ul&gt;&lt;li&gt;' . $row['time'] . '&lt;ul&gt;&lt;li&gt;' . $row['title'] . ' (&lt;a href="' . $row['url'] . '"&gt;' . $row['url']. '&lt;/a&gt; )' . '&lt;/li&gt;&lt;/ul&gt;' . '&lt;br /&gt;&lt;br /&gt;' . '&lt;/li&gt;&lt;/ul&gt;'; } //if no user activity, simply say so if($new_user == "") { $message .= '&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;span style="font-size: 18px; font-weight: bold;"&gt;No user activity to report&lt;/span&gt;'; } $message .= '&lt;/div&gt;'; $message .= '&lt;div style="position: fixed; bottom: 0; height: 40px; width: 100%; margin: 20px 0 0 0; background: #000; color: #FFF; line-height: 40px; padding: 0 20px;"&gt;' . 'Report generated ' . $date . ' ' . $time . '&lt;/div&gt;'; $message .= '&lt;/body&gt;'; </code></pre> <p>It works beautifully in the mail function. The output email groups like this...</p> <p>John Doe <br /> John Doe's Company <br /> johndoe@johndoeco.com <br /> 800-555-0000<br /> <br /></p> <p>*1:30pm <br /> *Video 1 <br /><br /></p> <p>*1:47pm <br /> *Video 2 <br /><br /></p> <p>*1:47pm <br /> *Video 3 <br /><br /></p> <p>============================== <br /><br /></p> <p>Instead, I'd like to output like this:<br /><br /></p> <p>John Doe <br /> John Doe's Company <br /> johndoe@johndoeco.com <br /> 800-555-0000<br /> <br /></p> <p>*1:30pm <br /> *Video 1 <br /><br /></p> <p>*<strong>1:47pm <br /> *Video 2 <br /> *Video 3 <br /><br /></strong></p> <p>============================= <br /><br /></p> <p>Can someone please tell me how to make this happen? Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload