zelig Posted May 8, 2012 Share Posted May 8, 2012 Okay, I have a field called "created" in my `users` table, and I'd like to be able to view it in-game on an administrator panel. However, it's being captured in a long number format (i.e. 1335076320) which, I believe, has to deal with seconds and such. How can I take that number and convert it to an actual date/time output? Here's how I currently have it coded in my php form: <tr><td width="20%">Registered On:</td><td>{{created}}</td></tr> So, obviously it's not converting it to any format, rather just pulling that 1335076320 number out. Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/262262-displaying-a-date-from-a-registered-field/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 8, 2012 Share Posted May 8, 2012 See the following link on how to convert a Unix timestamp to a datetime value in your query when you select the data. You can use the second format parameter to get the result into any format you need - http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_from-unixtime Quote Link to comment https://forums.phpfreaks.com/topic/262262-displaying-a-date-from-a-registered-field/#findComment-1344026 Share on other sites More sharing options...
zelig Posted May 8, 2012 Author Share Posted May 8, 2012 Okay, so I need to pull a second query just on the `created` field to be able to present it in the right format? I have an initial query that pulls everything from the `users` table, as I'm trying to make it so that the administrators can see everything as it relates to that specific user. Here's my whole code. Maybe that will help. function edituser($id) { global $player; if (isset($_POST["submit"])) { extract($_POST); $errors = 0; $errorlist = ""; if ($email == "") { $errors++; $errorlist .= "Email is required.<br />"; } if ($hometown == "") { $errors++; $errorlist .= "Hometown is required.<br />"; } if ($password == "") { $errors++; $errorlist .= "Password is required.<br />"; } if ($race == "") { $errors++; $errorlist .= "Race is required.<br />"; } if ($class == "") { $errors++; $errorlist .= "Class is required.<br />"; } if ($rank == "") { $errors++; $errorlist .= "Rank is required.<br />"; } if ($gender == "") { $errors++; $errorlist .= "Gender is required.<br />"; } if ($eyes == "") { $errors++; $errorlist .= "Eyes is required.<br />"; } if ($hair == "") { $errors++; $errorlist .= "Hair is required.<br />"; } if ($skin == "") { $errors++; $errorlist .= "Skin is required.<br />"; } if ($build == "") { $errors++; $errorlist .= "Build is required.<br />"; } if ($height == "") { $errors++; $errorlist .= "Height is required.<br />"; } if ($gender == "") { $errors++; $errorlist .= "Gender is required.<br />"; } if ($hp == "") { $errors++; $errorlist .= "Current HP is required.<br />"; } if ($mp == "") { $errors++; $errorlist .= "Current MP is required.<br />"; } if ($energy == "") { $errors++; $errorlist .= "Current energy is required.<br />"; } if ($maxhp == "") { $errors++; $errorlist .= "Max HP is required.<br />"; } if ($maxmp == "") { $errors++; $errorlist .= "Max MP is required.<br />"; } if ($maxenergy == "") { $errors++; $errorlist .= "Max energy is required.<br />"; } if (!is_numeric($hp)) { $errors++; $errorlist .= "Current HP must be a number.<br />"; } if (!is_numeric($mp)) { $errors++; $errorlist .= "Current MP must be a number.<br />"; } if (!is_numeric($energy)) { $errors++; $errorlist .= "Current energy must be a number.<br />"; } if (!is_numeric($maxhp)) { $errors++; $errorlist .= "Max HP must be a number.<br />"; } if (!is_numeric($maxmp)) { $errors++; $errorlist .= "Max MP must be a number.<br />"; } if (!is_numeric($maxenergy)) { $errors++; $errorlist .= "Max energy must be a number.<br />"; } if ($errors == 0) { $updatequery = <<<END UPDATE users SET email="$email", admin="$admin", hometown="$hometown", password="$password", race="$race", class="$class", rank="$rank", gender="$gender", eyes="$eyes", hair="$hair", skin="$skin", build="$build", height="$height", spouse="$spouse", fame="$fame", gfame="$gfame", quests="$quests", flags="$flags", gold="$gold", credits="$credits", bank="$bank", hp="$hp", maxhp="$maxhp", energy="$energy", maxenergy="$maxenergy", mp="$mp", maxmp="$maxmp", plevel="$plevel", experience="$experience", strength="$strength", agility="$agility", vitality="$vitality", wisdom="$wisdom", escape="$escape", interest="$interest", minecount="$minecount", stat_bonus="$stat_bonus" WHERE id="$id" END; $query = doquery($updatequery, "users"); admindisplay("User updated.","Edit Users"); } else { admindisplay("<b>Errors:</b><br /><div style=\"color:red;\">$errorlist</div><br />Please go back and try again.", "Edit Users"); } } $query = doquery("SELECT * FROM users WHERE id='$id'", "users"); $row = mysql_fetch_array($query); $iclass = $player->class; global $controlrow; $page = <<<END <b><u>Edit Users</u></b><br /><br /> <form action="admin_panel.php?do=edituser:$id" method="post"> <table width="90%"> <tr><td width="20%">ID:</td><td>{{id}}</td></tr> <tr><td width="20%">Username:</td><td>{{username}}</td></tr> <tr><td width="20%">Email:</td><td><input type="text" name="email" size="30" maxlength="100" value="{{email}}" /></td></tr> <tr><td width="20%">Password:</td><td><input type="text" name="password" size="30" maxlength="8" value="{{password}}" /></td></tr> <tr><td width="20%">Admin Level:</td><td><input type="text" name="admin" size="30" maxlength="30" value="{{admin}}" /></td></tr> <tr><td width="20%">Registered On:</td><td>{{created}}</td></tr> <tr><td width="20%">Last Online:</td><td>{{last_login}}</td></tr> <tr><td width="20%">Last IP:</td><td>{{ip}}</td></tr> <tr><td width="20%">Flags:</td><td><input type="text" name="flags" size="30" maxlength="1055" value="{{flags}}" /></td></tr> <tr><td colspan="2" style="background-color:#cccccc;"> </td></tr> <tr><td width="20%">Hometown:</td><td><input type="text" name="hometown" size="15" maxlength="30" value="{{hometown}}" /></td></tr> <tr><td width="20%">Race:</td><td><input type="text" name="race" size="10" maxlength="30" value="{{race}}" /></td></tr> <tr><td width="20%">Class:</td><td><input type="text" name="class" size ="10" maxlength="30" value="{{class}}" /></td></tr> <tr><td width="20%">Rank:</td><td><input type="text" name="rank" size="15" maxlength="15" value="{{rank}}" /></td></tr> <tr><td width="20%">Gender:</td><td><input type="text" name="gender" size="15" maxlength="25" value="{{gender}}" /></td></tr> <tr><td width="20%">Eyes:</td><td><input type="text" name="eyes" size="15" maxlength="30" value="{{eyes}}" /></td></tr> <tr><td width="20%">Hair:</td><td><input type="text" name="hair" size="15" maxlength="30" value="{{hair}}" /></td></tr> <tr><td width="20%">Skin:</td><td><input type="text" name="skin" size="15" maxlength="30" value="{{skin}}" /></td></tr> <tr><td width="20%">Build:</td><td><input type="text" name="build" size="15" maxlength="30" value="{{build}}" /></td></tr> <tr><td width="20%">Height:</td><td><input type="text" name="height" size="15" maxlength="30" value="{{height}}" /></td></tr> <tr><td width="20%">Spouse:</td><td><input type="text" name="spouse" size="15" maxlength="30" value="{{spouse}}" /></td></tr> <tr><td colspan="2" style="background-color:#cccccc;"> </td></tr> <tr><td width="20%">Fame:</td><td><input type="text" name="fame" size="5" maxlength="10" value="{{fame}}" /></td></tr> <tr><td width="20%">GFame:</td><td><input type="text" name="gfame" size="5" maxlength="2" value="{{gfame}}" /></td></tr> <tr><td width="20%">Quests:</td><td><input type="text" name="quests" size="5" maxlength="5" value="{{quests}}" /></td></tr> <tr><td width="20%">Gold:</td><td><input type="text" name="gold" size="5" maxlength="6" value="{{gold}}" /></td></tr> <tr><td width="20%">Bank:</td><td><input type="text" name="bank" size="5" maxlength="30" value="{{bank}}" /></td></tr> <tr><td width="20%">Interest:</td><td><input type="text" name="interest" size="5" maxlength="3" value="{{bank}}" /></td></tr> <tr><td width="20%">Credits:</td><td><input type="text" name="credits" size="5" maxlength="3" value="{{credits}}" /></td></tr> <tr><td colspan="2" style="background-color:#cccccc;"> </td></tr> <tr><td width="20%">Current Player Level:</td><td><input type="text" name="plevel" size="5" maxlength="6" value="{{plevel}}" /></td></tr> <tr><td width="20%">Current HP:</td><td><input type="text" name="hp" size="5" maxlength="6" value="{{hp}}" /></td></tr> <tr><td width="20%">Max HP:</td><td><input type="text" name="maxhp" size="5" maxlength="6" value="{{maxhp}}" /></td></tr> <tr><td width="20%">Current MP:</td><td><input type="text" name="mp" size="5" maxlength="6" value="{{mp}}" /></td></tr> <tr><td width="20%">Max MP:</td><td><input type="text" name="maxmp" size="5" maxlength="6" value="{{maxmp}}" /></td></tr> <tr><td width="20%">Current Energy:</td><td><input type="text" name="energy" size="5" maxlength="6" value="{{energy}}" /></td></tr> <tr><td width="20%">Max Energy:</td><td><input type="text" name="maxenergy" size="5" maxlength="6" value="{{maxenergy}}" /></td></tr> <tr><td width="20%">Strength:</td><td><input type="text" name="strength" size="5" maxlength="5" value="{{strength}}" /></td></tr> <tr><td width="20%">Agility:</td><td><input type="text" name="agility" size="5" maxlength="5" value="{{agility}}" /></td></tr> <tr><td width="20%">Vitality:</td><td><input type="text" name="vitality" size="5" maxlength="5" value="{{vitality}}" /></td></tr> <tr><td width="20%">Wisdom:</td><td><input type="text" name="wisdom" size="5" maxlength="5" value="{{wisdom}}" /></td></tr> <tr><td width="20%">Escape:</td><td><input type="text" name="escape" size="5" maxlength="5" value="{{escape}}" /></td></tr> <tr><td width="20%">Bonus:</td><td><input type="text" name="stat_bonus" size="5" maxlength="3" value="{{stat_bonus}}" /></td></tr> <tr><td colspan="2" style="background-color:#cccccc;"> </td></tr> <tr><td width="20%">Description:</td><td>{{description}}</td></tr> <tr><td width="20%">Weapon:</td><td>{{weapon}}</td></tr> <tr><td width="20%">Head:</td><td>{{head}}</td></tr> <tr><td width="20%">Neck:</td><td>{{neck}}</td></tr> <tr><td width="20%">Body:</td><td>{{body}}</td></tr> <tr><td width="20%">Shield:</td><td>{{shield}}</td></tr> <tr><td width="20%">Shoulders:</td><td>{{shoulders}}</td></tr> <tr><td width="20%">Arms:</td><td>{{arm}}</td></tr> <tr><td width="20%">Hands:</td><td>{{hands}}</td></tr> <tr><td width="20%">Fingers:</td><td>{{finger}}</td></tr> <tr><td width="20%">Wrists:</td><td>{{wrists}}</td></tr> <tr><td width="20%">Legs:</td><td>{{legs}}</td></tr> <tr><td width="20%">Feet:</td><td>{{feet}}</td></tr> <tr><td width="20%">Guild:</td><td>{{guild}}</td></tr> <tr><td colspan="2" style="background-color:#cccccc;"> </td></tr> <tr><td width="20%">Frozen:</td><td>{{frozen}}</td></tr> <tr><td width="20%">Muted:</td><td>{{muted}}</td></tr> <tr><td width="20%">Deaf:</td><td>{{deaf}}</td></tr> </table> <input type="submit" name="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" /> </form> END; $page = parsetemplate($page, $row); admindisplay($page, "Edit Users"); } Quote Link to comment https://forums.phpfreaks.com/topic/262262-displaying-a-date-from-a-registered-field/#findComment-1344044 Share on other sites More sharing options...
Jessica Posted May 8, 2012 Share Posted May 8, 2012 No, you do it when you select it, as he said. Quote Link to comment https://forums.phpfreaks.com/topic/262262-displaying-a-date-from-a-registered-field/#findComment-1344045 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.