Jump to content

RopeADope

Members
  • Posts

    157
  • Joined

  • Last visited

Posts posted by RopeADope

  1. Are you talking about the query cache?

     

    Probably?  I'm not familiar with the caching abilities of MySQL so I read through some documentation and user posts about it, but I'm still confused.  I think because of the way the question was asked of me, I figured there was an actual time setting somewhere.  Does the query cache has an actual time setting or is the time based on the number of queries ahead of the query in question?

  2. Hi all.

     

    I'm starting a mini-project with the purpose of creating PHP generated charts.  I just had a quick question on the class structure that I should use.  My instinct tells me to do it like this:

    class chart{
       function pie(){
       }
       function bar(){
       }
    }

     

    Is that a legitimate structure or is there a better way to do this?

  3. I might be thinking about it the wrong way, but it seems like to delineate table access by prefix I would need something in the connection script?  Or would the table access be purely on a database level?  If so, how do I restrict access on the database level?

  4. Hi all.

     

    I'm working on a PHP application that will serve several clients.  After a discussion on another thread about compliance, I've decided that using tables with a client specific prefix would be the safest way to go.  However, I'm having a lot of trouble wrapping my head around what the database connection script would look like.  I have a generic one that connects with host, user, pwd, and db as arguments but I'm not sure how to modify it to incorporate the table prefix requirement.  Thoughts on how I can incorporate the aforementioned requirement and enhance the script in general?

     

    function connect_mysql($host,$user,$pass,$database){
    $conn=mysql_connect($host,$user,$pass)or die('Cannot create link');
    mysql_select_db($database)or die('Cannot select database');
    };
    

  5. Finally got this figured out and working perfectly.  I had to rework the file naming convention slightly but everything displays perfectly now.  P.S. If there is any way to make this better or more compact, I'd greatly appreciate any input.

     

                <?php
    
                if ($handle = opendir($_SERVER['DOCUMENT_ROOT'] . '/documents/sop/')) {
                    echo "Files:</br>";
                    while (false !== ($file = readdir($handle))) {
                         if($file=="." or $file==".."){
                            echo "";
                         }else{
                            $pattern=array(
                            "/bus_mgmt_/",
                            "/dem_mgmt_/",
                            "/eng_/",
                            "/risk_mgmt_/",
                            "/ste_sta_/",
                            "/strategy_/",
                            "/financial_mgmt_/",
                            "/service_level_mgmt_/",
                            "/service_portfolio_/",
                            "/workforce_mgmt_/",
                            "/bus_it_requests_/",
                            "/change_mgmt_/",
                            "/project_mgmt_/",
                            "/release_mgmt_/",
                            "/availability_mgmt_/",
                            "/capacity_mgmt_/",
                            "/configuration_mgmt_/",
                            "/planning_/",
                            "/problem_mgmt_/",
                            "/compliance_/",
                            "/info_security_/",
                            "/service_continuity_/",
                            "/threat_mgmt_/",
                            "/incident_mgmt_/",
                            "/service_desk_/",
                            "/service_requests_/",
                            "/supplier_mgmt_/",
                            "/sop/",
                            "/context/",
                            "/.pdf/"
                            );
                            
                            $replace=array(
                            "Business Management - ",
                            "Demand Management - ",
                            "Engineering - ",
                            "Risk Management - ",
                            "Steady State - ",
                            "Strategy - ",
                            "Financial Management - ",
                            "Service Level Management - ",
                            "Service Portfolio - ",
                            "Workforce Management - ",
                            "Business/IT Requests - ",
                            "Change Management - ",
                            "Project Management - ",
                            "Release Management - ",
                            "Availability Management - ",
                            "Capacity Management - ",
                            "Configuration Management - ",
                            "Planning - ",
                            "Problem Management - ",
                            "Compliance - ",
                            "Information Security - ",
                            "Service Continuity - ",
                            "Threat Management - ",
                            "Incident Management - ",
                            "Service Desk - ",
                            "Service Requests - ",
                            "Supplier Management - ",
                            "SOP",
                            "Context",
                            ""
                            );
                           echo "<a href=\"$file\">" . preg_replace($pattern,$replace,$file) . "</a></br>";
                         }
                    }
                    closedir($handle);
                }
                ?>
    

  6. Just a side note...you may already do this...but I inevitably wind up with huge files mostly because I group things by logical function.  What I've always done is use tags and just search for the tags.

     

    Ex:

    <?php
    
    //Tags: post,print array, processing
    function myFunction(){
       echo "Doing some processing...";
       print_r($_POST);
    }
    
    //10,000 lines later...
    
    //Tags: mysql, query, last
    function lastFunction(){
       echo "This is the last function, I swear...";
       mysql_query();
       mysql_close();
    }
    

     

    Its obviously a very manual way to do it but its definitely easy to just "Find" a tag than to find something by scanning.

  7. Here's what's in my en.php so far.

    <?php
    
    $__TEXT__=array
    (
       /* Achievements Table */
       'achievements'=>"Achievements",
       'achievements_id'=>"Achievements ID",
       'date'=>"Date",
       'employee'=>"Employee",
       'achievement'=>"Achievement",
       'description'=>"Description",
       'date_of_occurence'=>"Date of Occurence",
       'skills_developed'=>"Skills Developed",
       'sponsor'=>"Sponsor",
       'comments'=>"Comments",
       /* Activity Details Table */
       'activity_details'=>"Activity Details",
       'activity_details_id'=>"Activity Details ID",
       'date'=>"Date",
       'activity'=>"Activity",
       'description'=>"Description",
       'comments'=>"Comments",
       /* Actual Table */
       'actual'=>"Actual",
       'actual_id'=>"Actual ID",
       'date'=>"Date",
       'capacity_incidents'=>"Capacity Incidents",
       'capacity_problems'=>"Capacity Problems",
       'capacity_10%'=>"Capacity 10%",
       'optimizations'=>"Optimizations",
       'description'=>"Description",
       'capacity_plan_date'=>"Capacity Plan Date",
       'capacity_plan_summary'=>"Capacity Plan Summary",
       'comments'=>"Comments",
       /* Agreement Activity */
       'agreement_activity'=>"Agreement Activity",
       'agreement_activity_id'=>"Agreement Activity ID",
       'date'=>"Date",
       'agreement_name'=>"Agreement Name",
       'activity'=>"Activity",
       'description'=>"Description",
       'next_step'=>"Next Step",
       'status'=>"Status",
       'comments'=>"Comments",
       /* Agreement Details Table*/
       'agreement_details'=>"Agreement Details",
       'date'=>"Date",
       'type'=>"Type",
       'agreement_name'=>"Agreement Name",
       'party'=>"Party",
       'description'=>"Description",
       'penalties'=>"Penalties",
       'start_date'=>"Start Date",
       'end_date'=>"End Date",
       'owner_1_name'=>"Owner 1",
       'owner_2_name'=>"Owner 2",
       'file_name'=>"File Name",
       'file_location'=>"File Location",
       'comments'=>"Comments",
       /* Availability Table*/
       'availability'=>"Availability",
       'availability_id'=>"Availability ID",
       'date'=>"Date",
       'avail_incid'=>"Incident",
       'avail_unavail'=>"Unavailable",
       'avail_down_pr1'=>"Down PR1",
       'avail_down_pr2'=>"Down PR2",
       'avail_down_pr3'=>"Down PR3",
       'avail_alerts'=>"Alerts",
       'util_unavail'=>"Utilities Unavailable",
       'avail_auto'=>"Availability Auto",
       'avail_proc'=>"Available Processes",
       'comments'=>"Comments",
       /* Strategy Table */
       'strategy'=>"Strategy",
       'strategy_id'=>"Strategy ID",
       'date'=>"Date",
       'bus_strategy'=>"Business Strategy",
       'tech_strategy'=>"Technology Strategy",
       'co_values'=>"Company Values",
       'comments'=>"Comments",
       'mission'=>"Mission",
       'project_approval_board'=>"Project Approval Board",
       'change_mgmt_board'=>"Change Management Board",
       'emergency_change_board'=>"Emergency Change Board",
       'cm_owner'=>"Change Management Owner",
       'cm_alternate'=>"Change Management Alternate",
       'change_window'=>"Change Window",
       /* KEDB Table */
       'kedb'=>"Known Error Database",
       'kedb_id'=>"KEDB ID",
       'date'=>"Date",
       'service'=>"Service",
       'system'=>"System",
       'it_owner'=>"IT Owner",
       'description'=>"Description",
       'impact'=>"Impact",
       'status'=>"Status",
       'resolution'=>"Resolution",
       'close_date'=>"Close Date",
       'comments'=>"Comments",
       /* vCTO Tasks Table */
       'vcto_tasks'=>"vCTO Tasks",
       'vcto_task_id'=>"vCTO Task ID",
       'date'=>"Date",
       'process'=>"Process",
       'task'=>"Task",
       'origination'=>"Origination",
       'assigned_to'=>"Assigned To",
       'status'=>"Status",
       'due_date'=>"Due Date",
       'completed_date'=>"Completed Date",
       'next_steps'=>"Next Steps",
       'comments'=>"Comments"
    );
    
    ?>
    

     

    The majority of the tables in this application were converted from Access so that's why it has all the weird naming conventions.  I understand your point now about uniqueness of the labels and such.  So my question is this: How do I modify the en.php file in such a way that it's unique to the tables?  Would I have a different array for each table then when I call the build_form function, I'd call it like this:

    build_form($table_name,$table_label_array)

    ?

     

    EDIT:  Another thing I thought of is in terms of "setting and forgetting" code.  As the database changes in either table names or field names, I'll still have to change the en.php file to address those changes.  So there really isn't a way to write something once and have it always work...or am I missing something?

  8. So really, the $__TEXT__ array should be split up into several table-specific label arrays?  I guess I'm confused as to why its not easier to have $__TEXT__ as a global "fits all" array that can be used anywhere.  That's where my thought process was...just have a huge list of labels that works regardless of context.  What sort of problems would that cause?

  9. So I would have to take my current $__TEXT__ array and put it into its own function to make it global?  Or am I supposed to add

    global $__TEXT__;
    

    to the existing build_form() function?  Or can I just add the word "global" before my $__TEXT__ array in the en.php file?

  10. It might be doing something, but it is apparently not set as I suggested. You would be getting errors when you reference $__TEXT__[...] as an array or those errors are hidden in the 'view source' of your page because they are being output inside of a html tag. Have you checked the 'view source' of the page in your browser?

     

    The source only shows the errors that are output to the web page.  Namely the one about an invalid argument in the foreach loop.

     

    This is a sample of the source.  The first set of <td></td> is where the labels should be shown.

    <form method="post" action="/php/process_data.php"><input type="hidden" name="selected_table" value="strategy"/><table><tr><td colspan="2" style="font:1em arial;font-weight:bold;text-align:center;">Input Form: Strategy</td></tr>
    
    <tr><td><br /> 
    <b>Warning</b>:  Invalid argument supplied for foreach() in <b>C:\xampp\htdocs\php\functions.php</b> on line <b>45</b><br /> 
    </td></tr><tr><td>Strategy Id</td><td><input type="text" size="30" disabled="disabled" name="strategy_id" /></td></tr>
    
    <tr><td></td><td><input type="text" size="30" name="date" /></td></tr>
    
    <tr><td></td><td><input type="text" size="30" name="bus_strategy" /></td></tr>
    
    <tr><td></td><td><input type="text" size="30" name="tech_strategy" /></td></tr>
    
    <tr><td></td><td><input type="text" size="30" name="co_values" /></td></tr>
    

     

    This is the function that builds the forms:

    function build_form($table_name){
    
       //The MySQL statement
    
    $sql="SELECT * FROM $table_name";
    
    //Result variable
    
    $result=mysql_query($sql);
    
    //If the result is empty, return.
    
    if($result=="") return;
    
    $i=0;
    
    
    
    //Echo some HTML for the form
    
    echo "<form method=\"post\" action=\"/php/process_data.php\">";
    
    echo "<input type=\"hidden\" name=\"selected_table\" value=\"" . $table_name . "\"/>";
    
    echo "<table>";
    
    
    
    //Echo the table name
    
    echo "<tr><td colspan=\"2\" style=\"font:1em arial;font-weight:bold;text-align:center;\">Input Form: " . ucwords(preg_replace("/_/"," ",$table_name)) ."</td></tr>" . PHP_EOL;
    echo "<tr><td>";
       foreach($__TEXT__ as $key=>$value){
          echo $key,$value;
          }
    echo "</td></tr>";
    
    //While $i is less than the number of returned fields, complete this loop
    
    while ($i < mysql_num_fields($result)){
    
    	$fields=mysql_fetch_field($result,$i);
    	if(preg_match("/ID/",$fields->name) or preg_match("/_id/",$fields->name)){
    
       		   echo "<tr><td>" . ucwords(preg_replace("/_/"," ",$fields->name)) . "</td><td><input type=\"text\" size=\"30\" disabled=\"disabled\" name=\"" . $fields->name . "\" /></td></tr>" . PHP_EOL;
    
    	   }elseif(preg_match("/comment/i",$fields->name)){
    
    	      echo "<tr><td>" . ucwords(preg_replace("/_/"," ",$fields->name)) . "</td><td style=\"padding:3px;\"><textarea style=\"width:98%;height:50px;resize:none;\" name=\"" . $fields->name . "\" /></textarea></td></tr>" . PHP_EOL;
    
    	   }elseif(preg_match("/owner/i",$fields->name)){
    
    	      echo "<tr><td>" . ucwords(preg_replace("/_/"," ",$fields->name)) . "</td><td style=\"padding:3px;\"><select style=\"width:100%;height:24px;\" name=\"" . $fields->name . "\" /><option value=\"\"> </option>";
    
                   $owner_sql="SELECT employee_id,last_name,first_name FROM employees";
    
                   	$owner_result=mysql_query($owner_sql);
    
                   	$y=0;
    
                   	while($y < mysql_num_rows($owner_result)){
    
                   	   $id=mysql_result($owner_result,$y,"employee_id");
    
                   	   $last=mysql_result($owner_result,$y,"last_name");
    
                   	   $first=mysql_result($owner_result,$y,"first_name");
    
                   	   echo "<option value=\"$id\">$first $last</option>";
    
                   	   $y++;
    
                   	   };
    
                echo "</select></td></tr>" . PHP_EOL;
    
    	   }else{
    
    	      echo "<tr><td>" . $__TEXT__[$fields->name] /*ucwords(preg_replace("/_/"," ",$fields->name))*/ . "</td><td><input type=\"text\" size=\"30\" name=\"" . $fields->name . "\" /></td></tr>" . PHP_EOL;
    
    	   };
    
    	$i++;
    
    	};
    
    echo "<tr><td colspan=\"2\" style=\"text-align:center;\"><input type=\"submit\" value=\"Submit Data\" style=\"width:75%\" /></td></tr>";
    
    echo "</table>";
    
    echo "</form>"; 
    
    };
    

     

    This is the actual warning I get from the foreach()

    Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\php\functions.php on line 45
    

  11. The current code is the same as previously posted.  Error reporting is working but its not catching any errors.  I tried to just print_r($__TEXT__) and all it prints is "1".

     

    Just for clarification, here's the contents of the en.php file again:

    <?php
    
    $__TEXT__=array
    (
       'strategy'=>"Strategy",
       'comments'=>"Comments",
       'date'=>"Date",
       'bus_strategy'=>"Business Strategy",
       'vcto_tasks'=>"vCTO Tasks"
    );
    
    ?>
    

     

    And a line with an attempt to use the contents of en.php

    echo "<tr><td>" . $__TEXT__[$fields->name] . "</td><td><input type=\"text\" size=\"30\" name=\"" . $fields->name . "\" /></td></tr>";
    

     

    I've also tried it as $__TEXT__[$fields] and I've tried it with a simple string variable that matches a label in the en.php file.  Always prints out a blank.

     

    EDIT/UPDATE:  I tried the following and got an invalid argument warning

       foreach($__TEXT__ as $key=>$value){
          echo $key,$value;
          }
    

  12. Interestingly enough, the left and right divs automatically increase height depending on the widget space required...I'm not quite sure what to make of that.  Logically, I would think that it would require the overflow:hidden.  But I guess maybe it wouldn't because of the catch that you mentioned in your blog about the "clearfix"?  Any ideas?

     

    P.S.  Problem is solved, just looking for some input :-)

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