Jump to content

Wolphie

Members
  • Posts

    682
  • Joined

  • Last visited

    Never

Posts posted by Wolphie

  1. Ah, I've just realised. You've done the includes the wrong way around. 
    
    Change DbConnector.php to
    [code=php:0]
    <?php
    class Dbvars {
    
        var $settings;
        
        function getSettings() {
    
            // Database variables
            $settings['dbhost'] = 'localhost';
            $settings['dbusername'] = '****';
            $settings['dbpassword'] = '****';
            $settings['dbname'] = '****';
    
            return $settings;
        }
    }
    
    
    class DbConnector extends Dbvars {
    
        var $theQuery;
        var $link;
    var $dbname;
    var $host;
    var $user;
    var $pass;
    
        //*** Function: DbConnector, Purpose: Connect to the database ***
        function DbConnector(){
            // Load settings from parent class
            $settings = Dbvars::getSettings();
            // Get the main settings from the array we just loaded
            $this->host = $settings['dbhost'];
            $this->dbname = $settings['dbname'];
            $this->user = $settings['dbusername'];
            $this->pass = $settings['dbpassword'];
        }
    
    function setDatabase($ndbname)
    {
    	$this->dbname = $ndbname;
    }
    
    function connect()
    {
            // Connect to the database
            $this->link = mysql_connect($this->host, $this->user, $this->pass)or die(mysql_error());
            mysql_select_db($this->dbname);
            //register_shutdown_function(array(&$this, 'close'));
    }
    
        //*** Function: query, Purpose: Execute a database query ***
        function query($query) {
    
            $this->theQuery = $query;
            $res = mysql_query($query, $this->link)or die(mysql_error());
    	return $res;
    
        }
    
        //*** Function: fetchArray, Purpose: Get array of query results ***
        function fetchArray($result) {
    
            return mysql_fetch_array($result);
    
        }
    
    }
    ?>
    

     

    Then as you would normally:

    <?php
    require_once("DbConnector.php");   // Include the database class
    $db = new DbConnector();               // Create an instance of the database class
    $db->connect();                               // Connect to the database
    $query = "SELECT * FROM table;    // Perform a query to the database
    $result = $db->query($query);
    $rows = $db->fetchArray($result);  // Get an array with the results
    echo $rows["data"];  
    ?> 
    

     

     

  2. You're going to have to change every local HREF to match your new URL scheme. Have fun ;)

    Yes, you will.

     

    As I mentioned before, this really isn't a sufficient method to use for a scale of 200 files give or take. Hence why you should use Clean URLs (mod_rewrite) when starting an application, that way you can put contingency and fail safes in place.

     

    For a pre-built website with 200 files or more and hundreds if not thousands of redirects and anchor links, I'd for sure advise against this. On the other hand, if you were just starting this application. I'd support you all the way and advise you to use Clean URLs provided you have fail safes and contingency in place.

     

    For a dynamic URL you would use something like..

     

    http://domain.com/val1/val2/

    http://domain.com/index.php?var1=val1&var2=var2

  3. Please do clarify how exactly I'm mistaken? If that is the case, it's due to your poor explanations and descriptions.

     

    If you're asking for help on something specific, state it as clearly as you can, with a description on what you want and what you're trying to achieve. Thank you.

     

    As a matter of elaboration, they're both "select" box elements. A "jump" box as you so describe is just a select box with some JavaScript implemented into it.

     

    Now please, explain as best you can what you want, and what you're trying to achieve.

  4. This is what I use:

     

    RewriteEngine on
    
    RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
    RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
    
    RewriteRule ^([^/\.]+)/?$ /index.php?q=$1 [L]
    RewriteRule ^([^/\.]+)/([^/\.]+)/?$ /index.php?view=$1&id=$2 [L]
    # RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /index.php?section=$1&subsection=$2&page=$3 [L]
    
    # These rewrite rules can be used over and over for different master pages.
    # For example, see below.
    
    # RewriteRule ^([^/\.]+)/?$ /profile.php?user_id=$1 [L]
    # RewriteRule ^([^/\.]+)/([^/\.]+)/?$ /profile.php?category=$1&page=$2 [L]
    # RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /profile.php?category=$1&subcategory=$2&page=$3 [L]
    

     

    However I doubt that would be sufficient enough for over 200 different filenames. However, it should help you out a bit. Hopefully.

  5. Yes it should, thanks for pointing that out for me. Although doing that, I now have another problem. How will I be able to determine whether I should use "None" or not? Since $completed will always return TRUE to being an array.

     

  6. Ok so,

      If have a group of checkboxes, and I know how to get the values from each of them in an array. However, I can't seem to find a solution to

    only return a default value if "none" of the checkboxes are checked, and only return the values that are checked.

     

    I've tried:

      foreach($form_values['completed'] as $complete) {
        if($complete != 0) {
          $completed = array();
          $completed = array_push($completed, $complete);
        }
      }
      
      if (is_array($completed)) {
        $completed = implode(', ', $completed);
      }
      else {
        $completed = 'None';
      }
    

  7. Try this:

     

    $query = sprintf("SELECT * FROM `table` WHERE `City`, `State`, `ZipCode` LIKE '%s' AND `%s` = '1'", 
      mysql_real_escape_string('%'. $_POST['mainSearch'] .'%'),
      mysql_real_escape_string($_POST['Type'])
    );
    $result = mysql_query($query) or trigger_error(mysql_error());
    

     

    That's how I'd do it any way, assuming the value of $_POST['Type'] will be equal to the name of a field.

  8. or just write

     

    <input type="checkbox" name="check[]" value="1" />

     

    in php you could access it in this manner:

     

    <?php

     

    echo $_POST['check'][0]; // 1

     

    ?>

    ohhh smart

     

    I prefer to use implode(', ', $_POST['check'])); which will turn the array into a string, with the values being separated by comma's. Or you could loop through them using a foreach loop, if you want to automate things a bit.

     

  9. I've never had any problem writing and retreiving data from the database in any character case. Have you tried just writing a value to the database using different cases throughout and then tried validating it using lower case / upper case?

     

    <?php
    $sql = "SELECT pwd FROM users WHERE LOWER (`username`) = '".strtolower($username)."'";
    ?>
    

     

    Field names should not be in single quotes, surroung them with bck ticks..try and let me know

     

    A back tick is just another form of a quote, it doesn't matter what you surround them in, it's strictly for clarity and easy reading.

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