Jump to content

newb

Members
  • Posts

    454
  • Joined

  • Last visited

Posts posted by newb

  1. fixed:

     

    heres code if anyone runs into a similar problem:

    function returnstats ($url,$name) {
    global $stats;
    echo '<tr>';
    echo '<td width="" valign="top"><p>'.$name.'</p></td>';
    $sum = 0;
    for($i = 1; $i <=4; $i++) {
    if (preg_match('|<td class="'.$i.' page" style="background-color:#ccc"><a href="'.$url.'">(.*)</a></td>
            <td class="'.$i.' sum">(.*)</td>|Ui',$stats,$result)) {
    		switch ($i) {
    		case 1:
    		$sum1 = $result[2];
    		break;
    		case 2:
    		$sum2 = $result[2];
    		break;
    		case 3:
    		$sum3 = $result[2];
    		break;
    		default:
    		$sum = $result[2];
    		}
    
    		$sum = $result[2];
    }
    
    if ($i == 4) {
    $sum = $sum1+$sum2+$sum3;
    }
    
    echo '<td width="" valign="top"><p>'.$sum.'</p></td>';
    
    
    }
    echo '</tr>';
    }

  2. well i updated my code a bit and removed the variable variables and made a function instead.

     

    function returnstats ($url,$name) {
    global $stats;
    echo '<tr>';
    echo '<td width="" valign="top"><p>'.$name.'</p></td>';
    for($i = 0; $i <=4 ; $i++) {
    if (preg_match('|<td class="'.$i.' page" style="background-color:#ccc"><a href="'.$url.'">(.*)</a></td>
            <td class="'.$i.' sum">(.*)</td>|Ui',$stats,$result)) {
    	echo '<td width="" valign="top"><p>'.$result[2].'</p></td>';
    	}
    
    	if ($i == 4) {			
    	}
    }
    echo '</tr>';
    }

     

    so is it possible to get the total sum of previous data pulled from the preg_match result within the for loop or what?

  3. when $i = 4, im trying to get the sum of the values and store it in a variable but idk how. im using variable variables..

     

    for($i = 0; $i < 5; $i++) {
    $varname = 'testimonyletters_'.$i.'';
    if (preg_match('|<td class="'.$i.' page" style="background-color:#ccc"><a href="'.$url.'">(.*)</a></td>
            <td class="'.$i.' sum">(.*)</td>|Ui',$stats,$result)) {
    $$varname = $result[2];
    
    }
    
    if ($i == 4) {
    $$varname = ($varname_1+$varname_2+$varname_3);
    }
    }
    

     

    i would like the $testimonyletters_4 variable to be the sum of the previous variables 1-3. when $i == 4, my current code is not working. any idea how to fix this?

  4. whats a more efficient way of achieviing the same results with less code:

     

    			switch ($info) {
    			case name:
    				return $row['username'];
    			break; 
    			case group:
    				return $row['usergroupid'];
    			break; 
    			case email:
    				return $row['email'];
    			break; 
    			case posts:
    				return $row['posts'];
    			break; 
    			case usertitle:
    				return $row['title'];
    			break; 
    			case securitytoken:
    				return $row['securitytoken'];
    			break; 
    			case lastvisitdate:
    				return $row['lastvisitdate'];
    			break; 
    			case joindate:
    				return $row['joindate'];
    			break; 
    			case pmtotal:
    				return $row['pmtotal'];
    			break; 
    			case pmunread:
    				return $row['pmunread'];
    			break; 

     

    nothing is wrong with this btw just looking for a better way of getting columns from the database w/o having to go back and add a case each time i want to.

  5. here is the fix...

    $cmd = "/bin/ping -c 5 ".$_SERVER['REMOTE_ADDR'];
    $ping = shell_exec($cmd); 
    
    if(strlen($ping) < 5)
    { 
    echo "? ms";
    }
    else
    {
    preg_match("/rtt min\/avg\/max\/mdev = (.*)\/(.*)\/(.*)\/(.*) ms/", $ping, $matches);
    $urping = number_format($matches[1],0)." ms";
    }

  6. find a way to add a zero to the single digit integers before sorting them. problem solved

     

    heres a simple function that i use to do it:

    function add_nulls($int, $cnt=2) {
        $int = intval($int);
        for($i=0; $i<($cnt-strlen($int)); $i++)
            $nulls .= '0';
        return $nulls.$int;
    }

  7. How can i add dates from the previous / next month to the calendar for this calendar script? id like it to appear so its like:

     

    28 29 30 31 1 2 3 4 5 6 etc.. then at the end 29 30 31 1 2 3 etc...

     

    function av_calendar () {
    $monthNames = Array("January", "February", "March", "April", "May", "June", "July", 
    "August", "September", "October", "November", "December");
    if (!isset($_REQUEST["sm"])) $_REQUEST["sm"] = date("n");
    if (!isset($_REQUEST["sy"])) $_REQUEST["sy"] = date("Y");
    $cMonth = $_REQUEST["sm"];
    $cYear = $_REQUEST["sy"];
    
    $prev_year = $cYear;
    $next_year = $cYear;
    $prev_month = $cMonth-1;
    $next_month = $cMonth+1;
    
    if ($prev_month == 0 ) {
    	$prev_month = 12;
    	$prev_year = $cYear - 1;
    }
    if ($next_month == 13 ) {
    	$next_month = 1;
    	$next_year = $cYear + 1;
    }
    //
    $today = date('d');
    echo '
    	<div class="head">
    	<h1>'.$monthNames[$cMonth-1].' '.$cYear.'</h1>
    	</div>
    	<div class="blockitem2">
    <table width="100%" class="calendar" style="margin-left:-10px;" border="0" cellpadding="2" cellspacing="2">
    <tr style="font-size:20px">
    <th align="center"><strong>S</strong></th>
    <th align="center"><strong>M</strong></th>
    <th align="center"><strong>T</strong></th>
    <th align="center"><strong>W</strong></th>
    <th align="center"><strong>T</strong></th>
    <th align="center"><strong>F</strong></th>
    <th align="center"><strong>S</strong></th>
    </tr> ';
    $timestamp = mktime(0,0,0,$cMonth,1,$cYear);
    $maxday = date("t",$timestamp);
    $thismonth = getdate ($timestamp);
    $startday = $thismonth['wday'];
    	$sy = date("Y",$timestamp);
    	$sm = date("m",$timestamp);
    	$sd = date("d",$timestamp);
    
    
    for ($i=0; $i<($maxday+$startday); $i++) {
    $day = ($i - $startday + 1);
    
    
    	if(($i % 7) == 0 ) { echo "<tr>\n"; }
    	if($i < $startday) { echo "<td></td>\n";
    	} else {
    	$now = "$sy-$sm-$day 00:00:00";
    	$then = "$sy-$sm-$day 23:59:59";
    	$sql = "SELECT av_episodes.id,av_episodes.date FROM av_episodes WHERE date between UNIX_TIMESTAMP('$now') AND UNIX_TIMESTAMP('$then')";
    	$query = exec_mysql_query($sql)  or die(mysql_error());
    	$rows = mysql_num_rows($query);
    	$nowurl = "$sy/$sm/$day/";
    
    		if(!empty($rows)) {
    		echo "<td class='dates' align='center' valign='middle' height='20px'><b><a href='".SITE_URL."updates/".$nowurl."'>". add_nulls($day) . "</a></b>";
    		} else { 
    		echo "<td class='datesInactive' align='center' valign='middle' height='20px'>". add_nulls($day) . "";
    		}
    		echo "</td>\n";
    
    
    
    
    
    	if(($i % 7) == 6 ) {echo "</tr>\n";	}
    
    
    
    }
    }
    echo '</table></div>
    ';

×
×
  • 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.