Changing Data In Objectified Mysql Records
I am using this very slightly modified function found here:
http://us2.php.net/mysql_fetch_object
to make mySQL rows into objects of type $classname:
// This takes db result rows and makes real objects of $classname type
function &buildObj($result, $classname) {
while($row = mysql_fetch_assoc($result)) {
if ($row === null) return null;
/* Create the object */
$obj =& new $classname;
/* Explode the array and set the objects's instance data */
foreach($row as $key => $value)
{
$obj->{$key} = $value;
}
$objs[] = $obj;
}
return $objs;
}
This is called by a retrieve: function:
function retrieve($where) {
echo $query = "SELECT * FROM $this->table WHERE " . join(' AND ',
$where);
$result = mysql_query($query);
$rows =& buildObj($result, get_class($this));
mysql_free_result($result);
return $rows;
}
The problem I am encountering is that if I do this in my script:
$listing = new Listing;
$listings = $listing->retrieve(array('row > 1') );
foreach ($listing as $aListing) {
$aListing->address='xxxxxxxxxxxxx'
}
foreach ($listing as $aListing) {
print_r($aListing);
}
The value in $aListing->address is unchanged.
However if I do this:
$listing = new Listing;
$listings = $listing->retrieve(array('row > 1') );
foreach ($listing as $aListing) {
$aListing->address='xxxxxxxxxxxxx'
$newArray[] = $aListing;
}
foreach ($newArray as $aListing) {
print_r($aListing);
}
I see the update values in $aListing->address .
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Changing Data Type
I want to change data type of some variable, if it would be C++. following would be the code: int $var; $var=int($str); i have two questions, how to declare $var as int in PHP, secondly how to cast a variable like () in PHP.
Changing Data In Text Files
Is there an easy way in which I can edit values in a text configuration file? I am creating a form based interface to administrate a few text based config files. I can get the values from the file by parsing it line by line, but I cannot find an efficient way to edit data based on changes submitted in the php form. Is there any way to get to a position in a file and then overwrite any information?
Changing Object Data In An Array Of Objects
In this sample script I create an array of objects. Print out their data with print_r().Update their data with a sub called v_set(). Print out data showing the chnages using print_r(). I push the altered objects into a new array and print them out again, still see the updated data. Then I iterate over the original array again with print_r and the objects lose the updates and have their original data. <? for ($i = 0; $i < 1; $i++) { $listingObj = new Listing; $listings[] = $listingObj; } foreach ($listings as $aListing) { echo "<h3>THIS IS IN SCRIPT IN ORIG ARRAY BEFORE VARS SET</h3>"; f_array($aListing); } foreach ($listings as $aListing) { $aListing->v_set( array( 'name' => 'Jane', 'address' => Ïã Ohce Ln.' ) ); // HERE IS BUG: WHY DO I NEED TO PUT IN NEW ARRAY? echo "<h3>THIS IS IN SCRIPT IN ORIG ARRAY AFTER VARS SET</h3>"; f_array($aListing); $newArray[] = $aListing; } foreach ($newArray as $aListing) { echo "<h3>THIS IS IN NEW ARRAY</h3>"; f_array($aListing); } foreach ($listings as $aListing) { echo "<h3>THIS IS IN ORIG ARRAY, APPARENTLY NOT ALTERED/UPDATED?</h3>"; f_array($aListing); } class Listing { var $changedVals = array(); var $name = 'Dick' var $address = ì« Echo Ln.' function v_set($data){ foreach ($data as $key => $value) { $this->$key = $value; $this->changedVals[] = $key; } } } function f_array($array) { echo '<pre>' print_r($array); echo '</pre>' } ?>
Upload In Directory And Records In Data Base
I am needing to configure a code in PHP that makes UPload for serious directory and the register in Data base MySQL. Such as the resource of UPload of images of this GuestBook. In the truth I already obtained some scripts ready in the InterNet, already I obtain to make the UPload of the archives of images for the directory but to record the register in data base it image to appear in the screen tá giving problem... Here it is the register that records in the bank: C:PHPuploadtempphp1281.TMP
Form Scrolling Through Records/adding Removing Data
I can display my data in a HTML but i was wondering how i would display it in a form view. I want the data to be displayed in a text field so that i can scroll through records individually and add and edit data. (Similar to Access) Code:
PHP/MySQL Records Per Row
Is there any way to have the records pulled from a mysql database display like this in a table: record1 | record2 record3 | record4 etc: I've been thinking about this for about three months and have yet to come to a good solution.
Changing A Row In A Mysql Database
I was just wondering, once you have a row in a certain column set....how do you change it with php for example i have a column named "cookie_hash" in my table...when the user logs in i want to update it every time with an md5 hash of their email and login time..I just dont know how to do so I have this part $hash= md5($email.date ("l dS of F Y h:i:s A")); But I just dont know how to do the query.
Changing MySql Database
Is there a way to change a Mysql database so the if the "result" column= win and a link is clicked to change it it automatically changes to lose without the user have to type anything/click anything. (Also vice versa).
How Many Records Can MYSQL 4.1.14 NT Via TCP/IP Can Hold?
how many records can MYSQL 4.1.14 NT via TCP/IP can hold? how many records per table can MYSQL 4.1.14 NT via TCP/IP can hold? how many records in a table can MYSQL 4.1.14 NT via TCP/IP can hold given the table has a field Primary key - BIGINT(20) autoincrement? need your opinion..Here are the facts: MY system is an internal one. My Server--Is only a Desktop.. Celeron 2.8 Gigahertz, 40Gig Baracuda HD, 512 MB memory.. And it serves an average of 20 users a day and it also serves me for my system development..The average records inserted per month on mYSQL is 10,000 records..We foresee that system would be used for about 10 years.
Counting Records In MySQL
I've been trying to write a page that checks the database and counts the number of records and if the number is less than 3000, it loads page X, but if the number is equal to 3000, it loads page Y. I know this should be a simple if/else statement but it's the checking and counting that I cannot get to work.
Changing Localhost IP Address For MySQL
I am moving a bunch of my database sites to a new server. I have to keep the databases hot durring the switch. Is there a way to change the IP address of 'localhost' to another IP address when you connect in PHP to MySQL? That way I wouldn't have to change 'localhost' to the new IP address on every script.
Changing A Mysql Table Name Threw Php?
i have a membership system. one of the feilds in the 'users' table in mysql is called rank. it has 2 posibilities. 1 or 2. 1 means ur a regular member. 2 means your an admin. so in the admin panel, i want to make a part were you can change the rank on a certain user. i was thinking about maybe a html form kinda, where you enter there username, then php searches for it in mysql. when it finds the desired row, it will display there ranking in a dropdown menu. you can change the ranking in this drop-down, and then click submit. then php would change the ranking in mysql.
How Do Iterate Through MySQL Records And Displat Them?
Basically I have a page where a person can choose from a list of stories posted by people, or they can choose to submit their own. I've managed to do the page where they can submit their on. The way i did this was to set up a mySQL database, and table in the database called stories. I then made an id (primary key), author, title, body and date field in the table. When the user submits their story its given an id (which increments on each submition) and their author, title and body fileds are sent to the database. The date key is automatically stamped in. Ive also managed to have the submition page display what they submitted by using the count(*) function, their story would be the last to be submited , so it pulls that from the database and displays it. Now what I want to do - on the page where they can pick a story, is have the page connect to the database and grab each record and display the author and title on the page next to a radio button. And have the id for the story in a hidden field or variable so when the user to chooses a particlar story it uses the id to grab the story from the database. So how do iterate through all the records in the database, and display each one?
Problems Updating Records In MySQL With PHP
Sorry to ask what is probably a simple answer, but I am having problems updating a table/database from a PHP/ PHTML file. I can Read From the Table, I can Insert into Table/Database, But not update. Here is a copy of the script I am using. I do not know what version of MySQL my host is running nor do I have Shell Access to it. I would like to setup a script so my website users can update thier records without my intervention. Also you may send replies to stevennyoung@yahoo.com Begin Script <?php $db = mysql_connect("localhost", "username", "password"); mysql_select_db("databasename",$db); if ($id) { if ($submit) { $sql = "UPDATE tablename SET EMail='$EMail',Username='$Username',Password='$Pas sword',Item= '$Item',Price='$Price',URL='$URL' WHERE Username='$Username'"; $result = mysql_query($sql); echo "table Updated."; } else { // query the DB $sql = "SELECT * FROM tablename WHERE Username='$Username'"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); ?> <form method="post" action="<?php echo $PHP_SELF?>"> e-Mail Address:<input type="Text" name="EMail" value="<?php echo $myrow["EMail"] ?>"><br> Username:<input type="Text" name="Username" value="<?php echo $myrow["Username"] ?>"><br> Password:<input type="Text" name="Password" value="<?php echo $myrow["Password"] ?>"><br> Item:<input type="Text" name="Item" value="<?php echo $myrow["Item"] ?>"><br> Price:<input type="Text" name="Price" value="<?php echo $myrow["Price"] ?>"><br> Item URL:<input type="Text" name="URL" value="<?php echo $myrow["URL"] ?>"><br> <input type="Submit" name="Update" value="Update table"> </form> <?php } } else { // display list of articles $result = mysql_query("SELECT * FROM tablename",$db); while ($myrow = mysql_fetch_array($result)) { printf("<a href="%s?Username=%s">%s %s</a><br> ", $PHP_SELF, $myrow["Username"], $myrow["Item"], $myrow ["URL"]); } } // Close DB Connection mysql_close() ?>
Grabbing Specific MySQL Records
I have set up a target page to pull information out of a mySQL database to populate the page. The problem is that it is only pulling from the first record and not the record specified. What do I have to do to pull from a specific record? I am using Dreamweaver MX to administer the site on WinXP using PHP if that information will help.
PHP Mysql Outputting Records Repeatedly.
I have not messed with php/mysql in a while and have come up with a problem I have run up against before but cannot remember the solution. See the following page:
Very Slow MySQL SELECT Query After 11 Records
I have a very weird problem I moved my database to new IIS 6.0 + PHP 4.3 + MySQL 4.0 setup. I tried to check with myphpadmin if everything works fine, but I couldn't browse my table (125 records). I used SELECT option and found out that SELECT query up to 11 records is ok, but after that, even if I choose to limit query to 12 records, it just hangs. I tried selecting from the beginning of the table and from the middle - same thing, but when I run query localy on mysql console, everything works fine
How Do I Prevent Mysql From Printing Redundant Records?
I have a very urgent question. I am using php and mysql. Say I have a database full of names and email addresses. I want to do a query that when you type in the name or partial name, mysql will only show a name once, even if it is in the database 200 times. Then I want to click on that name and have mysql show the 200 email addresses associated with that name (which I know how to do). See below:
Inserting Master-detail Records In Mysql
how I can insert a master-detail record in mysql? I use an auto-increment key, but I don't know how I can find that key for inserting the detail records, I tried to make a 'highest-key' function with 'select MAX(field)...' but in php it gives the wrong key (in mysql it gives the right one).
Break MySQL Records Into CSS Columns Automatically
I'm making a page of links, each assigned a category. There are two tables - "favourites_links" and "favourites_categories". This is how the links currently appear: Category 1 Name Link 1 Link 2 Link 3 Category 2 Name Link 1 Link 2 Link 3 What I want to do is break my page into columns. Basically, set a number of columns (e.g. 3), count the total records, and work out how many records to show per column. Each column should be enclosed in a <div class="column"> wrapper, which floats to the left. Code:
Having Trouble Looping Through Records In A MySQL Table
I'm having some trouble looping through the records of a MySQL table using PEAR DB. Here is my code: $navigationSql = "SELECT * FROM nav"; $navigation =& $db->query($navigationSql); while ($navigation->fetchInto($nav)){ define("NAVIGATION", "<a href="$nav[2]" target="$nav[3]" title="$nav[1]">$nav[1]</a><br />"); } The when I enter: print NAVIGATION; into any of my PHP scripts it should loop through the stuff in table named nav, but it is only displaying the first record and so far everything I've tried does not seem to make it loop through all of the records in the table and I can't figure out why not.
Displaying Priorty Records And Normal Records In The One Dataset.
I have a page which displays the records from the database and uses paging to display the records in groupes of 10 per page. I now want to be able to show results depending on the database field (display) in the database (can be set to either "full" or "limited"). If the record and the field display is equal to "full" i want to then display this record at the top of the record set and display all the fields. If the record is equal to "limited" i want to display different results and they must show after all the records which are equal to "full". I can't output two different recordsets as i use paging and only want to show 10 records per page. Code:
How To Control Access To Specific Mysql Records For A User
I am just trying out a php form, when posted submits data to database. The system is we allow everyone to submit the form. As administrator I can view and edit the records. But whoever submits the form should be a registered user and he should be able to only view his records but not edit.
Can I Convert MySQL Db Records Into Microsoft Word Documents?
i found the solution to export file from mysql db into *.csv. but is there anyway to convert the contents into *.doc and save in my webserver and providing a link for the end users to download the word file? FYI, the database records are obtained by end users submitting the forms themselve and i saved it in my db...
MySQL Inserting Into Multiple Tables Linked Records
Using MySQL can anyone tell me how to most efficiently insert a collumn in 'table1' retrieve the id from this record and insert mutliple records into 'table2' with a collumn for the id in 'table1' which links the two recordsets
How To Access And Modify And Add Records In MySQL Table From A Windows Client?
The MySQL table is located in a Linux Server OS, so I need the information from that table for updating Paradox tables in Windows OS. If a PHP program in the Linux Server can save a file with the information I need, can I make a PHP program in Windows OS to get the saved file or even better, to access the table in the Linus Server OS?...
Count,sort,diplay Number Of Records In MySQL Table
I am designing a search engine using PHP/MySQL and I am logging all search terms into a MySQL table. I was wondering how I count the number of occurences of a term in the table, and then sort and display the terms in descending order. For example, if the column in my table with search terms looked something like this: clothes casinos clothes homes homes clothes How can I count and order the records so that I can display according to how many times they appear, like so: 1. clothes(3 entries) 2. home(2 entries) 3. casinos (1 entry)
Need To Update Multiple Mysql Records With A Single Form Submit
I have a wish list like a shoping caty based on a mysql databse where i retrieve records with php I need to update the quantity which is in a text fields : input type = text name = quantity[] value = $quantity input type = checkbor value = $id name = id[] I need to update quantities based on the primary id represented with id with a single submit.
Comparing Form Data To Mysql Data
Im interested in building a script that would take form data, a variable like an address, and compare it with a known address in a mysql table (called addresses), then if there is a match log the address information in a separate table called (addresslog), and return the visitor to a certain page. If there is no match between the address entered in the form and known addresses then the information is still logged into the addresslog database but the visitor will be sent to a different page. I'm still new to this, and am working through the logic and the syntax, but I believe I'm close. It's still not working, I have all of the proper tables, maybe I'm way off with the coding so I thought I would seek out some expert advice. Here's the entire script with as much explanation as I could give. PHP Code:
Reading An Array Of Records From MYSQL Then "Save As" Them Back As Copy
Hi all, Ok here is what I want to do then I will show you what I have. I have some records in a MySQL DB that I want to store in an array and then immediately copy them back where the only thing that would change would be one field - the date. So here is my table: ------------------------------------- |userName | date | value | -------------------------------------- | theDano | 200005 | 123 | -------------------------------------- | theDano | 200005 | 345 | -------------------------------------- | theDano | 200004 | 678 | -------------------------------------- | joeUser | 199908 | 897 | --------------------------------------- So if I am querying for the user "theDano" on a specific date (format yyyymm) in this case 200005 (year 2000 month of May) Here is my array to query all records to fullfill this request: if ($update=="future") { if ($month!="01") { $db = mysql_connect("localhost", "dbuser"); if($db) { mysql_select_db("dbName",$db); $result = mysql_query("SELECT * FROM tableName WHERE userName = '$userName' AND date = '$date' ORDER BY value DESC ",$db); if ($result) { $num=mysql_numrows($result); $i=0; while($i < $num) { $userName = mysql_result($result,$i,"userName"); $value = mysql_result($result,$i,"value"); echo "<tr>"; echo "<td width=Ê×'>" . $userName . "</td>"; echo "<td width=ï`'><div align='right'>" . $value . "</div></td>"; echo "</tr>"; ++$i; } } } } } Now I want to take the array of records queried which was: | theDano | 200005 | 123 | -------------------------------------- | theDano | 200005 | 345 | and copy them to look like this back into the database: | theDano | 200006 | 123 | -------------------------------------- | theDano | 200006 | 345 | so you can see that the only thing changed was increasing the month by one. Would seem simple to most but I am having a tough time wirting the code to read the array and increase each date value by "1". Thank you in advance for anyone that replies. ) Dano
Get Mysql Data
I have a database, and what I want is for people to be able to put in a number from the database and it pull up their info and put into a form, so then they can just add to what they already had.
Data And Mysql
I want column XY be unique so: xy | gg | zz | ee 12 | df | df | fd 13 | df | df | fd I want to enter more data but it might enter 12 | df | df | fd again so i would get an error. How would i prevent that without having to loop threw the whole database checking for that entry?
Getting Data With MYSQL
IM interested in knowing of any better ways of retreiving data from mysql and if my current way is safe as i request it over all my scripts. $information = mysql_fetch_row(mysql_query("SELECT `row` FROM `table` WHERE `username` = 'Memphis'")); print("$information[0]");
Getting Data From Mysql To Put Into Form
i am trying to set up a page that will allow the user to select a name from a list. The details of this name(ie, last name,address, job etc) are then taken from a database and put into a form. If any changes are needed the user makes them then presses a submit to update the database. I can get the information out of the database and into the form fields but i have one small problem... In the address field i can only get the first part of the address... ie if the address is 123 Sample Street only 123 gets put into the form field. How do i get the rest of the address to appear? i am sure it is quite simple but cant quite put my finger on the answer! my code is: Address: <input type="Text" name="address" value =<?php echo $myrow["address"] ?>><br> where $myrow is the array holding the results from my database query. Any help would be appreciated!
Importing Data Into Mysql
I'm starting working on a new project where I'll have to allow users to upload and import tab-formatted text files into the db. Should I use the LOAD DATA INFILE from PHP or write a custom procedure?
Problems Getting Data From Mysql
I've written a scipt for breaking articles into several pages and it seem to be working fine but I can't get them from the database. PHP Code:
Mysql Data Doubled
I'm facing a problem with mysql and don't know what is the problem as I still learn php/mysql. I use a simple script to upload some images and a file. Everything runs very well untill I choose a name for a file that is allready in the database, the new data just overwrite the old one which gives me allmost two identical results in the db, allmost because only the path to the uploaded images are changed, the comments, name, creation data stay different. Here is my db:
Fragment Data In Mysql
i just wondering if there is update and delete,indert query activity in database.Which make it slow, how do we know if this thing happened and how to solve it?
Php, MySQL, And Binary Data
I'm trying to upload binary data and store it in mySQL as a mediumblob. Since there's always the possibility of quotes (along with any other character) within the binary stream, I assume I need to do something along the lines of AddSlashes to ensure that the sql request won't fail. The trouble is I'm finding that StripSlashes is blowing away the string when I retrieve it. I've tried rolling my own encoding, but ereg_replace("'", "'", $string) is truncating my data, apparantly at the first null character it hits. So: what's a solution for safely getting binary data into mysql via php?
Load Data Into MySQL
I have a table in which its primary key is auto-incremented. Yet, when I try to load data using load data infile, this column will not auto-increment. I am leaving that column blank in my file to be uploaded, yet it fills this value in with a zero for all records. Should I be using a php script to load this file? Why isnt this updating correctly?
How To Get The Data From MySQL Into A PHP Template
I am creating a template page that will have the same subsections on each page. Each subsection is supposed to get information from a MySQL database. The subsections are: Location, Host, Cost, Travel, Age Restrictions, Work Project, Ministry Description. The variables are $locationID (primary key),$location, $host, $cost, $travel, $agerestrictions, $project, $ministry. Now. My question is so simple. How do I get information from the database to the template based on the link (location) that the user chooses. I'm sure an "mysql_connect();" is involved, but I'm not sure how to pass the selection to the database and get the information back that I need to plug into the template.
Pull Data Out Off Mysql
I am making a database using mysql where i have 2 tables, one for car manufacturers and one for car models.I've already done that. I have made a php page where i have 2 drop down menus. The first menu shows car makers(manufacturers) and the 2nd nothing. Now when a user opens the 1st menu and selects a maker , the 2nd automatically fills up with models from that car maker only and it gets its information from the database.That is every time i decide to add a new model to my database the 2nd menu (if selected) must go and search the database for all the models for that maker and show them. Code:
PHP/MySQL Moving Row Data Help!
I have a table with about 600 rows of data in it. I'm trying to figure out how to move row 600 up to row 300. But I can't seem to figure out how.
Getting Data From A Specific Row With Mysql
I'm makin a member's area on my site with sessions, as they log in correctly the username is stored as $_SESSION['user'] what I can't work out, is how to access my table and extract data from just the row that has that username, eg SELECT * FROM table WHERE username=$_SESSION['user'] as I'm trying to make the users be able to edit profile, upload pics etc... any idea what I'm doing wrong?
Data Not Being Retrieved From Mysql
i'm workin on an app that will allow a client to update news items themselves without needing to ftp or know sql. Just in the process of setting it all up, i've got a page that retrieves the title of the news item(referred to as a slug in this context), the date it was last updated and an id for the item. the title itself becomes a link to a page that contains the full content of the item by appending the id to the url and calling that id from the database. The first page (news.php) works fine, it retrieves what it needs to and sends the user to the next page (story.php) when they click the link. However, for some reason the exception ("That press release could not be located in our database") is being displayed each time and not the content of the news story. i'm stumpted as to why this is the case as the fact that news.php is working shows there is data in there and that my connection script (db.php) is working. PHP Code:
|