Jump to content

TrueColors

Members
  • Posts

    45
  • Joined

  • Last visited

Posts posted by TrueColors

  1.  

    Try something like this.

     

     

    The value in the dropdown is the ID of the user.

    
    <script type="text/javascript">
        function showid ( val )
        {
              document.forms[0].elements['id'].value = val;
        }
    </script>
    <form>
        <select onchange="showid(this.value)">
            <option value="-1" selected disabled>Select One</option>
            <option value="1">Username 1</option>
            <option value="2">Username 2</option>
        </select>
        <input type="text" name="id" />
    </form>
    
    
    

  2. mysql_query returns a resource on success and false on failure. As the parameter passed is not a resource states that your query is indeed failing due to an error of some kind.

     

    Please use the following format:

    $result = mysql_query ( "SELECT Name FROM empdata ORDER BY Name ASC" ) or trigger_error ( mysql_error ( ) );

    What this does, if an error were to occur it'll throw an error. The key function here is mysql_error.

     

     

  3. I have a little class you may use.

     

    The class uses a db handler aswell... which is what $db is. It features functions like "execute" and a few others. You may look in the class to see what is used. You can replace them with mysql_* or whatever you desire if you do not have a $db handler. It'll require some changes but it would be fine.

     

    the 20 inside the instancing of the class, is the amount of rows per page to be displayed. The "page" is the ID, so ... url would be www.site.com/index.php?page=1 (note the "page" in the url)

     

    The query below also uses the FULL query. The class handles it and uses some changes to create the count() function in mysql.

     

    The rest is self explanatory. Here is this little bit:

    $page = new Pagination ( $db, 20, "page" );
    $page -> buildQueryString ();
    
    $page -> setQuery ( "SELECT column FROM table" );
    
    $page -> setNumberRows ();
    $page -> setPages ();
    $page -> setCurrentRow ();
    
    foreach ( $page -> getResults () as $result )
    {
        // your content here... $result is an array of the columns from your database.
    }
    

     

    Here is the class...

    <?php
    /**
    * Name: Pagination Object
    * Author: Andrew Judd
    * Date: May 14, 2011
    */
    class Pagination
    {
        /**
         * An instance of the database object
         */
        private $db = NULL;
    
        /**
         * The query which will be run.
         */
        private $query = NULL;
    
        /**
         * The total number of rows that the full query will return.
         */
        private $numRows = NULL;
    
        /**
         * The number of rows to return per page.
         */
        private $perPage = NULL;
        
        /**
         * The number of the current page.
         */
        private $curPage = NULL;
        
        /**
         * The number of the first page.
         */
        private $firstPage = 1;
        
        /**
         * The number of the last page.
         */
        private $lastPage = NULL;
        
        /**
         * The number of the current row.
         */
        private $curRow = NULL;
        
        /**
         * The $_GET page identifier
         */
        private $pageID = NULL;
        
        /**
         * The url QUERY string
         */
        private $queryString = NULL;
    
        /**
         * The three-argument constructor which takes in the connection to the database.
         * @param mixed $db - The database object
         * @param int $perPage - The number of rows per page
         * @param string $pageIdentifier - The page identifier
         */
        public function __construct ( $db, $perPage = 20, $pageIdentifier = 'page' )
        {
            $this -> db = $db;
            $this -> perPage = $perPage;
            $this -> pageID = $pageIdentifier;
        }
        
        /**
         * This function will build the URL Query String and remove any current page ID's
         */
        public function buildQueryString ()
        {
            if ( isset ( $_SERVER [ 'QUERY_STRING' ] ) && !empty ( $_SERVER [ 'QUERY_STRING' ] ) )
            {
                $ex = explode ( "&", $_SERVER [ 'QUERY_STRING' ] );
                
                foreach($ex as $k => $query)
                {
                    if ( preg_match ( "/" . $this -> pageID . "(.*)\b/", $query ) )
                        unset ( $ex [ $k ] );
                }
                
                if ( count ( $ex ) > 0 )
                {
                    $this -> queryString = implode ( "&", $ex ) . '&';
                }
            }    
        }
    
        /**
         * The setter for the query.
         * @param string $query - The query which will be run
         */
        public function setQuery ( $query )
        {
            $this -> query = $query;
        }
        
        /**
         * This function will set the current and last page.
         */
        public function setPages ()
        {
            $this -> lastPage = ceil ( $this -> numRows / $this -> perPage );
            
            if ( !isset ( $_GET [ $this -> pageID ] ) || $_GET [ $this -> pageID ] < $this -> firstPage)
            {
                $this -> curPage = $this -> firstPage;
            }
            else if ( $_GET [ $this -> pageID ] > $this -> lastPage)
            {
                $this -> curPage = $this -> lastPage;
            }
            else
            {
                $this -> curPage = $_GET [ $this -> pageID ];
            }
        }
        
        /**
         * This function will set the current row based upon
         * the current page and rows per page
         */
        public function setCurrentRow ()
        {
            $this -> curRow = ( $this -> curPage - 1 ) * $this -> perPage;
        }
    
        /**
         * This function is used in order to set the number of rows
         * that will be returned from the full query.
         */
        public function setNumberRows ()
        {
            /* Make sure that the query is set */
            if ( $this -> query == NULL )
            {
                /* Query wasn't set, so the number of rows is -1 */
                $this -> numRows = -1;
            }
            else
            {
                /* Build the query to retrieve how many rows are present */
                $sql = preg_replace ( '/SELECT (.*) FROM\b/'
                            , 'SELECT COUNT(*) AS NumRows FROM'
                            , $this -> query );
                $query = $this -> db -> execute ( $sql );
                
                $r = $this -> db -> fetchassoc ( $query );
                
                /* Return the number of rows that are present */
                $this -> numRows = $r [ 'NumRows' ];
            }
        }
        
        /**
         * This function is used in order to retrieve an array of results
         * that will be returned from the full query
         */
        public function getResults ()
        {
            /* Build and execute the query to retrieve the amount of rows set */
            $sql = $this -> query . ' LIMIT ' . $this -> curRow . ', ' . $this -> perPage;
            $query = $this -> db -> execute ( $sql );
            
            $results = array ();
            
            while ( $row = $this -> db -> fetchassoc ( $query ) )
            {
                $results[] = $row;
            }
            
            return ( $results );
        }
        
        /**
         * This function is used to retrieve a list of Pages which would
         * be used for the page navigation
         */
        public function getPageNavigation ()
        {
            $links = '';
            
            if ( ( $this -> curPage - 5 ) > $this -> firstPage )
                $links .= '<a href="?' . $this -> queryString . $this -> pageID . '=' . $this -> firstPage . '">First</a> ... ';    
                
            for ( $i = ($this -> curPage - 5 ); $i <= ( $this -> curPage + 5); $i++ )
            {
                if ( $i >= $this -> firstPage && $i <= $this -> lastPage )
                {
                    $links .= '<a href="?' . $this -> queryString . $this -> pageID . '=' . $i . '">' . ( ( $i == $this -> curPage ) ? "[$i]" : $i ) . '</a> ';
                }
            }
            
            if ( ( $this -> curPage + 5 ) < $this -> lastPage )
                $links .= ' ... <a href="?' . $this -> queryString . $this -> pageID . '=' . $this -> lastPage . '">Last</a>';
                
            return($links);
        }
    }
    ?>

     

    If you don't want to use it, it's fine, don't worry about it. If you have a database handler already... just pass it through when you instance the class... and there is no need to alter the class at all.

     

    Just thought I'd share my little ... pagination :)

     

  4. Yeah it came back up but two kids were acting innapropiately. One of them was MAU5 which also had nicks of FC, Magician, DashB, etc etc. He's a troll. So CrayonViolent closed it back down.

     

    I believe CrayonViolent is trying to get in contact with Daniel, there are no notes left by him so getting the backup and everything is difficult.

     

  5. I put the scrollbar on the div. I used JavaScript to loop through the LI's and add the widths, including padding's and any margins. Then that total width is the width of the UL.

     

    The JavaScript is:

    		<script type="text/javascript">
    		function updateULWidth()
    		{
    			var item_width = 0;
    
    			$("ul#attachmentList li").each(function() {
    				var wide = $(this).width();
    
    				$(this).css({'width' : wide + "px"});
    
    				item_width += parseInt($(this).css('padding-left')) + parseInt($(this).css('padding-right')) + parseInt($(this).css('margin-left')) + parseInt($(this).width());
    			});
    
    			$("ul#attachmentList").css({'width' : item_width + "px"});
    		}
    	</script>

  6. Below is my css

    ul#attachmentList {
        background:#fff;
        height:40px;
        padding: 0;
        list-style: none;
        width: 705px;
        border:1px solid #ABADB3;
        overflow-x: scroll;
    }
    ul#attachmentList:hover {
        border-top:1px solid #3B7BAD;
        border-left:1px solid #A4C9E3;
        border-right:1px solid #A4C9E3;
        border-bottom:1px solid #A4C9E3;
    }
    ul#attachmentList li {
        margin: 2px 0 2px 2px;
        float: left;
        background: AliceBlue;
        padding: 0 10px;
        text-align: center;
        height: 20px;
        line-height: 20px;
        
        -moz-border-radius: 5px;
        border-radius:5px;
        -webkit-border-radius:5px;
    }

    Now when I keep adding LI's it doesn't make use of the horizontal scrollbar (although the bar is visible). The li's just go beneath each other. I want it to make use to the scrollbar.

     

    What am I doing wrong?

     

  7. return ((md5($captcha) == $_SESSION['ckey']) ? true : false);

    That method works.

     

    Again I ask, along with my previous issue: Why did it not work the way I had coded it?

     

    My next issue, which is slightly different. Is for DOB. I call it the same way and this is the function

    	public function isValidDOB($day, $month, $year)
    {
    	if(($day > 31 || $day < 01) || ($month > 12 || $month < 1) || ($year >= date('Y', time()) || $year <= 1910))
    	{
    		return false;	
    	}
    }

  8. or die() statement should continue after mysql_query.

     

    Incorrect, it worked the way he had it because although it's on a different line, it still worked. (Fact as he got an SQL error showing) The problem was probably because he was missing quotes around the variable being inserted into the query.

  9. To do the same as the above. Remove the onclicks, and use this JS instead.

     

        <script src="http://code.jquery.com/jquery-latest.js"></script>
        <script type="text/javascript">
            $(function() {
                $('tr').click(function() {
                       $('.highlighted').removeClass("highlighted");
                    $(this).addClass("highlighted");
                });
            });
        </script>

    To do it with TD's instead of TR's just change 'tr' to 'td'

     

  10. Sorry about the wait. I got a solution.

     

    Example CSS:

        <style>
    	.highlighted { background:black; color: white; }
    	tr { cursor: pointer; }
    </style>

     

    Example JS:

    	<script src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript">
    	function myfunction (myTD)
    	{
       			$(".highlighted").removeClass("highlighted");
        		$(myTD).addClass("highlighted");
    	}
    </script>

     

    Example HTML:

    	<table style="border:2px solid blue;" cellspacing="0">
        	<tr onclick="myfunction(this)">
            	<td>TD Box 1</td>
                <td>TD Box 2</td>
            </tr>
        	<tr onclick="myfunction(this)">
            	<td>TD Box 1</td>
                <td>TD Box 2</td>
            </tr>
        </table>

     

    This is set so that when you click a row (TR) it'll add the class .highlighted which means the background will be black, text will be white. When clicking the other row (TR) - (Two in this example) it'll remove the class from the previous row (TR) and add it on the one you just clicked.

     

    If you want it for TD, just remove the onclick from the TR's and place them in the TD's.

     

    There is an easier method that doesn't require onclicks if you'd prefer that but I'd need some time alone to code it first :P

     

    Hope this is what you're looking for.

  11. Thanks thorpe that worked! Can you explain why my original method didn't work?

     

    - My next problem is the captcha.

    md5($captcha) is 706a335b65ce9ccabd6c683b2dec13d2

    $_SESSION['ckey'] is 706a335b65ce9ccabd6c683b2dec13d2

    (I echo'd them both out and they are exact)

     

    I call the function by doing this if(user::isValidCaptcha($this->captcha) == FALSE) $errors[] = "Your captcha image was incorrect!";

    The function is

    public function isValidCaptcha($captcha)
    {
    	die(md5($captcha) . '<br />' . $_SESSION['ckey']); // This was to test and both results were the same
    
    	if(md5($captcha) != $_SESSION['ckey']) return false;
    }
    

     

    Even though both are the same, why does it display the error that it's incorrect?

  12. mysql_connect("localhost", "", "") or die(mysql_error());
    mysql_select_db("") or die(mysql_error());
    
    if($_GET['nid'] == $nid)
    {
    $result = mysql_query("SELECT * FROM news where nid='$nid'") or die(mysql_error());
    
    while($row = mysql_fetch_array( $result )) {
    	echo "<strong>".$row['ntitle']."</strong>";
    	echo "<br><em>";
    	echo $row['ndate'];
    	echo " by ";
    	echo $row['npost'];
    	echo "</em><br>";
    	echo $row['nnews'];
    	echo "<br><br>";
    	echo $row['nmore'];
    }
    }
    else
    {
    $result = mysql_query("SELECT * FROM news") or die(mysql_error());
    
    while($row = mysql_fetch_array( $result ))
    {
    	echo "<strong>".$row['ntitle']."</strong>";
    	echo "<br><em>";
    	echo $row['ndate'];
    	echo " by ";
    	echo $row['npost'];
    	echo "</em><br>";
    	echo $row['nnews'];
    	echo "<br><br>";
    	echo $row['nmore'];
    	echo "<br><br>";
    }
    }

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