Jump to content

yonta

Members
  • Posts

    70
  • Joined

  • Last visited

    Never

Everything posted by yonta

  1. Thanks for your help Jenk I undestand it better now :)
  2. So are you saying that instead of extending the dbmanager in all my models, to avoid the repetition i could in a controller do $db = new DbManager(); $products = new ProductsModel($db); - basically just pass the dbmanager around, and since i only use one controller in a single call to the server there would be uneeded multiple instantiation. It does seem cleaner :) thank you, thank you So pconnect checks if there's already a connection available. I use persistent connections because i read that it's faster but that you also increase the risk of having too many connections open. How is that if pconnect checks if there's already a connection available? 'if it's a database management application, you may very well want multiple connections available' - it is, but i really don't get why i would want multiple connections to the database. If multiple users are asking to see the same or different pages, shouldn't the server use the same connection to mysql? Could you explain this a bit more please? thanks :)
  3. Ok, maybe my post was a bit confusing. If you follow the mvc pattern in your apps, do you have a common database manager for all your models (in my case, it's a wrapper for adodb - http://adodb.sourceforge.net/ ) or not? If not, why not? If you do have a common db manager, how do you avoid multiple attemps to connect to the database when you use more than one model in a controller? Do you simply detect if there's a connection already established or not? I'm thinking i could use something like this: [code] $this->DB = &ADONewConnection('mysql');   if(!$this->DB->IsConnected( ))   {   $this->DB->PConnect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE) or   trigger_error("Não é possível ligar à base de dados. Contacte o administrador.", E_USER_ERROR);   } [/code] Do you do something like this as well?.. I'm still a bit new to the oop scene so if anyone could tell me how they do it, it would help. Thanks
  4. Right now i'm following the mvc pattern in an app i'm building, so i basically have templates, controllers and models. There's one model per mysql table, so if i have a products table i'll have a products_model with all the basic CRUD functionality. A controller can use one or several models. For example, each product can have several documents and so there's a product_docs table and its corresponding model. This means that the product_controller can use the products_model and the product_docs_model. All models extend (inherit from) a common database manager class and it's this common class that's responsible for actually connecting to the database (it has a connect method). Now for my problem: if in a single call to the server more than one model is used, there will be more than one instance of the database manager class created, and so more than one attempt to connect to the database (it's a persistent connection, btw) and there seems to be no need for it. In a single call to the server i only need to connect once to the database. I mean, performance wise it just seems stupid. And so i thought i could use the singleton pattern to ensure that only one attempt to connect to the database was done. something like this: [code] class products_Model extends DbManager { var $select_titles; var $tablename; var $security; function products_Model() { $this->tablename = 'products'; $this->select_titles = 'SELECT prod_id, prod_title, prod_text, prod_ispub FROM '.$this->tablename; if(!singleton::getInstance('DbManager')) //if there's no dbmanager in singleton array, attempt to connect parent::connect();                 //without the singleton pattern it was just like below                 //parent::connect(); $this->security = new Security(); } [/code] But searching around i found this: "The singleton pattern applies to the situation where you need a single, global instance of a class. It fits situations where a factory object returns uniform objects, such as file handles or user sessions. These aren't good candidates for being implemented in a PHP script because the [b]language provides built-in solutions such as persistent database connections[/b]." ( http://www.zend.com/zend/trick/tricks-app-patt-php.php ) which of course got me thinking. Am i thinking about this the totally wrong way? Maybe i should do it another way? Or is it actually ok? Or there's no need to worry about making several calls to pconnect since it's a persistent connection anyway? Or should i use delegation ($db = new DbManager(); ) instead of inheritance (.. extends DbManager ) ? Any input would be a great great help.
  5. It should be okay. Here's a snippet - just check your code against this or if the error persists post your code here [code] //javascript in head section var valid; function validate_form ( ) {       if ( document.form.artistnametxt.value == "If not, write it here" || document.form.artistnametxt.value == "")     {         alert ( "You must select an artist name!!\n\nEither do so from the drop down list or input it manually" );         valid = false;     } else { alert ( "Good boy");//just for testing valid = true; } } //html in body section, notice i have 2 css styles named blue and red <form id="form" name="form" method="post" action=""> Artist &nbsp;<input type="text" name="artistnametxt" id="artistnametxt" value="If not, write it here"/><br/><br/>     <input type="button" name="Submit" class="red" value="Validate" onClick="validate_form();"/><br/> <input type="button" name="Submit" class="red" value="Check" onClick="if(valid==true){this.className='green'} else {this.className='red' };"/> </form> [/code]
  6. Well, if you put it outside of any function, you effectively make it global, and so it is available inside your functions. So when you do valid=true inside a function you are effectively changing the global variable valid from false to true.
  7. Glancing over your queries i noticed the BETWEEN keyword. Normally it's BETWEEN value1 AND value2. You don't specify the 2nd value. Also while debugging it's useful to remove the silencing operator @ from the mysql_query call to get the error message. If it still doens't work post the error message here.
  8. It has to do with variable scope. You defined the valid variable inside the function so it is only available inside that same function. To make it work you need to make the valid variable global. Just do this in the beginning of your script: var valid= false; Check this article http://www.webdevelopersnotes.com/tutorials/javascript/global_local_variables_scope_javascript.php3
  9. You could use something like this to rename a file: [code] function rename_filename($whichfile) { $random_number = rand(100000, 999999); $hour = date ("Hms");//234012                 $info = pathinfo($whichfile); return "usrfile_" . $random_number . "_" . $hour . '.' . $info['extension']; } [/code]
  10. So basically [code] <INPUT TYPE = Button VALUE = "Click Me" OnClick = "document.getElementById('myDivID').innerHTML='Hello World'"> <div id = "myDivID">It will appear here.</div> [/code]
  11. The error is telling you that there should have a php object named my dir ($mydir) and it should have a method read() ($mydir->read() ) but you don't. Somewhere in your script you should have $mydir = new MyClass(); where myclass is the name of the class that handles reading directories. If you can't find it, you'll need a function to read a directory (i can help you there). Either that or ask your friend who first helped you. Best
  12. I was under the impression that not all browsers set HTTP_REFERER, so you can't really rely on it (http://www.php.net/manual/en/reserved.variables.php). Any thoughts?
  13. Think you have an extra ( there try this: if (strlen($file) > 2) instead of if ((strLen($file) > 2)
  14. Not sure but i think you could use the $_SERVER['SCRIPT_FILENAME'] to return the full path to the current script, so if someone asked for news.php and if the login was false, you could use something like header("Location:login.php?url=".$_SERVER['SCRIPT_FILENAME']); and in login.php redirect to the specified $_GET['url'] Hope this helps
  15. How about putting a div below the submit button, and google about javascript's getElementById and innerHTML? Yes, this is really easy. Too easy to give you the full answer. Just google.
  16. How about this: [code] _root.sub.onRelease = function () {   loadphpVariables(); } function loadphpVariables() {       var objSend:LoadVars = new LoadVars(); /*Values (id) to be sent to php from textbox text value */ objSend.id = _root.textboxname.text; /*Sending variables to php and loading returned variables (post method) -> there was a typo here objSend not ObjManda*/ objSend.sendAndLoad("flash.php"+"?nocache=" + Math.random(), objSend, "POST"); /*When the results are received*/ objSend.onLoad = function(ok) { if (ok) { /*you now access the variables inside the php as this.variablename*/                         _root.movieclipname.text = this.mytitle; _root.movieclipname.text = this.mymessage; } }; } [/code] I haven't tested it but this how i remember it should be. Look for some tutorials here http://www.kirupa.com/web/index.htm Hope it helps
  17. Here's how you could do it: [code] var objSend:LoadVars = new LoadVars(); /*Values (id) to be sent to php*/ objSend.id = promoid; /*Sending variables to php and loading returned variables (post method)*/ objSend.sendAndLoad("promocoes.php"+"?nocache=" + Math.random(), objManda, "POST"); /*When the results are received*/ objSend.onLoad = function(ok) { if (ok) { /*you now access the variables inside the php as this.variablename*/                         _root.movieclipname.text = this.mytitle; _root.movieclipname.text = this.mymessage; } }; [/code] This actionscript expects php to process $_POST['promoid'] and print something like &mytitle=tittle 1&mymessage=text1 whatever You could also print xml from php and use something like var nXML = new XML(); nXML.ignoreWhite = true; nXML.onLoad = function(){ } gXML.sendAndLoad(file, nXML); For more info search for the Kirupa forums, LoadVars.send (eg. http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary434.html) or sendAndLoad, Xml.send (http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary855.html ). Just some clues. Best :)
  18. How about checkdate http://pt.php.net/manual/en/function.checkdate.php ?
  19. Are you sure this query actually returns anything? SELECT * FROM assignment WHERE promised_begin_dt = '$selectdate' and person_id = '$User_ID' Replace the variables with real values and try it in phpmyaddmin. Maybe it's simply empty. You should probably check before the while if it's false (which you do) and if the number of rows returned is bigger than zero.
  20. Your variable amount is astring and should be a float. You can use the settype function, like this settype($amount, "float"); before checking for is_finite.
  21. Well, it's probably of no interest to anyone but i'll just post it in case anyone runs into this using the same setup - phpSavant for templates and Cache_Lite for caching. The only problem was not Cache_lite related but Savant related. I thought Savant's fetch method executed, displayed the output, and last returned the output but no - it doesn't display. I had to always use ->display(); So the problem was this (in banners_List() method): CACHING == true? $data = $this->tpl->fetch('banners_list.tpl.php'): $data =$this->tpl->display('banners_list.tpl.php'); where instead i should have just done this [code] CACHING == true? $data = $this->tpl->fetch('banners_list.tpl.php'); //if caching is on fetch the output into variable $data $data =$this->tpl->display('banners_list.tpl.php'); //displays the output - this should always run, caching or not CACHING == true? $this->objCache->save($data, 'ban_list'):''; //if caching is on save the output in cache file [/code]
  22. Well, since i'm a developer and have no illusion of being - or ever becoming - a really good designer, i always work with a designer. I do what i'm best at, the designer does what she's best at, and the overall result is much better and unique than it would have been if the designer had done the code and the design, or if i had done the code and the design. The trick is, of course, finding someone who's easy and trustworthy to work with. My 2 cents :)
  23. Well, maybe it's the @ - shouldn't it be % ? $query = "select * from link where ".$searchtype." like '%".$searchterm."@'"; Or maybe try this $num_results  = mysqli_num_rows($result); Other than that i don't see anything wrong. Check this page http://www.php.net/manual/en/function.mysqli-num-rows.php
  24. Shouldn't be too hard to search on this, but if both fields are in the same table just 'SELECT field_one, field_two FROM tablename ' if they're in two separate tables 'SELECT tablename_one.field_one, tablename_two.field_two FROM tablename_one, tablename_two ' and if they're somehow related use the WHERE clause
  25. You have a typo here (notice the double $$ in result) $num_results = $$result->num_rows;
×
×
  • 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.