Jump to content

Explode Issues Or Alternate Insert Options


gramphp

Recommended Posts

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.

 

Link to comment
Share on other sites

 

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.