Updating Rows While Fetching?
I'm trying to be able to do somthing here, my problem is figuring out a way to check through every row in a table, and write the timestamp date value that results in my set of if statements in a specific field of the row that I'm checking. Here's the code that I've written so far, and it's not working... Any suggestions?
<?php
$db->query("SELECT * FROM gtraining WHERE start_date<NOW() AND end_date>NOW()");
while($db->fetch()) {
$thisid = $db->row['id'];
if ($db->row['date1'] > date('YmHis')) {
$nextdate = $db->row['date1'];
} else if ($db->row['date2'] > date('YmHis')) {
$nextdate = $db->row['date2'];
} else if ($db->row['date3'] > date('YmHis')) {
$nextdate = $db->row['date3'];
} else if ($db->row['date4'] > date('YmHis')) {
$nextdate = $db->row['date4'];
}
$query = "UPDATE gtraining SET next_date='$nextdate' WHERE id=$thisid";
}
?>
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Fetching Non-existent Rows
I've got a table "banneractivity", which stores clicks and views of banners on my website. The table contains the following fields: id INT activitydate DATE activitytime TIME action (either "click" or "view") bannerid INT I want to retrieve the activity by the hour, to show in some statistics. I've used the following query thus far: SELECT id, COUNT('action') AS actionsum, HOUR(activitytime) as theHour FROM banneractivity GROUP BY theHour This works reasonably well, but I would like to retrieve 24 rows, for every hour of the day, even if there has been no activity in a particular hour. Is this possible? Another thing I would like; is there a way to distinguish between "click" and "view" and therefore select two different sums from the database?
Updating Rows
I have a table say like this: t1 v1 AUTO_INCREMENT v2 char(40) v3 int (its empty, need this in here!) and say I have a CSV file with the values that I want to add, not in the same order as the values in the table, but the first column contains the index, v1. 1, "1234", 5 So is it possible to import like this? or would it be better to dump the whole table into a CSV file, add the data I need to and reload it in?On that subject, if you set a value of the auto_increment column when using LOAD DATA INFILE, will it set it providing that the value does not exist twice as requsted? or will it ignore it and auto_increment one up? because i need all the numbers to remain the same as they are linked into other tables from this index value!
Updating Rows
I have a table like this: id name -- ----- 1 red 2 green 1 blue 3 yellow 4 black I want to update the id's to 5 for names = red,green,black How can i achieve this in one query?
Updating Rows
I am trying to update a table with content from a different table. specifically, I am trying to add city and province info to rows which already have name and email info. if I run this query INSERT IGNORE INTO `jos_acajoom_subscribers` ( `city`, `province`) (SELECT city,province FROM jos_fabrik_formdata_1 ) it adds new rows for contacts not already in the table, BUT it does not update existing rows.
Updating Multiple Rows
The following UPDATE query works fine if run directly into phpMyAdmin (I take the $sql output of the script with the data in it and paste it into phpMyAdmin). But it doesn't update my records if run from the PHP script. I can't seem to figure out where the bug is: Code:
Updating Multiple Rows
I need to update multipule rows a once, using PHP. Here's what I mean. I have a mysql query out put the data as a form like this: Item 1 <input type="hidden" name="id" value="1"> <input type="text" name="order" value=""> Item 2 <input type="hidden" name="id" value="3"> <input type="text" name="order" value=""> Item 3 <input type="hidden" name="id" value="4"> <input type="text" name="order" value=""> <input type="submit"> Order need to be updated. I could setup to do a loop with multiple queries.
Updating Rows Problems
im doing a program in visual basic 6 with mysql as database, in some part of my program i edit some fields but when im try to update an error shows, it says: "Runtime error: -2147467259(80004005) Key column information wrong, Too many lines affected in update" i dont know why, when filter i only have one row, i see it with the recordcount command, here its the code: 'Conn its a conection that i made rsPartidasOC.Open "SELECT entregado, restante FROM mifpartidasoc" & _ "WHERE apunta = " & txtNOC.Text & " AND codigo = '" & strCodigo & "'", Conn, adOpenDynamic, adLockOptimistic ntmp = rsPartidasOC.RecordCount ' here recordcount its 1, only one row rsPartidasOC![entregado] = ValLlegadoTemp rsPartidasOC![Restante] = ValRestanteTemp rsPartidasOC.Update 'the error comes here rsPartidasOC.Close **VALUES** txtNOC.Text = "2" strCodigo = "ART1" table mifpartidasoc: id apunta codigo llegado restante 19 1 ART1 100 1000 20 1 ART2 10 900 21 2 ART1 200 1500 22 2 ART2 150 20
Updating Multiple Rows
I am running the following UPDATE statement UPDATE history set t_own = t_user * 0.75 where user_cur = 7 and lg = 'Local' t_own and t_user are defined as DECIMAL 12,2 650 rows should be updated, but i get error 1136 Column count doesn't match value count at row 1.
Updating Multiple Rows.
I went to MySQL home page and found one comment that kind of tried to explain it but it was written in such a manner that I could make no sense of it at all. I am trying to find a way to update a row with 12 entries in a table that has 12 teams (teamid) and 12 ranks (r1,r2,r3...r12) the data to update the teamid comes from a form and they would all be updated (unless everything remains the same) with the use of the said form. I am not certain how to make this work (call the table 'team') PHP Code: UPDATE team SET teamid='team1', teamid='team2'...teamid='team12' WHERE?
Updating Multiple Rows In One Query
tried to find the answer with search but didn't return any answers. OK, here is the table table test ------------------------ | test_id | test_order | ------------------------ | 1 | 1 | ------------------------ | 2 | 2 | ------------------------ | 3 | 3 | ------------------------ I'm trying to change the orders in one query, but not sure how to do that. phpMyAdmin shows me the code like this Quote: $sql = 'UPDATE `test` SET `test_order` = ƈ' WHERE `test_id` = 1;' 'UPDATE `test` SET `test_order` = Ɖ' WHERE `test_id` = 2;' 'UPDATE `test` SET `test_order` = Ƈ' WHERE `test_id` = 3;' . ' ' I'v tried that but got a syntax error. MySQL version is 4.0.26, can anyone help please?
Updating Exisiting Rows From A File
There's probably a very simple answer to this, but I can't find it anywhere.... I have a pricelist table with three fields product_id product_description product_purchase_count product_price I have 150 rows (ie products) in my pricelist. How can I update the pricing only (product_price) when the I have a text file (CSV) with product_id and product_price colums? I have used LOAD DATA INFILE to populate the table, but now I'd liek to do an update.
Updating Multiple Rows With Same Fields (in One Query?)
I have 2 tables here table categories +--------------------------------------- + | cat_id | cat_name | cat_total_articles | +----------------------------------------+ | 1 | PHP | 23 | +----------------------------------------+ | 2 | MySQL | 17 | +----------------------------------------+ table articles +---------------------------- + | article_id | article_cat_id | +-----------------------------+ | 1 | 1 | +-----------------------------+ | 2 | 2 | +-----------------------------+ Now I've changed an article's category from cat1 to cat2, and I need to update cat_total_articles of both cat1 (minus 1) and cat2 (plus 1) in category table. Is it possible to combine the following queries into one statement? PHP mysql_query("UPDATE categories SET cat_total_articles = cat_total_articles + 1 WHERE cat_id = 2"); PHP mysql_query("UPDATE categories SET cat_total_articles = cat_total_articles - 1 WHERE cat_id = 1");
Help With Updating Duplicate Rows In Mysql Query.
Quote: SELECT id, count(*) AS numlist FROM products GROUP BY category, name, brands HAVING numlist > 1 ORDER BY id ASC What it does is find the duplicates. I also have a column called "app" which has a default set to "1". So now what I want to do is that when duplicates are found, I want the first duplicate row in each group to stay as a "1" and the others in the same group to be updated to a "2". I need this done for every group. How can I do this. I have looked high and low accrossed the web, but can't seem to find any solution. I have managed to find out how to group them and count the number of listings in each group, but I can't seem to figure out how to do the rest. Also, if possible, I would like it to be done with one query.
Updating Rows In Table B Based On Related Field In Table A
Ver 4.1.8-standard for apple-darwin7.6.0 on powerpc (Official MySQL-standard binary) I am trying to do some data migration based. I have several tables that contain our legacy pkey field and I want to update the tables with new ID's. I need to do this several times and have tried it several ways to no avail. Table A --------- companyID int(10) pKey legacyID int(10) old legacy pkey Table B --------- bAID int(10) pkey companyID int(10) legacyID int(10) Table A has values for both companyID (unique key) and legacyID. Table B has values for bAID (unique key) and legacyID but companyID is empty. I need to update tableB.companyID with tableA.companyID based on tableb.cSerialID to tablea.cSerialID relationship. I need a query that will update ALL rows.
Fetching One Field
let's say i have a table in my database, with only one column. all i want to do is retrieve a list of the entries.. i could do it like this $result = mysql_query("SELECT * FROM t1"); while( $x = mysql_fetch_row($result) ) { echo $x[0]; } but it seems kinda silly to fetch an entire array, when only the first index is used. is there a better/more efficient way?
Numbering And Fetching
Well I thought I read somewhere it was possible to fetch a row, and get the number of something in one query.For instance I have a member table, and it has a column for userid, I would like to number the amount of posts they have made in the newspost column, which is identified by posterid. So "SELECT members.userid FROM members WHERE num(members.userid=newspost.posterid) AS newscount" Something like that... is it possible to do in 1 query? I know theres some num function that can be used inside the query...
Fetching Information
an example: $dbl->query($query); $res = $dbl->get_result(); how do i pull information from a row in $res without automatically moving the pointer ahead.with: $myrow = $res->fetch_array() i pull the correct information but i don't want the pointer to move ahead in $res.
Fetching The POSITION Of A Record
I have this script which allows for users to add other users to be apart of a favorites list. The script works, but when I a user adds another user, I don't know the exact position it ends up in within the records. When a user adds another user as his or her favorite list, the page redirects to the users' favorite list which contains the updated favorite records (the new user has been put in). The results are split up by 20s in their pages. So 50 = 20 + 20 + 10 = 3 pages. Obviously this depends on the ordering of the records. But if I only allow for ordering by user_id, then is there a way to find the position of newly added record? So my query looks like this: SELECT f.user_id,username FROM favorites f INNER JOIN users u USING(user_id) WHERE f.owner_id=[USER_ID of the user who owns the favorite list] ORDER BY user_id LIMIT 20; Then the LIMIT is changed according to what page it's on. But when the new user is added, the user_id can be anywhere in between the other favorite records. It can be on page 1,2,3,etc... So what I want to happen is that when the user adds someone else, I want the script to find the position of where exactly the record has been added. PHP $pos_sql = mysql_query('SELECT...POSITION OF USER_ID WHERE THE OWNER_ID OF THE FAVORITE LIST IS THIS'); //Finds the record number position of the newly added user$pos_row = mysql_fetch_row($pos_sql);$pos = $pos_row[0];$limit = 20; //20 results per page//The page is now found$page = ceil($pos/$limit);//now select the 20 records from the page where the newly added favorite record consists. The favorites table only contains two columns: owner_id and user_id. I don't want to add anything new, such as a date column, because I don't really need it. One other solution would be to simply fetch every record from the table which are linked to the owner and order by user_id and make a loop that increments a php variable to see where the position on the newly added favorite is.
Database Fetching Gives Warning
I am using the following code to extract info from db and display it. The extracted info is basically a link to a stored image. I get the following warning after $sql data is printed as shown SELECT * FROM reflections WHERE `trusted` = 1 AND `catid` = 1 ORDER BY `id` ASC LIMIT 8, 1 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mysite/public_html/addons/class.upload/pages.php on line 66 PHP $sql = "SELECT * FROM reflections WHERE `trusted` = 1 AND `catid` = 1 ORDER BY `id` ASC LIMIT $from, $max_results"; mysql_query($sql); echo $sql; while($row = mysql_fetch_array($sql)) { if(strlen(isset($_GET['tcheck']))>0 && $_GET['tcheck']==$safeurl->make_safe_url($row['title'])){ $tcheck=trim(mysql_real_escape_string($_GET['tcheck'])); }else{ echo "invalid query"; exit;} echo "<!--start-->"; echo "<font size=3><b>"; echo $row['title']."</b><br /></font>"; echo "<font size=2>"; echo "Added On "; echo date("jS F Y H:i:s", $row['date'])."<p>"; echo '<img src="/addons/class.upload/test/'.$name.'" border="0" height="50%" width="50%" alt="' . $row['title'] .'" />' echo "<!--end-->"; }
Query Fetching Average
I have 2 tables in a database. One table consists of persons. Each person appears only once in the table.....
Fetching And Posting Info
I am having some issues using the mysql_numrows function and I am getting this error Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource I have also tried mysql_fetch_row and some otehr functions but get this warning pertaining to it. Is this a server problem? Does my server not hold these resources. It is PHP enabled, and MYSQL.
Fetching Text From Phrase
i can fetch tousearray content from following table using following query PHP Code: SELECT `title` , `message` , `touserarray` FROM `pmtext` WHERE `fromusername` = 'zodehala' ; but how can i fetch only joe word from tousearray column ?
Fetching Auto-increment
I am writing to a table with a cell that is at auto-increment and need the auto-incremented value as feedback from the writing to the table process. e.g. table abc field a (= auto increment) field b field c my SQL query INSERT INTO table_abc (b,c) VALUES ('5','9') Now the value in cell a would be at auto-increment but I would need to know which value it would have been set when I inserted the values above for b and c
Fetching Highest Column Value, From A Table...
To simplify things, lets say l've got a table, with three columns... an auto-increment ID, the user's name, and their age (which is an integer). lets say my column has five rows: TABLE NAME: my_users column 1 | column 2 | column 3 [ID] [NAME] [AGE] ------------------------------ 0 | Bill | 23 1 | Bob | 18 2 | Eric | 37 3 | Steve | 58 4 | Frank | 19 ------------------------------- Now, lets say l wanted to tell the user who the oldest user in table was, with something like: Hello, our oldest user is $oldest_age and our youngest user is $youngest_age $sql = 'SELECT age FROM `my_users` WHERE ... ???? obviously Steve is the oldest as he's 58, and Bob is the youngest at 18... However l was wondering what the most efficient way to select this data quickly from the database would be? Though this example is small, l've got 10,000 rows in the actual application l working with here, so a while loop won't really cut it
Fetching MySQL Stored Procedure
Can anyone confirm it's not yet possible to retrieve the result set from a stored procedure in MySQL5? I found some posts regarding this issue but no answers yet. I'd like to keep data-model specific stuff out of my Perl DBI code...
Noob Issue With Cursor, Only Fetching 1 Row Of Data ;)
I have recently started using stored procedures in our application, and today, I have tried to create a cursor to fetch me some data, but for some reason it only fetches 1 row of data. Its a really simple cursor (and procedure) at the moment, so im really stumpped. DELIMITER $$ DROP PROCEDURE IF EXISTS `test`.`task_get_task_list` $$ CREATE PROCEDURE `test`.`task_get_task_list` () BEGIN DECLARE field_value VARCHAR(20); DECLARE value_value VARCHAR(255); DECLARE task_user_filter_cursor CURSOR FOR SELECT field , value FROM task_user_filter_settings; OPEN task_user_filter_cursor; REPEAT FETCH task_user_filter_cursor INTO field_value , value_value; IF NOT done THEN SELECT field_value , value_value; END IF; UNTIL done END REPEAT; CLOSE task_user_filter_cursor; END $$ DELIMITER ; The table looks like this (well here are some SQL statments to create the table and add some dummy data) CREATE TABLE `task_user_filter_settings` ( `task_user_filter_settings_id` int(10) unsigned NOT NULL auto_increment, `task_user_id` int(10) unsigned NOT NULL, `field` enum('pro','sub_pro','prior','cat','dead','status','assig_user','assig_group','dep') collate latin1_general_ci default 'assig_user', `value` varchar(255) collate latin1_general_ci default NULL, PRIMARY KEY (`task_user_filter_settings_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=4 ; INSERT INTO `task_user_filter_settings` VALUES (1, 1, 'assig_user', Ƈ'); INSERT INTO `task_user_filter_settings` VALUES (2, 2, 'cat', Ɖ'); INSERT INTO `task_user_filter_settings` VALUES (3, 1, 'prior', Ƌ');
Error While Fetching Schema Table Status
I've recently installed MySql 5.0.2 on a WinXp box and am always getting the above error every time I click on a schema in the Catalog. I can log on to the db fine, it always happens when I click on a schema.
Help Needed Fetching Data From Table (string Matching)
I have a table "officers" table two with 4 fields all with variable char which will end up just being names. However, I need to create a report that counts each the occurance of each name and ouputs the name with the count next to it. The names in table "officers" are concatinated from a first name field and last name field in a separate table "persons"; I need some help figuring out how to write this using PHP.
Searching For Rows That Depend On Other Rows In Some Fashion...
Maybe this is a very stupid question. I'll try anayway. I'm using MySQL 3.23.52 on RedHat 8.0. I have a very big table (several millions of rows). Each entry actually constitute a word in a big text. Among other fields we have an ID for each word which represents the postition in the text. Now I want to search for short phrases. For example "welcome to sweden". This means i want to find all occurences of the word "welcome" with ID x, where we have the word "to" with ID x+1 and the word "sweden" with ID x+2. I've tried doing this recursively with temporary tables - but a find myself hitting a wall as i'm not allowed to refer to 2 different temporary tables in the same query... Resorting to another type of data strucutre, full text index etc.. is unfortunately not an option. We only need this as an add on feature if we can do it. We believe that indexes, data structures etc.. are near optimal as is. Please use my email for further conversion since I'm not a frequent usenet reader.
Zero Rows Or One Rows Returned, Same Data And Same Query
I have a query that produces a single row (as I expect) when I run it from the mysql client (mysql 4.0.18-Max/linux, also 5.0.19-standard/OSX-intel), or from sqlgrinder (osx, uses jdbc). When I run it inside my application (a Java app connecting via jdbc), I get zero rows from this query. I tried it under phpmyadmin, and once again I get zero rows. Why do I get inconsistent results? Here's the query:
Insert New Rows With Qty Values From Existing Rows
I am trying to make all my products unique in my db. Lets say I have a row with an id, it also has all relevant details about the product and it has a quantity value of 4. What I would like to do is take the entire row and duplicate it by the number of the quantity field. This would result in the same product 4 times instead of one product with qty of 4. Reason, I am going to serialise all the products so that they each have unique barcode from the id field. I will encounter the reverse issue when running an insert statement for inputting new data, i.e. insert a new row for each item depending on its qty value??
Searching For Rows That Depend On Other Rows In Some Fashion...
Maybe this is a very stupid question. I'll try anayway. I'm using MySQL 3.23.52 on RedHat 8.0. I have a very big table (several millions of rows). Each entry actually constitute a word in a big text. Among other fields we have an ID for each word which represents the postition in the text. Now I want to search for short phrases. For example "welcome to sweden". This means i want to find all occurences of the word "welcome" with ID x, where we have the word "to" with ID x+1 and the word "sweden" with ID x+2. I've tried doing this recursively with temporary tables - but a find myself hitting a wall as i'm not allowed to refer to 2 different temporary tables in the same query... Resorting to another type of data strucutre, full text index etc.. is unfortunately not an option. We only need this as an add on feature if we can do it. We believe that indexes, data structures etc.. are near optimal as is.
Updating From 4.0 To 4.1
My web host will update the server to MySQL 4.1 this week. What's the difference? Should I look for something special in my code that might not work after that? They will probably update to ver 5 later as well. But not yet.
Updating
If I have a bunch of cells that say: ,4, and i want to update them with another number (5, and 6, -> $var) so that I would get results like ,4,5, and ,4,6, how would I go about updating that? I notice, if I defined $var, and just use a normal update command, it just replaces it, but I want to keep the 4 in there (not necessarily always 4, but this is an example, as that too is a different number each time). I tried using variables as well, but if I did anything within the while method, I couldn't bring it to the query. Any suggestions?
Updating A Row ....
I have an application for employee punch in/out. My table structure is, ID,Date,Employee Name,In-time,Out-time. Now when on the first punch in of the day, it will add a new record for that employee for that date only in in-time field. Next time, when same employee punches out, it should update the same existing record and put time value in out-time field. Next time when again, same employee tries to punch in, a new record gets added with value in only in-time field and so on.. Now, a totally weird thing happens. Whenever employee tries to punch out (so there is a value in in-time field), it updates that record as well as it adds a new record with same out-time value in in-time field. So in nutshell, it updates the existing record and adds a new record. I checked my script 50 times and put debugging code, but i don't find any errors.
Updating In SQL
UPDATE phpbb_auth_access SET auth_cal = auth_sticky; UPDATE phpbb_forums SET auth_cal = auth_sticky; How do I do this in MySQL?
Updating
Is it possible to do an update with load data infile? We need to load a load of csv files into our database but the tables have additional fields over the ones in the csv files that we need to preserve as they contain the margins and profits for each item.
Updating
like...is it supposed to make only sense if you update the content of your database NOT via a standard rdbms ?and second...do i have to worry about what i ask mysql cause it is so slow?like...i have a query of 17 lines...does it matter at all? and better ask 2 small queries or 1 large?
Can Updating
###### I am trying to update data in a vehicle_fuel column where the conditions match up to the costpergallon column. I need to know if I am doing this right and if this is possible, because at the moment it is not working for me. sql = "UPDATE vehicle_fuel,costpergallon SET vehicle_fuel.fuel_value=costpergallon.costper WHERE vehicle_fuel.fuel_value='0' AND vehicle_fuel.fuel_type_pumped=costpergallon.cost_type"; #### There should be about four different match ups with four different data values and I need it to loop through the entire table and update the data in the different rows.
Updating A Single Value In A Row
So i have a table with the following columns: id fname lname occupation photo (holds the path to the photo) and at some point I want to delete the path of the photo (i need it empty and not null) UPDATE db.table SET table.photo=' ' WHERE id=$id but this will delete ALL of my values along with the photo path except id!?
Updating To Mysql 5.1
trying to update to mysql 5.1 on mac os x 10.4.3 without much success. I've reinstalled mysql 5.1 and now in terminal when I try to start it with: sudo ./bin/mysqld_safe & /usr/local/mysql/bin/mysql test I get this error message 2002, server not running (http://dev.mysql.com/doc/refman/5.1/...-server.html): [1] 1342 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 127:/usr/local/mysql garrett$ 070913 11:56:08 mysqld_safe Logging to '/usr/local/mysql/data/127.0.0.1.err'. ./bin/mysqld_safe: line 366: [: -eq: unary operator expected 070913 11:56:08 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data 070913 11:56:11 mysqld_safe mysqld from pid file /usr/local/mysql/data/127.0.0.1.pid ended so I have checked the error report as it says to do here (http://dev.mysql.com/doc/refman/5.1/...-server.html): 070913 11:58:17 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/mysql/data/ is case insensitive /usr/local/mysql/bin/mysqld: Unknown error 1146 070913 11:58:17 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it. 070913 11:58:17 InnoDB: Started; log sequence number 0 46409 070913 11:58:17 [ERROR] Aborting 070913 11:58:17 InnoDB: Starting shutdown... 070913 11:58:19 InnoDB: Shutdown completed; log sequence number 0 46409 070913 11:58:19 [Note] 070913 11:58:19 mysqld_safe mysqld from pid file /usr/local/mysql/data/127.0.0.1.pid ended what is the mysql_upgrade? where is it and how do I run it? any help much appreciated. This (http://search.dbanotes.net/doc/mysql...#mysql-upgrade) is a little enlightening but apparently I need to have the server running to execute something that is stopping the server from running - argggg!!!
Updating Most Recent/last Row
This is for a directory and the table Dir holds the selected plan of each member. The table contains a history of the plans (inserted on each selection) so what I need to do is update the last row of Dir.DirID. Every time 'Posting' value is echoed on the page with query 'Listings' (two seperate tables from Dir - one for runtime and one for the actual postings (a foreign/primary key) - then Dir.Dview is incremented as a basic hit counter with the query Listings higher on the page. What is the most reliable way of updating the last row of Dir.DView where DirID is primary? note: query 'Listings' uses SELECT max But experimenting with this before, I hessitate to use SELECT max for an update. <?php echo ($row_Listings['Posting']); $query_updateSQL = sprintf ("UPDATE Dir SET Dir.DView = (Dir.DView+1) WHERE DirID = %s", $colname_Listings); $result = mysql_query($query_updateSQL); ?>
Updating A Specific Row
I have a question about updating a row in a table. This table keeps a record of when a user logs in/out with username, time of login/logout and ip-adress. When a user logs in, the logouttime is of course left blank. When that user logs out I need to update that row with the logout time. I know I need to use "UPDATE log SET timeLoggedOut = '$timeLoggedOut'" I have a session variable with the identity of the user currently logged in. But how do I update only the last row in the table containing the username of the user logging out? If I only use WHERE username='$userloggedin' it will update every row containing that username..... EDIT: I guess I could use $sql = "SELECT MAX(loginID) from log WHERE username = '$userloggedin'" to identify the row I need to change, right? But how do I return that information from the db so that I can put it in a php variable?
Updating Row Changes Timestamp.
I have a flagging system on posts... if someone flags a post it adds 1 to the "flagged" field. My problem is, whenever someone does this, it changes the timestamp so the post they flagged goes to the top of the list because they are ordered by postdate DESC.
Reading & Updating
I have a table where I have all my cars in. They have a brand_id and a model_id. I would like to read this cars table, see how many cars I have from every brand, and every model, and update my other tables, being brands and models. Cars: car_id, brand_id, model_id Brands brand_id, nr_cars Models: model_id, nr_cars I can read every line seperately, and then within that loop do a UPDATE, but I guess there is a 'good' way to do this.
Updating Database
I'm fairly new to mySQL and php and seeking some input. I created a database to hold a member directory. It is a single table. The client uses some contact management software we're they keep track of their members. Therefore, the client does not want to enter the information through a form on the website. Instead the client wants to export a comma delimited file from the program and then use that exported file to update the database. What would be the best approach to do this??? MySQL's LOAD DATA works fine as long as the original data does not change. If a member is removed or a primary key is changed, new rows are added but the old ones (that should of been updated) remain. I figured whenever the client goes to update the db, a script deletes all data from the db, then imports the text file. This doesn't seem like a very efficient approach to me though. Maybe importing the data into a temporary table and then comparing it to the actual table would work, though I am not sure how to go about doing this.
Updating Phpmyadmin.
How do I add this info to my database using phpmyadmin? I have no idea as to how phpmyadmin works, so I will appreciate basic step by step guides to do this.... : I need to add: ALTER TABLE phpbb_themes ADD fontcolor4 VARCHAR (6) ; ALTER TABLE phpbb_themes_name ADD fontcolor4_name CHAR (50) ;
Updating Fields
I'm trying to update values in one column. Some values contain numbers and some are blank. I need to update both but I'd like to do it one query instead of two but I can't figure out how. Example: tableA has 2 columns, item and itemNum. Lets say there's 10 records and 5 values for itemNum are blank, the rest have a number. I need to update itemNum's all blank values to one number and update the initial values as well, but in one query. In other words, I know how to make the query's one by one but I'd like them both in one query. Example single query's: UPDATE tableA SET itemNum = '10' + item WHERE item = 'cd'; UPDATE tableA SET itemNum = '20' WHERE itemNum = ' '; btw, the blank values are not null, they just have a blank string.
|