Jump to content

roopurt18

Staff Alumni
  • Posts

    3,746
  • Joined

  • Last visited

    Never

Everything posted by roopurt18

  1. I tried to think of the most obscure line I could and that has to be a winner. While I loved that show, that line in conjunction with the one directly before it, is probably the most clever bit of writing that came out of it.
  2. Shawshank Redemption. pwnt (no google necessary) If anyone gets this without Google, I'll be surprised.
  3. As soon as you process the user's input, use header("Location: " . $newurl); exit() to redirect to a final page.
  4. http://www.phpfreaks.com/forums/index.php/topic,58799.0.html
  5. Follow this link: http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html#function_date-add Then scroll down until you see: As of MySQL 3.23, date arithmetic also can be performed using INTERVAL together with the + or - operator: date + INTERVAL expr unit date - INTERVAL expr unit Following is a list of date manipulations you can perform right in SQL without using any PHP code.
  6. CSS, aka cascading style sheets.
  7. Yes, you do use Javascript for the onchange event. You should try posting this in the Javascript forum. Additionally you should do some learning on your own as Javascript can become quite messy and complicated in the hands of a novice. A link to the O'Reilly book I used to learn Javascript: http://www.amazon.com/JavaScript-Definitive-Guide-David-Flanagan/dp/0596101996/ref=sr_1_4/103-2697599-1496625?ie=UTF8&s=books&qid=1178131946&sr=1-4 A link to w3schools Javascript tutorial, which I refer to constantly when I don't have the O'Reilly book handy: http://www.w3schools.com/js/default.asp
  8. The (int) is a typecast; it tells the interpretor to treat the variable as the data type within the parentheses, in this case as an integer. If you remove the typecast, the script will output: Bool is set to true Bool is set to This is because when you echo false, nothing is echoed. By using the typecast, the output becomes: Bool is set to true Bool is set to 0
  9. Scroll all the way to the bottom of the page.
  10. In our software we have what's called an option number, which is really a concatenation of a trade code and an actual number. In your SQL you can do: SELECT CONCAT( field1, LPAD( field2 ) ) AS PONum FROM ... To pull the data in the format you wish to use it. But separating the fields will give you advantages down the road when you wish to sort Of course, you can work with the system you have an all will most likely be well.
  11. If you don't use a login system where people have to identify themselves, then this is next to impossible. Cookies can be turned off or a user can just use a different computer. You can't do this based off IPs because users are assigned dynamic IPs and a company, library, university, etc. will have many machines mapped to a single outgoing IP.
  12. Is there any reason you don't break it into two fields? You can always concatenate them as you pull from the database and pad the number with leading zeros for numbers less than 1000.
  13. clown, if you read the error message you will see that the OP is using mysql_connect as it is mysql_connect that is generating the error. To the OP, the pertinent part of the error is: Where ever the code is that actually connects, it is trying to use a constant named DB_SERVER_USERNA. The code you posted: <?php define('DB_SERVER_me222', ''); // your username that you use to log into your web server define('DB_SERVER_handyman', ''); // your password that you use to log into your web server define('DB_DATABASE', 'me222_books'); // replace username with your web server username ?> You have changed DB_SERVER_USERNA to DB_SERVER_handyman. Try: <?php define('DB_SERVER_USERNA', 'handyman'); ?> I have a feeling you're going to receive more errors though.
  14. You need to read and interpret the errors you receive if you want to excel as a developer. This is telling you that the file you are trying to include does not exist. "But it does exist!" you say. "I can see it in windows explorer!" Well, in that case you're probably using the wrong path. <?php include ("./comments/comments.php?id=1"); ?>
  15. Using the == approach you can potentially not process an order. Using the >= approach you can potentially process an order more than once. Out of the two, the first is more catastrophic; either the end-user never gets their service or your client never gets their money. I'd use this approach: <?php if($today >= $billing && !$processed){ } ?>
  16. My uncle has a Rav4 and they got a bit of juice to them. I still remember the first year that they came out, they were a cross between a jeep and SUV and looked ridiculous. They look a lot better in recent years than they did then.
  17. Grats! But the million dollar question is.... Whats the MPG?
  18. Constants are just that, constant. They're not meant to be changed, ever. For instance, a framework or module might use internal constants for it's own purposes that are not meant to be modified by the application that is using the framework or module. For example, a forum module might define it's own internal error constants. <?php define( 'EZFRM_ERR1', 0x01 ); define( 'EZFRM_ERR2', 0x02 ); // and so forth ?> When you see something like that, those values are integral to the operation of the forum module. The authors of the module do not intend for you to change those values. They are defined in that fashion because when the authors of the forum are maintaining the code if( $status == EZFRM_ERR2 ){ is easier to read and implies more information than if( $status == 0x02 ) Most modules and frameworks provide a series of settings that can be modified through an array named $config. There are two things any programmer should notice about this variable right off the bat: 1) config is short for configure or configuration 2) it is a variable, therefore it can be modified There will always be settings or parameters that are environment dependent that the authors of a framework or module are unable to predict. I'm sure you've noticed that moving a website from one host to another is not an easy task, invariably certain things break. The reason is because the operation of your site depends on certain settings of the environment. The same goes for creating a general-purpose module or framework. As the author of such a tool, you can not begin to predict what type of environment it will be run in. Therefore, you provide a means of allowing the user, or client, who is another programmer, of your module / framework a method of configuring it. You do this through the $config array.
  19. They're constants. <?php define("FILE_EXT_CSS", "css"); define("FILE_EXT_JS", "js"); ?> Typically, constants are IN_ALL_CAPS. Using capital letters for constants isn't anything that's forced on us by the interpretor. Most programmers just adopt the convention of using all capitals for their constant names because it makes them stand out. Thus, when you see all caps in your code where a variable name could have been used instead, you should see that as, "Hey buddy! I'm a constant! I'm probably defined elsewhere!"
  20. CTemplate.php <?php // CTemplate.php // Template object. Wrap up our mechanism for creating and displaying // pages in a more simple matter. require_once( DIR_MODEL_ROOT . "/CNavMenu.php"); class CTemplate{ var $stylesheets = Array(), $javascript = Array(); // constructor // Prepare the object for use function CTemplate(){ $this->stylesheets = Array(); $this->javascript = Array(); return; } // AddJavascript // $Name - Name of the javascript file. // Will automatically be prefixed with URI_JS_ROOT and ended with // FILE_EXT_JS function AddJavascript($Name){ if(!in_array($Name, $this->javascript)){ $this->javascript[] = $Name; } return; } // AddCSS // $Name - Name of the CSS file. // Will automatically be prefixed with URI_CSS_ROOT and ended with // FILE_EXT_CSS function AddCSS($Name){ if(!in_array($Name, $this->stylesheets)){ $this->stylesheets[] = $Name; } return; } // Display // $Title - The page title // $Content - The page content // Display the page to the user function Display($Title, $Content){ global $clientObj, $sessObj; $params = Array(); $Maint = LoadComponent("General/Maintenance"); $navMenu = &new CNavMenu($clientObj, $sessObj); $params = Array(); $params['Client'] = $clientObj; $params['Sess'] = $sessObj; $params['Title'] = $Title; $params['Javascript'] = $this->makeExtraJavascript(); $params['CSS'] = $this->makeExtraCSS(); $params['Content'] = $Content; $params['NavMenu'] = $navMenu->getMarkup(); $params['Maintenance'] = $Maint; echo LoadComponent("General/Page", $params); return; } // makeExtraCSS // Take the internal css array and create the necessary links out of it. // In addition, add any custom styling information added by our clients. function makeExtraCSS(){ $CSS = ''; if(count($this->stylesheets)){ foreach($this->stylesheets as $href){ $CSS .= "<link href=\"" . URI_CSS_ROOT . "/{$href}." . FILE_EXT_CSS . "\" rel=\"stylesheet\" type=\"text/css\" media=\"all\" />"; } } return $CSS; } // makeExtraJavascript // Take the internal javascript array and create the necessary links out // of it. function makeExtraJavascript(){ $JS = ''; if(count($this->javascript)){ foreach($this->javascript as $src){ $JS .= "<script src=\"" . URI_JS_ROOT . "/{$src}." . FILE_EXT_JS . "\"" . " type=\"text/javascript\"></script>"; } } return $JS; } } ?> The function LoadComponent() and an example component follow to provide clarification on what occurs in CTemplate::Display() LoadComponent() <?php // LoadComponent // $name - component name // $params - associative array holding component parameters // do not have any keys with the following names: // File__ // Template // RETURN: HTML text to print from the component function LoadComponent($name, $params = NULL){ global $Template; $html = NULL; $File__ = DIR_COMPONENTS . "/" . $name . ".php"; if(file_exists($File__)){ if(is_array($params) && count($params)){ extract($params); } ob_start(); include($File__); $html = ob_get_contents(); ob_end_clean(); }else{ $File__ = str_replace(".php", "", $File__); $File__ = str_replace(DIR_COMPONENTS . "/", "", $File__); $html = "Could not locate component: {$File__}"; $html = CreateStandardText($html, "left"); } return $html; } ?> ExampleComp.php <?php /** * ExampleComp.php * Expects vars: * $Letter - A letter * $Num - A number */ ?> <p> Today's broadcast was brought to you by the letter '<?=$Letter?>' and the number <?=$Num?> </p> This component would be loaded with the following code: <?php $params = Array(); $params['Letter'] = "B"; $params['Num'] = "5"; echo LoadComponent(COMPONENT_DIRECTORY . "/Messages/ExampleComp", $params); ?>
  21. All of the pages in the site at my work are built through a CTemplate class. This class uses Page.php as the basis for all of it's pages: Page.php <?php /** * Page.php * The basis for every page in the site. * Expects Vars: * $PageHeader - Page header * $PageContent - Page content * $PageFooter - Page footer */ ?> <!DOCTYPE ...> <html> <head> <!-- Stylesheets for every page --> <style ...></style> <style ...></style> <style ...></style> <!-- Javascript for every page --> <script ...></script> <script ...></script> <script ...></script> </head> <body> <?=$PageHeader?> <?=$PageContent?> <?=$PageFooter?> </body> </html> In addition, CTemplate exposes an addJavascript method. This method takes the name of a JS file and automatically adds the appropriate Javascript tags into the header section of all pages outputted. Using this system, it's very easy to set up Javascript files that are included on every single page in addition to allowing certain pages to include specific JS files particular to that page.
  22. Some of you need to turn on your verbose flags.
  23. Alternatively you could have put back ticks around it.
×
×
  • 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.