what's with this number string?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

what's with this number string?

Post by m3rajk »

i was having issues with the forums when it was loading and getting no errors. i decided to go to sleep for the night. i think php restarted because i got notices now which i hadn't been getting even after switching from E_ALL ~E_NOTICE to E_ALL

in any case, the notices allowed me to figure out why i wasn't seeing anything (combined with an echo to track doen bugs) but now i have another issue, i'm getting a number string that i don't understand where it's coming from. i want to get rid of JUST the number string but since i don't understand what's causing it....

could anyone tell me what's causing this number string (taken from a view while logged out):
test:

test:1062417559
Problems/Suggestions 0

test:10624175591062417560
Problems/Suggestions 0
Fakes 0

test:10624175591062417560
Problems/Suggestions 0
Fakes 0

test:10624175591062417560
Problems/Suggestions 0
Fakes 0
from this code:

Code: Select all

function getforums($ual, $db, $utds, $gmtos){ # get the forum listing by user access level, db link
  include('/home/joshua/includes/fyd.altincs.php'); # includes file
  $findforums=mysql_query("SELECT * FROM forums", $db); # get forum info
  $forumlist=''; # create an empty list. that will be filled with forums
  
  while($foruminf=mysql_fetch_array($findforums)){ // while we can retrieve more forums
    $fal=$foruminf['access']; # get forum access level
    if($fal==$visitor){ # if everyone can see
      $forum=$foruminf['title']; $fid=$foruminf['forum_id']; $threads=$foruminf['threads'];
      $lauth=$foruminf['last_post_auth']; $lpt=$foruminf['last_post_time']; # who/when of last post
      $lpt=gmmktime($utds, (toTimestamp($lpt)+($gmtos*60*60))); # change to the user's time format/zone
      $forumlist.="       <tr><td><a href="forums.php?fid=$fid">$forum</a></td><td>$threads</td><td>$lauth</td><td></td>$l
pt</tr>\n"; # add the row with the forum
    }elseif($fal==$rmember){ # restricted to members
      if((contains($ual, $regulars))||(contains($ual, $desireds))){ # if you're signed in
        $forum=$foruminf['title']; $fid=$foruminf['forum_id']; $threads=$foruminf['threads'];
        $lauth=$foruminf['last_post_auth']; $lpt=$foruminf['last_post_time']; # who/when of last post
        $lpt=gmmktime($utds, (toTimestamp($lpt)+($gmtos*60*60))); # change to user's time format/zone
        $forumlist.="     <tr><td><a href="forums.php?fid=$fid">$forum</a></td><td>$threads</td><td>$lauth</td><td></td>$l
pt</tr>\n"; # add the row with the forum
      }
    }elseif($fal==$pmember){ # resticted to paying members
      if(contains($ual, $desireds)){ # you're a paying member
        $forum=$foruminf['title']; $fid=$foruminf['forum_id']; $threads=$foruminf['threads'];
        $lauth=$foruminf['last_post_auth']; $lpt=$foruminf['last_post_time']; # who/when of last post
        $lpt=gmmktime($utds, (toTimestamp($lpt)+($gmtos*60*60))); # change to user's time format/zone
        $forumlist.="     <tr><td><a href="forums.php?fid=$fid">$forum</a></td><td>$threads</td><td>$lauth</td><td></td>$l
pt</tr>\n"; # add the row with the forum
      }
    }elseif($fal==$adult){ # restricted to those verified 18+
      if(contains($ual, $adult)){ # you're verified 18+
        $forum=$foruminf['title']; $fid=$foruminf['forum_id']; $threads=$foruminf['threads'];
        $lauth=$foruminf['last_post_auth']; $lpt=$foruminf['last_post_time']; # who/when of last post
        $lpt=gmmktime($utds, (toTimestamp($lpt)+($gmtos*60*60))); # change to user's time format/zone
        $forumlist.="     <tr><td><a href="forums.php?fid=$fid">$forum</a></td><td>$threads</td><td>$lauth</td><td></td>$l
pt</tr>\n"; # add the row with the forum
      }
    }elseif($fal==$admoap){ # restricted to moderators/approvers/(jr) admins
      if((contains($ual, $moderators))||(contains($ual, $approvers))){ # you're a mod/app/...
        $forum=$foruminf['title']; $fid=$foruminf['forum_id']; $threads=$foruminf['threads'];
        $lauth=$foruminf['last_post_auth']; $lpt=$foruminf['last_post_time']; # who/when of last post
        $lpt=gmmktime($utds, (toTimestamp($lpt)+($gmtos*60*60))); # change to user's time format/zone
        $forumlist.="     <tr><td><a href="forums.php?fid=$fid">$forum</a></td><td>$threads</td><td>$lauth</td><td></td>$l
pt</tr>\n"; # add the row with the forum
      }
    }elseif($fal==$admin){ # restricted to (jr) admins
      if(($ual==$wbm)||($ual==$adm)||($ual==$jra)){ # you're on the admin team
        $forum=$foruminf['title']; $fid=$foruminf['forum_id']; $threads=$foruminf['threads'];
        $lauth=$foruminf['last_post_auth']; $lpt=$foruminf['last_post_time']; # who/when of last post
        $lpt=gmmktime($utds, (toTimestamp($lpt)+($gmtos*60*60))); # change to user's time format/zone
        $forumlist.="     <tr><td><a href="forums.php?fid=$fid">$forum</a></td><td>$threads</td><td>$lauth</td><td></td>$l
pt</tr>\n"; # add the row with the forum
      }
    }
    echo "<p>test:<table>$forumlist</table></p>";
  }
  return $forumlist;
}
note: it's also in the print out used in the display, so i do need to track it down
User avatar
PixelMaster
Forum Newbie
Posts: 11
Joined: Sat Aug 16, 2003 11:48 am

