gramphp Posted December 4, 2011 Share Posted December 4, 2011 Hi all, I am still learning all the variations of code commonly used with sites. I have one particular issue of which I am having trouble locating an answer or returning a proper result. I want to be able to use one page to query a distinct date, say 1-1-11 and the results return with the other columns matching this date and separating the time to be displayed for the entry row. So it would look something like this in the results. Acct: Tester User: John.Smith Time: 1:30 PM Currently there are 4 columns to the table, ID, Acct, Logintime, User. I have tried splitting this off the table but that fails out, unless someone knows an insert command to enter date and time individually. This would make it much easier for my purposes as well. Below is one of the many codes I have tried for this from examples. <?php $con = mysql_connect("localhost","gram","compassion"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("tester", $con); $result = mysql_query("SELECT * FROM test_history"); echo "<table border='1'> <tr> <th>Date:</th> <th>Time:</th> </tr>"; while($row = mysql_fetch_array($result)) (explode(" ",$row['logintime'])); echo $row[0]; echo $row[1]; { echo "<tr>"; echo "<td>" . $row[0] . "</td>"; echo "<td>" . $row[1] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> I know I am newb but I am a fast learner if I can merely get some points in the right direction. Quote Link to comment https://forums.phpfreaks.com/topic/252427-explode-issues-or-alternate-insert-options/ Share on other sites More sharing options...
btellez Posted December 4, 2011 Share Posted December 4, 2011 Your loop section looks disturbing, you are probably looking for something closer to the following, (if i'm guessing right) while($row = mysql_fetch_array($result)) { /* explode returns an array with your pieces, so assuming login time is split into 2 parts by the space, it should work(eg: "PARTA PARTB" or "MM/DD/YYYY HH:MM:SS") */ $timePieces = explode(" ",$row['logintime']); echo "<tr>"; echo "<td>" . $timePieces[0] . "</td>"; echo "<td>" . $timePieces[1] . "</td>"; echo "</tr>"; } As a side note you may want to look into loop syntax. Quote Link to comment https://forums.phpfreaks.com/topic/252427-explode-issues-or-alternate-insert-options/#findComment-1294200 Share on other sites More sharing options...
trq Posted December 4, 2011 Share Posted December 4, 2011 Just format Logintime to return only the time. SELECT ID, Acct, DATE_FORMAT(Logintime, '%h:%i %p'), User FROM test_history Quote Link to comment https://forums.phpfreaks.com/topic/252427-explode-issues-or-alternate-insert-options/#findComment-1294201 Share on other sites More sharing options...
gramphp Posted December 4, 2011 Author Share Posted December 4, 2011 The first response works great, ty so much. I am also going to test the other just to verify the quickness of each of them. Quote Link to comment https://forums.phpfreaks.com/topic/252427-explode-issues-or-alternate-insert-options/#findComment-1294210 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.