Jump to content

cpd

Members
  • Posts

    883
  • Joined

  • Last visited

  • Days Won

    5

Posts posted by cpd

  1. Have you printed your query out? Its quite possible that because you're using LIKE with wild cards on both sides of the value and OR for everything there is a match for every row. 

     

    Print the query and show it to us along with some of your database data.

     

    Posting a page of code isn't going to help, especially when its confusing as hell.

  2. I need it to where I don't always have to have a entry in there like this.

     

     

    Sorry... what?

     

    Yes

     

    Great answer, care to share why?

     

    If you NEED to use an XML file I suggest you do the following:

    1. Break your problem down into small problems, i.e. I need to create a file if it doesn't exist and append to one if it does.
    2. Tackle each problem individually, one-at-a-time.
    3. Comment your code so you, and others, know whats going on.
    4. Change "reports" to "report" as it contains report information not many reports.
    5. Define a Document Type Definition (DTD) to create a fully qualified XML document.

    Once you've broken the larger problem down into smaller ones you will, hopefully, find its actually a really easy task.

     

    Let me get you started

    // Does the file exist?
    if(file_exists($file)) {
        // Yes, lets get its contents
        $xml = file_get_contents($file);
    } else {
        // No, lets set up a default
        $xml = "<entries></entries>"; //Should also contain the DTD and the XML definition. Perhaps have a default XML file.
    }
    
    
    // Lets load the XML into a DOMDocument object...
    $dom = DOMDocument::loadXML($xml);
    
    
    // Now lets append entries. This will be the same regardless of whether or not the file already exists.
  3. One can only assume your system forces unique usernames, apply the same technique to your phone number field.

     

    Otherwise, post only the relevant code.

     

    Bambinou, do you understand what Jessica is saying here? By enforcing a UNIQUE constraint on the phone field within your table you'll achieve the basis of what you want. You can then implement php code to check for the phone number and display an error if it exists. 

     

    Moreover, why on earth were you attempting to create the table every time the script loaded? Think logically about what you're doing.

  4. I'd start by restructuring your DOM; at the moment you have no encapsulation for each expandable section. Consider wrapping each section in a div and then using a single span to wrap the titles with an additional span tag around the [-/+] parts.

     

    You can then write your JavaScript using the top node in each section, i.e. using the div that encapsulates each section, to manipulate the content within. I'd also suggest registering your event listeners in your JavaScript as opposed to inline although its not a big issue either way.

  5. I would consider using recursion to simplify your problem here as you have a 3 dimensional array. You need to consider how you want to display your data as well as this will affect the algorithm.

     

    Example

    function display(array $array) 
    {
        $output = "";
        foreach($array as $v) {
            $output.= (is_array($v) ? display($v) : $v);
            $output.= "<br />";
        }
        
        return $output;
    }

    You can then use this function by doing

     
    $array = array(...);
    
    
    foreach($array as $v) {
        foreach($array as $v) {
            echo (is_array($v) ? display($v) : $v);
            echo "<br />";
        }
    }

    That said, if you're unsure of the depth of your array you should consider a different data structure and definitely not use this method as it could cause overflow issues.

  6. From what you've said it sounds as though you'd merely return an array of data detailing the user information. A good object oriented design involves encapsulating data in the correct data structures with the correct visibility. For example the ID field of a user could be considered a property that shouldn't be overwritten and therefore you only provide a getter for that attribute. In contrast you could have the first and last name of a user that you want to be able to overwrite so you can write a getter and setter.

     

    You can then appropriately manipulate the state of the object and commit it to the database via the ORM.

  7. You're getting confused between your data model layer and your database layer; arguably one-in-the-same. 

     

    The logic for interacting with the database, i.e. the logic to actually run a query, should ideally be in a class of its own; this acts as a portal for all queries. A data model class wraps, normally, a single row from your query into an object. You can then pass this object between other objects to keep the information contained. If you want to pass multiple rows you can create an iterator and pass the iterator around.

     

    Or perhaps have an iterator contained within the data model that, when iterated through, sets the fields to their appropriate values within the data model.

  8. Whilst I love MVC and its approach so solving many programming problems I don't think its the answer you're looking for. MVC is a way of structuring you're code, not a design process.

     

    You need to look at your requirements and see what's already available. If something is available, how can you implement it? There are many frameworks, good and bad, available so look into them as they'll provide a rigid foundation for you to build your app on top of.

     

    Its hard to give any further comments because everything starts at what your requirements are i.e. what you want to achieve.

  9. An array holds many values not 1. Manipulating an array usually means altering its structure not merely taking its values and processing them. So again I ask, what do you want to actually do?

     

    MySQLi is usually downloaded with PHP as one of its extensions but if not you can probably download it from PECL.

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