Reusing An Object For Common Select To Database
I've noticed that after I finished this app, I had repeated a similar task over and over and would like to modularize it. The repeated task was connecting to the database, executing a select, putting all the results of the columns into different variables of an object. PHP Code:
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Pre-caching Common Queries On A Database
In trying to improve the performance of searches on a database, I read that it makes sense to run a small set of common queries off-line and cache them in a plain HTML file, and then use HTTP Location: to point to the static page. Problem is the book I read only talks about CGI. Can anyhow tell me/point me in the right direction for doing a similar thing using PHP?
Call To A Member Function Select() On A Non Object.
I amn trying to use my db class in my auth class, but i get the error: call to a member function select() on a non object: <?php class db { // Members private $db_user = "mydbuser"; private $db_pass = "mypassword"; private $db_name = "mydb"; private $db_server = "myhost.com"; private $link; private $result_id;...
Capturing $_REQUEST And Reusing It Later
I'm working on an authentication system in which it's possible that a user might be requested to log-in as a result of submitting a form if the inactivity timeout is exceeded. In order that they don't lose the information in the form I would like to capture this information ($_RESULT), serialise it and store it in their session. After they've successfully logged in I would like to retrieve this information and put it back in $_RESULT so the user can carry on with what they were doing. Is $_RESULT meant to be writable in this wayand is there any reason why this isn't a good idea?
Big Database: Many SQL Tables Vs. Object Serialization
I'm building a PHP+MySQL application for a large website, with 100.000+ records in the main table, each one with a lot of dependencies in other SQL tables. Thus each page view requires many SQL queries and/or joins. Since I want to optimize performance, I'm wondering whether it would be better to serialize full objects instead and store them in a single table's TEXT field. This way I could just retrieve the row and unserialize it, avoiding other queries. So far this is my comparison: Pros: - only one query per page view Cons: - not only a bigger database, due to serialization overhead, but a single HUGE table (does this slow down things more than doing many queries?) Of course there are other drawbacks I actually don't care, such as getting a very PHP-specific database or limiting retrival to IDs. Does anybody have any advice about this? (Other than "try and benchmark it" :->)
Object Oriented Approach To PHP Programing And MySQL Database
I am new to PHP and working on extending my knowledge of OOP. The posts in this group concerned with whether or not to use an OO approach when programming in PHP is not what I want to discuss in this post. Rather I would like to discuss the best way to program the following problem: I have a MySQL Database which for example exists of phonenumbers. The table might look something like this. +---+---------------+------+ |ID | PHONENUMBER | FLAGS| +---+---------------+------+ |001| 612341234| FALSE| +---+---------------+------+ |002| 612341235| TRUE | +---+---------------+------+ |...| ...| FALSE| +---+---------------+------+ |00N| 612341238| FALSE| +---+---------------+------+ An object representation in PHP might be the object PhoneNumber. The object PhoneNumber would be extended from a general class called Entity. The class Entity allows for easy creation of new database objects. Say I would like an EmailAddress object, I would simply create the MySQL table, extend the Entity class with an EmailAddress class and populate the SQL variables with the correct SQL statements. Until this far everything is ok. But what if I would like an extended version of the objects PhoneNumber or Emailaddress? Say for example that I would like an object called MobilePhoneNumber. The only difference with the normal PhoneNumberClass is that it is of the type MobilePhoneNumber (usage: A function only accepting MobilePhoneNumber Objects for sending text messages). I would like to create a MySQL table that consists of mobilephonenumerid's and phonenumberid's. What would be the best way, rewriting the internals of the Entity class and just fetch the data from MySQL right away or writing new internals for the MobilePhoneNumbers class which create a phoneNumberObject if it does not exist? Hope that my problem and questions are clear,
Database Value Select In Combo Box!
This function is intended to display the current database field value as selected.. along with other values as general options. I can't figure out how to get it work. Help is appreciated!! function retrieve_category() { $cat = mysql_query("SELECT category_id FROM category"); while ($current_row = mysql_fetch_row($cat)) { $row = $current_row[0]; if ($row == $id) { printf("<option selected>%s</option> ",$current_row[0]); } else { printf("<option>%s</option> ",$current_row[0]); } } }
Populating A Select Box From A Database
I have a subscription database that allows you to edit a subscribers data. For example, you enter a search term like "Bob" and it returns a list of everyone named Bob. You click the one you want and it goes to a subscriber detail page, where all of his data is populated to a form. You can directly edit this form and click save to overwrite it. The only issue is the select boxes (drop downs) - say I have four options in the drop down box, red, blue, green and black. On my details page for bob I end up with five, I have those four PLUS whatever was saved for his color, so it shows up twice. If Bob is green, my select box looks like: Green Red Blue Green Black How can I make it so that Green only shows up once?
Select One Record From A Database
I am trying to select one record from a database. This databse has like 10 tables. I do not know which table this record is in. What php and mysql syntax would I use to accomplish this?
Randomly Select From Database?
this might seem like a stupid question, i should be able to do this. but on the front page of my site i want a thing to show a few users. but i dont want it to show the same people over and over. i want it to select different people each time. any ideas?
Selective Echoing And Database Select
I have written a search engine for business listings for the company I work for. Each listing is in a database, and that works fine. The problem though is two-fold. The first part of the problem is that not all listings utilise every column of the database, and this leaves gaps when echoing the results. This is not what i had in mind, Any ideas/help would be appreciated. The second part of the problem is related to the first in that there is a link for any listing that has a website, but not every listing has a website, so every listing having a "Visit our Site" link is impractical and shoddy. Also, i'm not sure how to echo the url from the database effectively in the first place.
Editing Mysql Database Row With Select Box
I have a small site, this small site has a few categories, now I can add items through my online admin area fine and delete them fine, but when it comes to editting them I am having some trouble, everything is working fine except the category column, because it is a drop down box I do not know how to have the category selected during the creation progress selected all the other info is loaded.
Multiple Select From Database Where Clause
I have a website with a database full of category names...I want to be able to chose lets say 5 of these categories and use a select from database clause where I could simply enter the category names I want to use but am not sure how I would go about doing it. I can get the list to display just the Aprilia category using the code below: $data1->q("SELECT * FROM categories WHERE cat_name = 'Aprilia' ORDER BY cat_name asc"); However...how could I get my site to display Aprilia, Ducati, Honda, Suzuki, Yamaha?
Using PHP And MYSQL To Select From Database Using Images
I'm trying to update a main page with a list of details matching a selection from a display of images that are displayed in a small window that have been selected from an image group using a select box in the main window, however I don't know how to do this and the main page is not receiving anything when clicking on an image so it's refreshing with empty data. I've seen many many pages giving examples of how to do this with select boxes or how to do this if only one entry uses an image shown in the small window, but the image display window is displaying many different small images not a select box and the database itself has multiple entries that use the same image. Can anyone help? I have a few instant chat programs if someone wishes to discuss this with me in real-time to see what it is I'm trying to achieve.
Tick Box, Select And Update Database.
I am trying to change the value in table with a tick box. If the tick box is selected it changes the value in the field to 'y' and if it is not selected it changes the field to 'n'. First of all I need to bring back the current state of the field and then I need to be able to update it from 'y' to 'n' as many times as I want. Code:
Population Select Menu Using Php And Database Values
I have no idea how to go about this. so i would apreciate some help i want to populate the values in a html select menu from database values in one table so i want all the values from 1 particular field in the database to be displayed in the select menu as separate options.
Displaying A List Of Categories From A Database In A Select Box
Could someone please tell me why this outputs nothing <select name=categories> <? $cat_array = get_categories(); foreach($cat_array as $this_cat) { echo "<option value=""; echo $this_cat["category_id"]; echo """; echo ">"; echo $this_cat["category_name"]; echo " "; } ?> </select> ========================================================== function get_categories() { //get the list of categories from the database $conn = mysql_pconnect("localhost", "user", "pwd"); $query = "select * from categories"; $result = mysql_query($query); if(!$result) return false; $num_cats = mysql_num_rows($result); if($num_cats == 0) return false; $result = db_result_to_array($result); return $result; } //A function that returns a query to the database as an array function db_result_to_array($result) { $res_array = array(); for($count=0; $row=@mysql_fetch_array($result); $count++) $res_array[$count] = $row; return $res_array; }
Select Specific Phrase From MYSQL Database
I am working on a World of Warcraft guild's website and I am trying to create a page where players can select different kinds of gear, i.e. the gear with the most Stamina. All the player's items are stored in the database and every item have a field in the Items-table containing the item's tooltip. This could look something like: Boots of the Nexus Warden Soulbound Feet Cloth 97 Armor +27 Stamina +17 Intellect Durability 35 / 35 Equip: Improves spell hit rating by 18. Equip: Increases damage and healing done by magical spells and effects by up to 21. I then want to select the item with i.e. the most Stamina for all the different slots; Head, Chest, Legs etc. If I write this: $query = mysql_query("SELECT substring(item_tooltip, LOCATE('Stamina', item_tooltip)) AS maxor FROM roster_items WHERE member_id = ེ'") or die(mysql_error()); It returns the following: Stamina +17 Intellect Durability 35 / 35 Equip: Improves spell hit rating by 18. Equip: Increases damage and healing done by magical spells and effects by up to 21. But I want for it to show the leading characters also (in this case "+27 " before "Stamina") and then not show anything else after the phrase "Stamina". So it shows "+27 Stamina" and nothing else for the above mentioned item. How do I accomplish this? And then, secondly how do I then get it to show only the item with the most Stamina after it selected the above? Hope this makes any sense. I've tried to search these forums and found something a little along the lines of my problem but haven't been able to adjust them to my needs and I therefore need your help which will be greatly appreciated.
Simple Filter Of Database With $_GET And Select SQL
I need help with my logic statement with a simple search engine on a MySQL table. I have three form text input fields named f_name, l_name and dept. I am using the GET method to gather data the user enters in each input field. So far I have been able to build a check to see that the submit has been clicked but I am having trouble with assembling the SQL statement because I need for the search engine to be able to filter the results based on the information provided in 1-3 of the fields. I could use if statements with some and clauses but that would mean that I would have to account for each combination. Something like If(($_GET[‘f_name’] != “”) || ($_GET[‘l_name’] !=) || ($_GET[‘dept] !=)){ $sql = "SELECT * FROM facform WHERE f_name LIKE '$_GET[f_name]', l_name LIKE '$_GET[‘l_name]', dept LIKE '$_GET[dept]' ”;} The problem with this is that I would have to get every combination and it’s not very scalable. How can I create this SQL statement dynamically? Code:
Error In Generating Table From Database Select Statment
I am trying to dynamically create a table with the results from a select statement. Below is the code that is not working. Any help would be oh so greatly appreciated. This is for a final at school which is due in an hour. This is the only thing I can't seem to make work. Code:
Select Specific Snippet Of Text, Replace With A Database Result
I'm having some problems trying to do something; I just can't think of a way to do it. Basically, I want to search for a specific snippet of text in a body of text, then replace it with the requested database result with some thrown in HTML. Users will be able to type the following (or something along these lines, depending on what works best): [image=12345]Insert caption here[/image] Then I need it to search for the requested image in the appropriate table and return the image's url (for an example, let's say the table is called "images", and the columns required are "imageid" and "imageurl". Code:
__destruct() Destroy An Object That Contains A Reference To Another Object
i'm using PHP 5.1 I have two objects and the second one is using an instance of the first. As displayed in the example below, the Garbage Collector calls the destruct method of the first class before the second even if the second contains a reference to the other, so i can't complete all the operations not having all "the code available"! Ex.: class MyFirstClass { public function __construct() { ... operations... } public function __destruct() { echo "Destroyed MyFirstClass"; } } class MySecondClass { private $obj = NULL public function __construct($obj) { ... operations... } public function __destruct() { echo "Destroyed MySecondClass"; } } $obj1 = new MyFirstClass(); $obj2 = new MySecondClass($obj1); // Result // Destroyed MyFirstClass // Destroyed MySecondClass
How Do You Sort An Object Array By An Object Property?
array_walk($result, create_function('$a, $b', 'return (strtolower($a->{$section . "_name"}) < strtolower($b->{$section . "_name"}));'), $section); I thought this would sort an object array by the property {$section . "_name"} (the variable $section has multiple values, hence, the object array might be "image_name", "video_name", "audio_name", "anything_name", but it will definitely exist, by whatever name comprises ${section}_name, in the object property within the object that makes up each array element), however, the sorting never takes place. How can I ensure that the object array is always sorted by $obj->{$section . "_name"}?
Common SQL Injection
What are common SQL injection methods that are used? I would like to test my site against them. Login Set Up Email: [input box] Pass: [input box] [submit button]
Web Surveys: Common Practice
I am just wondering, what is the current best common practice for online surveys: 1. allowing users to vote any number of times 2. allowing one vote per IP 3. requiring email address verification (seems overly complex for a survey) 4. setting a cookie on the web browser and allowing no more voting until the user closes the web browser 5, other
Common PHP Files On Different Domains
I have several websites on a remote virtual server. These websites use the same software. I am looking for a way to update all the common files at the same time, rather than uploading the same file via FTP to each domain. I can not INCLUDE() a file from a different domain. Is there a way to use a common source file stored on one domain, to be used on multiple domains?
PHP In Array Issue - Common Words
I have an array $commonwords = array ("and", "he", "I", "in", "is", "it", "of", "that", "the", "to", "was","are", "as", "at", "be", "but", "for", "had", "have", "him","his", "not", "on", "one", "said", "so", "they", "we", "with", "you", "about", "an", "back", "been", "before", "big", "by", "call","came", "can", "come", "could", "did", "do", "down", "first", "from", "get", "go","has", "her", "here", "if", "into", "just", "like", "little", "look", "made", "make","more", "me", "much", "must", "my", "no", "new", "now", "off", "old", "only", "or","our", "other", "out", "over", "right", "she", "see", "some", "their", "them", "then","there", "this", "two", "up", "want", "well", "went", "were", "what", "when", "where","which", "who", "will", "your", "i", "&", "a", "good", "i'm"); Now I am trying to check if a perticuler search word containing any word which is in array.. so avoide them.. example: if(!in_array($space_split['search_word'],$commonwords)) { // some work } this is not giving me right result.. for example.. it is not avoiding some words like "a" "i'm" "&" and few others.. can anyone tell me what is this issue?
Common Login For Diff Modules
I need to make a community site containing blog, forum, shoutbox, gallery, news, event calenders. Any one can give me suggestions like how can i make them accessible with one common login? Is it already handled by joomla or any other cms?
Common MySql Search Algorithms In PHP?
I need to put together a simple search function. I imagine there is already some PHP code out there that handles the basics? For instance, how do I search for just words, from one word boundry to another?
Common Causes For Apache Exiting With SIGSEGV?
I have a website that's built with PHP and MySQL and it works just fine, most of the time. However, when the load gets higher (say 3 hits per second), Apache starts to exit with SIGSEGV on almost every request. Are there any typical areas to look at to solve these kinds of problem?
Sharing Common Files Between Sub-domains
I'm looking for some ideas and best practices for setting up my sub-domains to make sharing/including common files among different sub-domains easy. Specifically, I am looking for a solution that will make it easy to reference common files in the PHP script as well as referencing common images within the HTML. This is particularly a problem when including files in a PHP script that may include other files - can't use relative pathing. For example, let's say I had this folder structure: mydomain.com | |--sub1.mydomain.com | |--sub2.mydomain.com | |--images | |--includes I could create a $prepath varaible with the value ".." for the subdomains and "" for the main domain. Then use that to reference all files from the root of the main domain. Of course I would have to reference any images in the HTML with a full path from the main domain only.
What Might Destroy An Object That Is A Member Of Another Object
At the top of one class I declare a security object: var $securityObject = null; In the constructor, I initialize a bunch of member objects. Because I've had trouble with the security object, I also test to make sure it has been initialized: function IntfCommands() { parent::IntfBasic(); $this->resultsObject->notes("We are now at the beginning of the constructor for IntfCommands."); $this->pageInfoObject = & $this->core->getObject("McPageInfo", " IntfCommands"); $this->selectObject = & $this->core->getObject("ExteriorSelect", "IntfCommands"); $this->arrangementsObject = & $this->core->getObject("McArrangements", "IntfCommands"); $this->validationObject = & $this->core->getObject("ExteriorValidation", "IntfCommands"); $this->userObject = & $this->core->getObject("McUsers", "IntfCommands"); $this->optionsObject = & $this->core->getObject("SingletonOptions", "IntfCommands"); $this->fetchObject = & $this->core->getObject("ExteriorFetch", "IntfCommands"); $this->securityObject = & $this->core->getObject("ExteriorSecurity", "IntfCommands"); $this->outputObject = & $this->core->getObject("ExteriorOutput", "IntfCommands"); $this->fileObject = & $this->core->getObject("ExteriorFile", "IntfCommands"); if (is_object($this->fileObject)) { $this->fileObject->setFileObject("pathAccess"); } else { $this->resultsObject->error("In the constructor of IntfCommands we could not get an instance of ExteriorFile.", "IntfCommands"); }
Common Email Characters Not Accepted By Mysql
I'm making array of characters to replace with temporary proxys (equalsign, singlequote, doublequote, etc.) that will be switched back the original character when a user views his or her emails. For those of you who've done e-mail scripts with mysql before, which characters have proven to be the most trouble (I'm only imagining how many emails one email could hold up if checkmail.php's error array didn't have a certain charactter)?
Failed Opening Required 'common.inc'
I get this fatal error message when i try to include the 'common.inc' file. Could someone explain where common.inc and php.ini should be located and what their contents should be. I am running an apache server and php4. I found 3 different 'common.php' files in different locations within the php directory.
Forum Integrating Into The Common Web-site Interface
I am developing a dynamic site and I'd like to have the communication place for users of my web-site. For this goal I'd like to use phpBB, I like it. But I don't want to open this forum separately in another window or in the same with another design. I'd like to save the common web-site design (navigation menu on the left side of page, header and feuilleton).
Common Prob With Mysql LOAD DATA LOCAL INFILE ...
i have most recent php & mysql versions running on a linuxmachine i want to use LOAD DATA LOCAL INFILE and pass it from php to mysql. - the file i load is given with full path and the directory is readble - On MySQL local-infile = ON - From PHP i connect using client flag (128) to allow passing a file over that connection: mysq_connect( $host, $usr, $pwd, false, 128) Ive followed all advice from php & mysql sites and deja.com ... But i still get the message: The command is not allowed with this MySql Version or something ... any ideas where i should look further? what are *all* the requirements for a LOAD DATA LOCAL INFILE to work seamingly?
Multiple Select From Listbox And Execute A Sql Query Select Statement
Supposing i have a html form with 2 listbox and i name it status and resolution. So it goes <select name='status[]'>... <select name='resolution[]'> Then i have a another php page. $status = $_POST['status']; $resolution = $_POST['resolution']; Now my question is, how do i do the sql query statement? mysql_query("SELECT * from bugs where status=$status and resolution=$resolution"); The problem is, i select 3 options form the status listbox eg. new, closed, duplicate. And from the resolution, i chose fixed, invalid.
Global Object From Object?
I'm trying to set a object as global for access through out the rest of my script ... {a basic SQL accessing object} however if I try calling the object from with in another object it acts as if it isn't global and hasn't been accessed at all ... weather I decalre it from inside the object or declare it outside the object I would rather not have to resort to the standard of refrenceing sence I plan on having modular support and having this one object be a global rathen then everyone refrencing it would just be easyer for people to understandanyways heres some of the code and mind you this is pretty basic so far ---------index.php---------------- <?php include_once("config.php"); include_once("libs/mod.class.php"); include_once("libs/DataBase.class.php"); include_once("libs/main.class.php"); $site= new main(); $site->init(); $site->loop(); $site->close(); ?> --------end------------------------ --------main.class.php----------- <?php global $db; class main { function init () { global $db; $db = new DBAccess($config['database']); } function loop () {} function close () { $db->DBKill(); } } ?> ----end------------------------- ---error------------------------ Fatal error: Call to a member function on a non-object in main.class.php on line 11 -------------end----------------
Php Object To Javascript Object?
Is there a way to convert a Php object to a JavaScript Object onn client side ? I tried using JSON $output = json_encode($Obj); echo $output.""; But I got a slight error, Warning: [json] (json_encode_r) type is unsupported, encoded as null. in whats the best way I should do this ?
Select Statement - Select Random ID #
I have made up a page that pull info on 13 branches of stores onto one main page. It's basically there to display all the branches on one page... then you click on the one you're interested in and then you go to a more detailed page. Back to the main page. On the top, there's kind of a featured branch that has a bigger picture and bigger title but it's still getting pul pulled from the same table etc etc etc. In order for me to avoid favortism to one branch (and for other branches to start complaining) I want to ramdomized the order every time someone came to page but I have no idea how. right now I have a super simple select statement.
Authenticating User Common User Names
I want to create a password protected page with PHP and Mysql. I have 2 groups User and Admin. The respective groups have a common user/password. The user/password are stored in a database. I want to authenticate the user through a login form and not through a pop-up ($PHP_AUTH_USER) way. What I want is, if a user logs in and he moves from one page to another, he should not be asked for validity again. Is this possible only with scripting (without session and $PHP_AUTH...). If yes - how do I keep track of an authorised user and unauthorised user, so that he should not be validated again. Does setting the user variable to global in all the pages do the trick.?
Get Object Value
I have the following class shop and function. makelist makelist() function is going to generate the dummy data for testing. At the end when displaying the id and shopname I only get the shopname for both $shoplist[$i]->getID() and $shoplist[$i]->getName() why is that? Class Shop{ var mID; var mName; function setID( $id ){ $this->$mID=$id; } function getID(){ return $this->$mID; } function setName( $name ){ $this->$mName=$name; } function getName(){ return $this->$mName; } } function makelist( ){ $vector=array(); $aShop = new Shop(); for( $i=0;$i<10;$i++){ $aShop->setID($i); $aShop->setName("shopname".$i); $vector[]=$aShop; } return $vector; } $shoplist = makelist(); for( $j=0;$j<10;$j++){ echo "ID: " . $shoplist[$i]->getID()."Name: ".$shoplist[$i]->getName(); } }
|