Post by PixelMaster »

A few random thoughts ... which may or may not be of any help ...
Simplifying your code and making it a bit easier to read would really help in rooting out the problem. Also, I'm not sure why the exact same variable assignments are made within each condition of the if/elseif... chain. (Btw, a switch statement would come in handy with those).
In any case, those numbers look awfully like timestamps ... Which leads me to ask: is toTimestamp() a function you wrote yourself? Because it's not listed in the PHP manual at php.net ...
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

I don't have time to check really thoroughly but, some quick thoughts.

I think there is a deeper problem which is leading to the specific problem: one-big-function-itis. This makes code much harder to follow and so makes bugs both more likely and harder to track down. Some refactoring might be in order.

For example, this bit of code:

Code: Select all

<?php
        $forum=$foruminf['title']; $fid=$foruminf['forum_id']; $threads=$foruminf['threads'];
        $lauth=$foruminf['last_post_auth']; $lpt=$foruminf['last_post_time']; # who/when of last post
        $lpt=gmmktime($utds, (toTimestamp($lpt)+($gmtos*60*60))); # change to user's time format/zone
        $forumlist.="     <tr><td><a href="forums.php?fid=$fid">$forum</a></td><td>$threads</td><td>$lauth</td><td></td>$l
pt</tr>\n"; # add the row with the forum 
?>
.. is repeated several times and so is a candidate for its own function definition. That way it's only written out once. Anything repeated - even repeating script patterns - should be captured in a new piece of code.

For example, "draw a list" is a pattern. You could write a generic function to deal with lists such as the table rows example here. The fn would also be re-usable in other scripts.

My own preference is to keep html out of php. That helps to slim the page down allowing you to focus on what's going on.

There are an awful lot of if/else steps. That's often a sign that a redesign is in order.

I noticed you seem to be checking if the user is an admin/etc in every loop: only forum table info will change on each loop so don't check anything else in there. User level checks should be run before the loop.

Hope that is helpful.
Last edited by McGruff on Wed Aug 10, 2005 6:48 pm, edited 1 time in total.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

mcgruff: that sounds like a good idea.. making the actual change to a list it's own function. it will allow me to add more cases easier

the while loop anctually does two things: firs it finds the access level of the forum (who should be allowed to view it) then it checks the users access level (ual) against an array to see if the user is in that group. and may access the forum. if so it prints it out.


toTimeStamp takes a mysql datetimefeild and converts it to a unix timestamp. i made it.

and that brings up a question.... did i have an echo there left over from debugging that?
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

