Location: PHPKode > projects > Ars Lab > arsLab-1.4.1/functions.php
<?
// Function File

// produce <option> tags for categories
function catOpts($mark = 0)
{
  global $ars;
  $db = mysql_pconnect($ars[host],$ars[user],$ars[pass]);
  mysql_select_db($ars[dbname]);
  if( $res = mysql_query("select cid,cname from category order by cname") )
    while( $r = mysql_fetch_array($res) )
	  if( $mark == $r[cid] )
	    echo "      <option value=\"$r[cid]\" selected>$r[cname]</option>\n";
	  else
		echo "      <option value=\"$r[cid]\">$r[cname]</option>\n";
}

// returns arrays with category names
function getCats()
{
  global $ars;
  $db = mysql_pconnect($ars[host],$ars[user],$ars[pass]);
  mysql_select_db($ars[dbname]);
  if( $res = mysql_query("select cid,cname from category") )
  {
    while( $r = mysql_fetch_array($res) )
	  $C[$r[cid]] = $r[cname];
	return $C;
  }
  else
    return 0;
}

// years();
// creates <option> tags for years,  $start (number) will designate which year to start from
// $range will tell you how many (number), $select will select a certain year (number)
function years($start,$range, $select)
{
  for( $i = $start; $i < ($start + $range + 1); $i++ )
  {
	if( $i == $select )
	  echo "    <option value=\"$i\" selected>$i\n";
	else
	  echo "    <option value=\"$i\">$i\n";
  }
}

// months();
// creats <option> tags for months, $select (number, Jan=0, Dec=11) will have a certain month selected
function months($select)
{
  for( $i = 1; $i < 13; $i++ )
  {
	if( $i == $select )
	  echo "    <option value=\"$i\" selected>". date("F",$i*2500000-1000000) ."\n";
	else
	  echo "    <option value=\"$i\">". date("F",$i*2500000-1000000) ."\n";
  }
}
// days();
// creats <option> tags for month days 1-31st, $select (num) will select
function days($select)
{
  for( $i = 1; $i < 32; $i++ )
  {
	if( $i == $select )
	  echo "    <option value=\"$i\" selected>". date("jS",$i*86400-40000) ."\n";
	else
	  echo "    <option value=\"$i\">". date("jS",$i*86400-40000) ."\n";
  }
}

// hours(); see months()/days()
function hours($select)
{
  for( $i = 1; $i < 25; $i++ )
  {
	if( $i == $select )
	  echo "    <option value=\"$i\" selected>". sprintf("%02d",$i) ."\n";
	else
	  echo "    <option value=\"$i\">". sprintf("%02d",$i) ."\n";
  }
}

// mins(); see months()/days()
function mins($select)
{
  for( $i = 0; $i < 60; $i++ )
  {
	if( $i == $select )
	  echo "    <option value=\"$i\" selected>". sprintf("%02d",$i) ."\n";
	else
	  echo "    <option value=\"$i\">". sprintf("%02d",$i) ."\n";
  }
}
?>
Return current item: Ars Lab