Jump to content

djfox

Members
  • Posts

    327
  • Joined

  • Last visited

    Never

Posts posted by djfox

  1. What I want to do is have the code add up all the entries in the database and find the average from a field.

     

    Ie, the field name "views" in the table "submissions" and the entries in that field in that table are 234, 365, 264, 646, 354. Add up all of those and get the average number, which in this case is 373 (with the number rounded up to a whole number). I can do the rounding of the number up but I`m not sure how to tell the code to add up all of those numbers from a certain field in the database table.

  2. I would like a pop-up box to appear before the page is loaded and have two buttons on it. If the user clicks "yes", the page will load like normal. If they click "no", they should be redirected to the page they were on previously. How would I accomplish this? Or even if someone knows what this kind of code is called and could tell me, I could probably do some searching for it.

  3. Here`s my code:

     

    <?php
    $res = mysql_query("SELECT bought FROM userdata WHERE id='$logged'");
    $a = mysql_fetch_row($res);
    $it = explode(",", $a[0]);	
    
    foreach ($it as $th) {
    $res2 = mysql_query("SELECT id, shortname, type, name, cost FROM clothing WHERE id='$th'");
    $b = mysql_fetch_row($res2);
    mysql_free_result($res2);
    
    echo "$b[3] <br>";
    }
    ?>

     

    I want the end results to be listed in the order of the id numbers (listed in both as $b[0] and $th). How do I tell my code to list the results in numerical order?

  4. I know how to do greater than, less than, and equal to with if ()

    But what about something like "if $wt[2] can be found in the string of values entered in $pa[2]"?

     

    Example:

    Let`s say $pa[2] is "Normal"

    And let`s say $wt[2] is "Normal,Ice,Rock,Steel"

     

    How could I get if () to look for $pa[2] in $wt[2] ?

  5. For whatever reason, it seems as though my code can`t count. I`ve set the offset to be at 50, and it is displaying every single item from the table rather than just the 50. I`ve copied and pasted the code form another file which uses the same system and works successfully, but it still seems to have trouble counting on this file I`m trying to get this to work for.

     

    <a href="mlpcollection_main.php?g=<? echo "$g"; ?>&sort=newest">Newest</a> | <a href="mlpcollection_main.php?g=<? echo "$g"; ?>&sort=alpha">Alphabetical</a>
    <p>
    <?php 
      if (isset($_GET['sort']) && $_GET['sort'] == "newest") {
      if(!$offset) $offset=0;
      $recent = 0;
      $res = mysql_query("SELECT id, image, date, date2, name, descr, type, gen, cond, owner FROM ponycol WHERE owner='$g' ORDER BY id DESC")or die( mysql_error() );
      while( $row = mysql_fetch_row($res) ){
    if( $recent >= $offset && $recent < ($offset + 50 )){
        echo "<a href='mlpcollection.php?id=$row[0]'>$row[4]</a><br>";
    }
          }
    $recent = $recent + 1;
    }
    ?>
    <p>
    <table border=0 width=100%>
    <tr>
    <td><?php
    if ($offset >= 50) {
    ?><b><a href="mlpcollection_main.php?g=<? echo $g ?>&sort=<? echo "$sort"; ?>&offset=<? echo $offset - 50 ?>"><img src="<? echo $butprev ?>" border=0></a></b>
    <?php
    }
    ?>
    <td><div align=right>
    <b><a href="mlpcollection_main.php?g=<? echo $g ?>&sort=<? echo "$sort"; ?>&offset=<? echo $offset + 50 ?>"><img src="<? echo $butnext ?>" border=0></a></b>
    </div>
    </table>

     

    The Next/Previous counts show up properly, they add/subtract the correct number from the correct field.

     

    Break-down:

    Instead of showing just 50 items, it shows every single item in the table.

  6. They are logged out randomly.

     

    Stupid me forgot to post the code:

     

    <?php
    	// Defines
    
    	DEFINE('SESSION_MAGIC','sadhjasklsad2342');
    
    	// Initialization
    	@session_start();
    	@ob_start();
      
    
        /*
          Redirects to another page
        */
        function Redirect($to) {
    
       @session_write_close();
       @ob_end_clean();
       @header("Location: $to");
        } 
    
         /*
            Deletes existing session
        */
    function RemoveSession() {
    	$_SESSION = array();
    	if (isset($_COOKIE[session_name()])) {
    	   @setcookie(session_name(), '', time()+(60*60*24*365), '/');
    	}
    }
        
    /*
      Checks if user is logged in
    */ 
    function isLoggedIn() {
    
    	return(isset($_SESSION['magic']) && ($_SESSION['magic']==SESSION_MAGIC));
    }
    
    
    
        /* 
          read message count
        */
        function CountMessages($id) {
        
       if ($res=mysql_query("SELECT * FROM messagedata WHERE recBoxID=$id AND isNew=1"))
       {
    	   $count=mysql_num_rows($res);
    	   mysql_free_result($res);	   
    	   return($count);
       }
       return 0; 
        }
        
        /*
          Go login go!
        */
        function Login($username,$password) {
       
        global $nmsg, $rows;
       
       $ok=false;	
       if ($res=mysql_query("SELECT id,level,mailNum, echo_count, status, isHold, guildLim, adult, battle, showtime FROM userdata WHERE login='$username' AND password='$password'"))
       {
    	   if ($rows=mysql_fetch_row($res)) {
    		    $_SESSION['sess_name'] = $username;
    			$_SESSION['pass'] = $password;
    			$_SESSION['gal'] = $rows[0];
    			$_SESSION['mail'] = $rows[2];
    			$_SESSION['level2'] = $rows[1];	
    			$_SESSION['echos'] = $rows[3];
    			$_SESSION['status'] = $rows[4];
    			$_SESSION['suspend'] = $rows[5];
    			$_SESSION['guildnum'] = $rows[6];
    			$_SESSION['adult'] = $rows[7];
    			$_SESSION['bat2'] = $rows[8];
    			$_SESSION['tim'] = $rows[9];
    		    $_SESSION['magic'] = SESSION_MAGIC;
    		    $nmsg = CountMessages($rows[0]);
    		    $ok=true;
    	   } else {
    		   include('login_failed.php');
    	   }
    	   mysql_free_result($res);
       }
       return($ok);
       }
       
           /*
          Terminates an existing session
        */
        function Logout() {
        @RemoveSession();
        @session_destroy();
        }
    
        /*
          Escape array using mysql
        */   
    function Escape(&$arr)
    {
     if (Count($arr)>0) {
    	    foreach($arr as $k => $v) {
    	        if (is_array($v)) {
    	            Escape($arr[$k]);
    	        }
    	        else {
    	            if (function_exists('get_magic_quotes')) {
    	                if(!get_magic_quotes_gpc()) {
    	                    $arr[$k] = stripslashes($v);
    	                }
    	            }
    	            $arr[$k] = mysql_real_escape_string($v);
    	        }
    	   }
          }
    }
    
    // -----------------------------------------------    
    // Main
    // -----------------------------------------------    
    
       Escape($_POST);
       Escape($_GET);
       Escape($_COOKIE);
       Escape($_REQUEST);
       Escape($_GLOBALS);
       Escape($_SERVER);
       
    ?>

     

    Note: For those who don`t already know, this was made by the first programmer who worked on my site years back. I have lost contact with the person long ago.

  7. I have set for my login to last a long time but it seems like my coding doesn`t matter to the system. The time the site allows for the person to be logged in before unlogging them varies greatly. Examples of the most extremes: Sometimes, no matter how active I am, it`ll kick me off after 15 minutes. Other times, after shutting down my computer and then start it back up the next day, I`m still logged in.

     

    What would cause it to be so unstable like that?

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