PixelMaster wrote:A few random thoughts ... which may or may not be of any help ...
Simplifying your code and making it a bit easier to read would really help in rooting out the problem. Also, I'm not sure why the exact same variable assignments are made within each condition of the if/elseif... chain. (Btw, a switch statement would come in handy with those).
In any case, those numbers look awfully like timestamps ... Which leads me to ask: is toTimestamp() a function you wrote yourself? Because it's not listed in the PHP manual at php.net ...
the toTimestamp function: (because i couldn't findanything to do this)

Code: Select all

function toTimestamp($dateTime){  # turn a mysql datetime into a unix timestamp
  $year=substr($dateTime,0,4); $month=substr($dateTime,5,2); $day=substr($dateTime,8,2); # find all the
  $hour=substr($dateTime,11,2); $min=substr($dateTime,14,2); $sec=substr($dateTime,17,2); # parts of time
  $ts=gmmktime($hour,$min,$sec,$month,$day,$year); # get the unix timestamp
  return $ts; # return it
}
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Just an adding:
UNIX_TIMESTAMP()
UNIX_TIMESTAMP(date)
If called with no argument, returns a Unix timestamp (seconds since '1970-01-01 00:00:00' GMT) as an unsigned integer. If UNIX_TIMESTAMP() is called with a date argument, it returns the value of the argument as seconds since '1970-01-01 00:00:00' GMT. date may be a DATE string, a DATETIME string, a TIMESTAMP, or a number in the format YYMMDD or YYYYMMDD in local time:
If you "select UNIX_TIMESTAMP('your_date_field') from table" you will ger something you can use, rather than the function above.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

m3rajk wrote:the while loop anctually does two things: firs it finds the access level of the forum (who should be allowed to view it) then it checks the users access level (ual) against an array to see if the user is in that group. and may access the forum. if so it prints it out.
I'm very tired and I haven't tested any of this code but it should at least illustrate some ideas.

First let's look at a buildTableRow utility which could be something like this - vary to suit:

Code: Select all

<?php

/*
    A sample utility to build table rows in a loop.

    builds table rows, and only table rows - open and close <table> tags in the calling script
    
    $tr - whatever attributes you want to assign to tr tags
    
    $td - an array of td attributes 
    one for every $values element ie count($td) == count($values)
    using an array lets you have different styles/widths etc per cell if required

    $values - an array of values to print in this row

*/
function buildTableRow($tr, $td, $values)
{
	$row = '<tr ' . $tr . '>';

	for($i=0;$i<count($values);$i++)
	{
		$row .= $'<td ' . $td[$i] . '>';
		$row .= $values[$i];
		$row .= '</td>';
	}
    $row .= '</tr>';
    return $row;
}
?>
Now, back to your script. Replacing if/else's with variable functions has a dramatic effect, replacing the mass of code in the loop with just three lines:

Code: Select all

<?php
// just showing the while loop here
// declare outside the loop where possible
$other_args = array('...see below...');
$tr = 'class="mystyle"';
$td = array('...td attributes..');

while($foruminf = mysql_fetch_array($findforums))
{
    // if you wanted to process any $foruminf values, do it here
    // .. but I'm just going to use the array as is:
    // As was mentioned, you can get the timestamp
    // .. with a mysql date fn.
    
    // variable functions: bye bye if/elseif's
    if({$foruminf['access'] . 'Forum'}($ual, $other_args)) 
    {
        $forumlist .= buildTableRow($tr, $td, $foruminf);
    }
}

?>
You need a function for each $fal case:

Code: Select all

<?php
// Build one of these function for each $fal case.
// Passing the other args might take a bit of thought..
// .. prolly just dump the lot in one array.
function adminForum($ual, $other_args)
{
    // access check here: 
    return TRUE/FALSE;
}    

?>
You can see how the original code can be drastically pared down. Lovely things happen when you rework code written as one big function. It becomes easier to read & debug - and you often wind up with a bunch of re-usable utilities.

(1) Split things into sub functions where you can, each fn carrying out a single task.

(2) Look for repeated blocks of code, or repeated patterns in code: these are almost certainly functions (or objects) in waiting.

(3) Try and think of related problems as well as the issue at hand. If you can create flexible fns to cover a wide range of uses they'll be more useful in future - but be careful not to add too much in.

One other point: it ought to be possible to use query logic to find only those forums for which the user has access, simplifying the script still further.
Last edited by McGruff on Wed Aug 10, 2005 6:38 pm, edited 1 time in total.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

mcgruff. i'm changing it a bit to do that, but i still need to check two things: what's the access level of the forum and what's the access level of the user. i grab rhe level of the user, but i can't simply then call the forums based on it.


i have regulare level, a visitor level, and an age restricted level.
then there's to admin levels. and i'm figuring when this launches that to get it to pay for itself i'll need to have ppl pay something nominal to use the site. to do that i need something draw them. i figure more search functions, html in their profile and extra forums might be enough of a draw. since that's seperate from the age restriction, i can't simply seach based on a number. in some cases there may be the paying level without age and visa versa

the most i can do is make an array of the needed arrays to check and have a for loop that does it instead of the nested foreaches
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

i think i figured it out....turns out there's a differnt issue i need to figure out now. but i figured that one out.

it was actually in the html (smething i figured would be the case since it was int he tests)

i had

Code: Select all

$forumlist.="       <tr><td><a href="forums.php?fid=$fid">$forum</a></td><td>$threads</td><td>$lauth</td><td></td>$lpt</tr>\n"; # add the row with the forum
the problem is in where $lpt is. it should have been

Code: Select all

$forumlist.="       <tr><td><a href="forums.php?fid=$fid">$forum</a></td><td>$threads</td><td>$lauth</td><td>$lpt</td></tr>\n"; # add the row with the forum
now i need to figure out why

Code: Select all

$lpt=gmmktime($utds, (toTimestamp($lpt)+($gmtos*60*60))); # change to user's time format/zone
is returning what looks to be a unix timestamp instead of a date in the format "m/d/Y H:i:s"
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

ok. the function that makes the forum listing (i sent that out to a diff function so i change things once as mcgruff suggested) is this:

Code: Select all

function mkfrmlst($foruminf, $utds, $gmtos){ // make a forum into a table string for display
  $forum=$foruminf['title']; $fid=$foruminf['forum_id']; $threads=$foruminf['threads']; // forum info
  $lauth=$foruminf['last_post_auth']; $lpt=$foruminf['last_post_time']; # who/when of last post
  $lpta=toTimestamp($lpt); $lptd=gmmktime($utds, ($lpta+($gmtos*60*60))); # change to user's time format/zone
  $tblln="        <tr><td><a href="forums.php?fid=$fid">$forum</a></td><td>$threads</td><td>$lauth</td><td>$lptd</td></tr>
\n"; # add the row with the forum
  
  echo "<p>test:$utds -> $gmtos<br />$lpt=\$foruminf['last_post_time']; < br />$lpta=toTimestamp($lpt); <br />$lptd=gmmktime
($utds, ($lpta+($gmtos*60*60)));</p>";
  
  return $tblln;
}
and the timestamp:

Code: Select all

function toTimestamp($dateTime){  # turn a mysql datetime into a unix timestamp
  $year=substr($dateTime,0,4); $month=substr($dateTime,5,2); $day=substr($dateTime,8,2); # find all the
  $hour=substr($dateTime,11,2); $min=substr($dateTime,14,2); $sec=substr($dateTime,17,2); # parts of time
  $ts=gmmktime($hour,$min,$sec,$month,$day,$year); # get the unix timestamp

  echo "<p>$year=substr($dateTime,0,4); <br />$month=substr($dateTime,5,2); <br />$day=substr($dateTime,8,2); <br />$hour=su
bstr($dateTime,11,2); <br />$min=substr($dateTime,14,2); <br />$sec=substr($dateTime,17,2); <br />$ts=gmmktime($hour,$min,$s
ec,$month,$day,$year);</p>";

  return $ts; # return it
}
the echos are there to debug.

i don't get why i'm getting -1 as a result from the toTimestamp function, but i am, as can be seen in this printout from the echos( i think that is what's causing the timestamp instead of display as a result of the gmmktime call):
0000=substr(0000-00-00 00:00:00,0,4);
00=substr(0000-00-00 00:00:00,5,2);
00=substr(0000-00-00 00:00:00,8,2);
00=substr(0000-00-00 00:00:00,11,2);
00=substr(0000-00-00 00:00:00,14,2);
00=substr(0000-00-00 00:00:00,17,2);
-1=gmmktime(00,00,00,00,00,0000);

test:m/d/Y H:i:s -> -5.00
0000-00-00 00:00:00=$foruminf['last_post_time']; < br />-1=toTimestamp(0000-00-00 00:00:00);
1062590357=gmmktime(m/d/Y H:i:s, (-1+(-5.00*60*60)));
when the toTimestamp function worked fine in the testsi used.. so much so that i adjusted the page for someone elseon here to use... as demoed by this that i took from a past backup

Code: Select all

<?php
include("/home/joshua/includes/fyd.incs.php"); # includes file
# this is a test to get utc/gmt times

$metime=date("Y-m-d H:i:s", time());
$gmttime=gmdate("Y-m-d H:i:s", time());
$gmttimestamp=time();
$year=substr($gmttime,0,4);
$month=substr($gmttime,5,2);
$day=substr($gmttime,8,2);
$hour=substr($gmttime,11,2);
$min=substr($gmttime,14,2);
$sec=substr($gmttime,17,2);
$ts=toTimestamp($gmttime);
$fts=gmdate("Y-m-d H:i:s", (toTimestamp($gmttime)+(-8*60*60)));

# forum print choices
$choice01=gmdate("m/d/Y H:i:s", (toTimestamp($gmttime)+(-5*60*60))); # 12/24/1234 13:23:23
$choice02=gmdate("m/d/Y h:i:s", (toTimestamp($gmttime)+(-5*60*60))); # 12/24/1234 01:23:23
$choice03=gmdate("m/d/Y h:i:s A", (toTimestamp($gmttime)+(-5*60*60))); # 12/24/1234 01:23:23 PM
$choice04=gmdate("m/d/Y h:i:s a", (toTimestamp($gmttime)+(-5*60*60))); # 12/24/1234 01:23:23 pm
$choice05=gmdate("D M d Y H:i:s", (toTimestamp($gmttime)+(-5*60*60))); # tues dec 24 1234 13:23:23
$choice06=gmdate("D M d Y h:i:s A", (toTimestamp($gmttime)+(-5*60*60))); # tues dec 24 1234 01:23:23 PM
$choice07=gmdate("D M d Y h:i:s a", (toTimestamp($gmttime)+(-5*60*60))); # tues dec 24 1234 01:23:23 pm
$choice08=gmdate("m-d-Y H:i:s", (toTimestamp($gmttime)+(-5*60*60))); # 12-24-1234 13:23:23
$choice09=gmdate("m-d-Y h:i:s", (toTimestamp($gmttime)+(-5*60*60))); # 12-24-1234 01:23:23
$choice10=gmdate("m-d-Y h:i:s A", (toTimestamp($gmttime)+(-5*60*60))); # 12-24-1234 01:23:23 PM
$choice11=gmdate("m-d-Y h:i:s a", (toTimestamp($gmttime)+(-5*60*60))); # 12-24-1234 01:23:23 pm
$choice12=gmdate("n/d/Y H:i:s", (toTimestamp($gmttime)+(-5*60*60))); # 2/24/1234 13:23:23
$choice13=gmdate("n/d/Y h:i:s", (toTimestamp($gmttime)+(-5*60*60))); # 2/24/1234 01:23:23
$choice14=gmdate("n/d/Y h:i:s A", (toTimestamp($gmttime)+(-5*60*60))); # 2/24/1234 01:23:23 PM
$choice15=gmdate("n/d/Y h:i:s a", (toTimestamp($gmttime)+(-5*60*60))); # 2/24/1234 01:23:23 pm
$choice16=gmdate("n-d-Y H:i:s", (toTimestamp($gmttime)+(-5*60*60))); # 2-24-1234 13:23:23
$choice17=gmdate("n-d-Y h:i:s", (toTimestamp($gmttime)+(-5*60*60))); # 2-24-1234 01:23:23
$choice18=gmdate("n-d-Y h:i:s A", (toTimestamp($gmttime)+(-5*60*60))); # 2-24-1234 01:23:23 PM
$choice19=gmdate("n-d-Y h:i:s a", (toTimestamp($gmttime)+(-5*60*60))); # 2-24-1234 01:23:23 pm
$choice20=gmdate("m/d/Y H:i", (toTimestamp($gmttime)+(-5*60*60))); # 12/24/1234 13:23
$choice21=gmdate("m/d/Y h:i", (toTimestamp($gmttime)+(-5*60*60))); # 12/24/1234 01:23
$choice22=gmdate("m/d/Y h:i A", (toTimestamp($gmttime)+(-5*60*60))); # 12/24/1234 01:23 PM
$choice23=gmdate("m/d/Y h:i a", (toTimestamp($gmttime)+(-5*60*60))); # 12/24/1234 01:23 pm
$choice24=gmdate("D M d Y H:i", (toTimestamp($gmttime)+(-5*60*60))); # tues dec 24 1234 13:23
$choice25=gmdate("D M d Y h:i A", (toTimestamp($gmttime)+(-5*60*60))); # tues dec 24 1234 01:23 PM
$choice26=gmdate("D M d Y h:i a", (toTimestamp($gmttime)+(-5*60*60))); # tues dec 24 1234 01:23 pm
$choice27=gmdate("m-d-Y H:i", (toTimestamp($gmttime)+(-5*60*60))); # 12-24-1234 13:23
$choice28=gmdate("m-d-Y h:i", (toTimestamp($gmttime)+(-5*60*60))); # 12-24-1234 01:23
$choice29=gmdate("m-d-Y h:i A", (toTimestamp($gmttime)+(-5*60*60))); # 2-24-1234 01:23 PM
$choice30=gmdate("m-d-Y h:i a", (toTimestamp($gmttime)+(-5*60*60))); # 2-24-1234 01:23 pm
$choice31=gmdate("n/d/Y H:i", (toTimestamp($gmttime)+(-5*60*60))); # 2/24/1234 13:23
$choice32=gmdate("n/d/Y h:i", (toTimestamp($gmttime)+(-5*60*60))); # 2/24/1234 01:23
$choice33=gmdate("n/d/Y h:i A", (toTimestamp($gmttime)+(-5*60*60))); # 2/24/1234 01:23 PM
$choice34=gmdate("n/d/Y h:i a", (toTimestamp($gmttime)+(-5*60*60))); # 2/24/1234 01:23 pm
$choice35=gmdate("n-d-Y H:i", (toTimestamp($gmttime)+(-5*60*60))); # 2-24-1234 13:23
$choice36=gmdate("n-d-Y h:i", (toTimestamp($gmttime)+(-5*60*60))); # 2-24-1234 01:23
$choice37=gmdate("n-d-Y h:i A", (toTimestamp($gmttime)+(-5*60*60))); # 2-24-1234 01:23 PM
$choice38=gmdate("n-d-Y h:i a", (toTimestamp($gmttime)+(-5*60*60))); # 2-24-1234 01:23 pm
$choice39=gmdate("m/d/y H:i:s", (toTimestamp($gmttime)+(-5*60*60))); # 12/24/1234 13:23:23
$choice40=gmdate("m/d/y h:i:s", (toTimestamp($gmttime)+(-5*60*60))); # 12/24/1234 01:23:23
$choice41=gmdate("m/d/y h:i:s A", (toTimestamp($gmttime)+(-5*60*60))); # 12/24/1234 01:23:23 PM
$choice42=gmdate("m/d/y h:i:s a", (toTimestamp($gmttime)+(-5*60*60))); # 12/24/1234 01:23:23 pm
$choice43=gmdate("D M d y H:i:s", (toTimestamp($gmttime)+(-5*60*60))); # tues dec 24 1234 13:23:23
$choice44=gmdate("D M d y h:i:s A", (toTimestamp($gmttime)+(-5*60*60))); # tues dec 24 1234 01:23:23 PM
$choice45=gmdate("D M d y h:i:s a", (toTimestamp($gmttime)+(-5*60*60))); # tues dec 24 1234 01:23:23 pm
$choice46=gmdate("m-d-y H:i:s", (toTimestamp($gmttime)+(-5*60*60))); # 12-24-1234 13:23:23
$choice47=gmdate("m-d-y h:i:s", (toTimestamp($gmttime)+(-5*60*60))); # 12-24-1234 01:23:23
$choice48=gmdate("m-d-y h:i:s A", (toTimestamp($gmttime)+(-5*60*60))); # 12-24-1234 01:23:23 PM
$choice49=gmdate("m-d-y h:i:s a", (toTimestamp($gmttime)+(-5*60*60))); # 12-24-1234 01:23:23 pm
$choice50=gmdate("n/d/y H:i:s", (toTimestamp($gmttime)+(-5*60*60))); # 2/24/1234 13:23:23
$choice51=gmdate("n/d/y h:i:s", (toTimestamp($gmttime)+(-5*60*60))); # 2/24/1234 01:23:23
$choice52=gmdate("n/d/y h:i:s A", (toTimestamp($gmttime)+(-5*60*60))); # 2/24/1234 01:23:23 PM
$choice53=gmdate("n/d/y h:i:s a", (toTimestamp($gmttime)+(-5*60*60))); # 2/24/1234 01:23:23 pm
$choice54=gmdate("n-d-y H:i:s", (toTimestamp($gmttime)+(-5*60*60))); # 2-24-1234 13:23:23
$choice55=gmdate("n-d-y h:i:s", (toTimestamp($gmttime)+(-5*60*60))); # 2-24-1234 01:23:23
$choice56=gmdate("n-d-y h:i:s A", (toTimestamp($gmttime)+(-5*60*60))); # 2-24-1234 01:23:23 PM
$choice57=gmdate("n-d-y h:i:s a", (toTimestamp($gmttime)+(-5*60*60))); # 2-24-1234 01:23:23 pm
$choice58=gmdate("m/d/y H:i", (toTimestamp($gmttime)+(-5*60*60))); # 12/24/1234 13:23
$choice59=gmdate("m/d/y h:i", (toTimestamp($gmttime)+(-5*60*60))); # 12/24/1234 01:23
$choice60=gmdate("m/d/y h:i A", (toTimestamp($gmttime)+(-5*60*60))); # 12/24/1234 01:23 PM
$choice61=gmdate("m/d/y h:i a", (toTimestamp($gmttime)+(-5*60*60))); # 12/24/1234 01:23 pm
$choice62=gmdate("D M d y H:i", (toTimestamp($gmttime)+(-5*60*60))); # tues dec 24 1234 13:23
$choice63=gmdate("D M d y h:i A", (toTimestamp($gmttime)+(-5*60*60))); # tues dec 24 1234 01:23 PM
$choice64=gmdate("D M d y h:i a", (toTimestamp($gmttime)+(-5*60*60))); # tues dec 24 1234 01:23 pm
$choice65=gmdate("m-d-y H:i", (toTimestamp($gmttime)+(-5*60*60))); # 12-24-1234 13:23
$choice66=gmdate("m-d-y h:i", (toTimestamp($gmttime)+(-5*60*60))); # 12-24-1234 01:23
$choice67=gmdate("m-d-y h:i A", (toTimestamp($gmttime)+(-5*60*60))); # 2-24-1234 01:23 PM
$choice68=gmdate("m-d-y h:i a", (toTimestamp($gmttime)+(-5*60*60))); # 2-24-1234 01:23 pm
$choice69=gmdate("n/d/y H:i", (toTimestamp($gmttime)+(-5*60*60))); # 2/24/1234 13:23
$choice70=gmdate("n/d/y h:i", (toTimestamp($gmttime)+(-5*60*60))); # 2/24/1234 01:23
$choice71=gmdate("n/d/y h:i A", (toTimestamp($gmttime)+(-5*60*60))); # 2/24/1234 01:23 PM
$choice72=gmdate("n/d/y h:i a", (toTimestamp($gmttime)+(-5*60*60))); # 2/24/1234 01:23 pm
$choice73=gmdate("n-d-y H:i", (toTimestamp($gmttime)+(-5*60*60))); # 2-24-1234 13:23
$choice74=gmdate("n-d-y h:i", (toTimestamp($gmttime)+(-5*60*60))); # 2-24-1234 01:23
$choice75=gmdate("n-d-y h:i A", (toTimestamp($gmttime)+(-5*60*60))); # 2-24-1234 01:23 PM
$choice76=gmdate("n-d-y h:i a", (toTimestamp($gmttime)+(-5*60*60))); # 2-24-1234 01:23 pm
#$choice=gmdate("m/d/Y H:i:s", (toTimestamp($gmttime)+(-5*60*60)));


echo <<<END
<html>
<head>
<title>simple time test page</title>
</head>
<body>
<p>my time is: $metime
<br />if this works right, this will be 4 or 5 hours ahead since it's<!--'--> suppossed to be UTC/GMT time: $gmttime
<br />gmt timestamp? $gmttimestamp
</p>
<p>breaking down gmt dateTime
<br /> year: $year
<br /> month: $month
<br /> day: $day
<br /> hour: $hour
<br /> min: $min
<br /> sec: $sec
</p>
<p>toTimeStamp function test (should be the same as above) and switching back to a datetime
<br />$ts
<br />cali's<!--'--> datetime (pst, not pdt): $fts
</p>
<p>choice tests for forums
<br />$choice01
<br />$choice02
<br />$choice03
<br />$choice04
<br />$choice05
<br />$choice06
<br />$choice07
<br />$choice08
<br />$choice09
<br />$choice10
<br />$choice11
<br />$choice12
<br />$choice13
<br />$choice14
<br />$choice15
<br />$choice16
<br />$choice17
<br />$choice18
<br />$choice19
<br />$choice20
<br />$choice21
<br />$choice22
<br />$choice23
<br />$choice24
<br />$choice25
<br />$choice26
<br />$choice27
<br />$choice28
<br />$choice29
<br />$choice30
<br />$choice31
<br />$choice32
<br />$choice33
<br />$choice34
<br />$choice35
<br />$choice36
<br />$choice37
<br />$choice38
<br />$choice39
<br />$choice40
<br />$choice41
<br />$choice42
<br />$choice43
<br />$choice44
<br />$choice45
<br />$choice46
<br />$choice47
<br />$choice48
<br />$choice49
<br />$choice50
<br />$choice51
<br />$choice52
<br />$choice53
<br />$choice54
<br />$choice55
<br />$choice56
<br />$choice57
<br />$choice58
<br />$choice59
<br />$choice60
<br />$choice61
<br />$choice62
<br />$choice63
<br />$choice64
<br />$choice65
<br />$choice66
<br />$choice67
<br />$choice68
<br />$choice69
<br />$choice70
<br />$choice71
<br />$choice72
<br />$choice73
<br />$choice74
<br />$choice75
<br />$choice76
<br />$choice
</p>
<p>hey mikusan, here's<!--'--> the php for you (well.. almost, i can't<!--'--> jsut use the showcode() commandhere because i don't<!--'--> wanna show a specific thing since it's<!--'--> irrelevant to the dispay other than gathering functions)
END;
echo '<br /><?php<br />
# this is a test to get utc/gmt times<br />
<br />
$metime=date("Y-m-d H:i:s", time());<br />
$gmttime=gmdate("Y-m-d H:i:s", time());<br />
$gmttimestamp=time();<br />
$year=substr($gmttime,0,4);<br />
$month=substr($gmttime,5,2);<br />
$day=substr($gmttime,8,2);<br />
$hour=substr($gmttime,11,2);<br />
$min=substr($gmttime,14,2);<br />
$sec=substr($gmttime,17,2);<br />
$ts=toTimestamp($gmttime);<br />
$fts=gmdate("Y-m-d H:i:s", (toTimestamp($gmttime)+(-8*60*60)));<br />
<br />
echo <<<END<br />
<html><br />
<head><br />
<title>simple time test page</title><br />
</head><br />
<body><br />
<p>my time is: $metime<br />
<br />if this works right, this will be 4 or 5 hours ahead since it''s suppossed to be UTC/GMT time: $gmttime<br />
<br />gmt timestamp? $gmttimestamp<br />
</p><br />
<p>breaking down gmt dateTime<br />
<br /> year: $year<br />
<br /> month: $month<br />
<br /> day: $day<br />
<br /> hour: $hour<br />
<br /> min: $min<br />
<br /> sec: $sec<br />
</p><br />
<p>toTimeStamp function test (should be the same as above) and switching back to a datetime<br />
<br />$ts<br />
<br />cali''s datetime (pst, not pdt): $fts<br />
</body><br />
</html><br />
END;<br />
?>';
echo '</body>
</html>';
?>
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

m3rajk wrote:i still need to check two things: what's the access level of the forum and what's the access level of the user. I grab the level of the user, but i can't simply then call the forums based on it.
Doesn't your $fal var hold a value for the forum access level for that row? That's all you need to call variable function which will perform the correct user access check for that row.

In any case I think you can in fact do all that in one fell swoop with query logic although you may need to restructure your database. The entire script, really, is redundant - slimmed down or not.
Last edited by McGruff on Tue Sep 16, 2003 5:46 pm, edited 1 time in total.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

i'm not advancded enough to do that right now, and i have that part working, so i think i'd prefer to work out what bugs i do have before i go for making a better use of the db calls. i'm the firs to admit i'm nto the most experienced with databases. right now getting the display right is more important to me than getting the calls to the db perfected.

like i said, as a result of the fact i have some levels that are independant and people can be one or both, makes it so that i can't see any way asid eform several calls to the ds, or having php check after i get it


can you help me witht he timestamp issue and why it's rerturning -1 now and screweing everything up? (i have to fix post.php after i get this set working because one fo the forums shouldn't be 0000-00-00 00:00:00 because i've posted, but since it's working enough to debug forums.php i'd like to debug that first)
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

The bug doesn't matter: your coding style is holding you back, IMHO.

An excellent tutorial on db design is here: http://www.oreilly.de/catalog/javadtabp ... r/ch02.pdf
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

McGruff wrote:The bug doesn't matter: your coding style is holding you back, IMHO.

An excellent tutorial on db design is here: http://www.oreilly.de/catalog/javadtabp ... r/ch02.pdf
i fail to see how database design is causing gmmktime to return -1 when it should return the timestamp for jan 1 1970.

please explain that to me


also: hypothetical. you have 10 access levels. levels 0,1,2 are heirarchal, but 3,4,5,6 are on the same level, yet restrict to different groups. users may be members of multiple groups. leverl 7,8,9 are heirachal and you must have 0,1,2 and at least one of the set 3 through 6 to have it


how do you do that via db calls witout multiple calls?

i can't see anyway, and since that's the type of situation i have, i felt that the the best thing is to do ONE db call, get everything transfered and then check access in php since the major time consumption is the transfer between the db and php
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

m3rajk wrote:i fail to see how database design is causing gmmktime to return -1 when it should return the timestamp for jan 1 1970.
It doesn't but we have also discussed an access check by query logic: that requires a properly designed relational database...
m3rajk wrote: also: hypothetical. you have 10 access levels. levels 0,1,2 are heirarchal, but 3,4,5,6 are on the same level, yet restrict to different groups. users may be members of multiple groups. leverl 7,8,9 are heirachal and you must have 0,1,2 and at least one of the set 3 through 6 to have it

how do you do that via db calls witout multiple calls?
...which laughs in the face of groups, hierarchies and so on provided you don't object to humungous JOIN queries.

I suspect that your integer access levels create functional dependencies which break the 2nd normal form.

Where are your definitions of privilege sets (ie the individual privileges assigned to each level)? Implicit in your code and hence scattered throughout the scripts? That could make it awkward to edit privilege sets.

Of course, you don't HAVE to create a database using normal forms but you probably should at least start off with that and de-normalise it purposefully, as mentioned in the article.

Making db design decisions based on the simplest queries can cripple the data structure.
Post Reply