943,708 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 14848
  • PHP RSS
Aug 17th, 2004
0

Update entire Mysql DataBase with PhP

Expand Post »
Hello to everyone,

I'm new here - Great forum.

I would like to update an entire database at once.
I use Mysql database and PhP scripts.

I explain : I have to update prices in one column of the DB by puting +10%

This is what I have but it takes the first price, put +10% and update all prices with this same value, and the idea is I update all prices that are all different, so I suppose to get all different result !

I first select * from the DB where kind=$kind
then I update :

$Price_Ex_1 = $Price_Ex *10/100;
$Price_Ex_2 = $Price_Ex + $Price_Ex_1;

$q = "update DB set Price_Ex = '$Price_Ex_2'
where Kind = $kind

For sure this won't give the expected result !!
Can somebody please help me ?
In advance many thanks.
Erick.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Erick is offline Offline
2 posts
since Aug 2004
Aug 17th, 2004
0

Re: Update entire Mysql DataBase with PhP

Ok, here is a couple of places that you can look. I know that php doesn't have types, but you want to make sure that you aren't truncating the value of $Price_Ex. Another place you want to look is your mysql database, make sure that you have the correct type on the mysql attribute. Finally, if that doesn't work, post a snippet of your code, and I will take a look


Quote originally posted by erick ...
$Price_Ex_1 = $Price_Ex *10/100;
$Price_Ex_2 = $Price_Ex + $Price_Ex_1;

$q = "update DB set Price_Ex = '$Price_Ex_2'
where Kind = $kind

For sure this won't give the expected result !!
Can somebody please help me ?
In advance many thanks.
Erick.
Last edited by cscgal; Aug 17th, 2004 at 5:51 pm.
Reputation Points: 47
Solved Threads: 1
Newbie Poster
oberoc is offline Offline
20 posts
since Nov 2003
Aug 17th, 2004
0

Re: Update entire Mysql DataBase with PhP

HI,
Thanks for your answer.
about the type for $Price_Ex, I guess it's OK (double), as the echo of my data is OK.

$q = "select * from DB_Product
where

Kind = $Kind ";

if(!($res = mysql_DB_query($DB, $q)))
die("query failed.");

$res = mysql_db_query($DB, $q);

while($row = mysql_fetch_object($res)) {

$Product_ID=$row->Product_ID;
$Kind=$row->Kind;
$Price_Ex=$row->Price_Ex;
$Price_Ex_1 = $Price_Ex *10/100;
$Price_Ex_2 = $Price_Ex + $Price_Ex_1;
}

$q = "update DB_Product set Price_Ex='$Price_Ex_2'
where Kind = $Kind ";

if(!($res = mysql_DB_query($DB, $q)))
die("query failed.");

$res = mysql_db_query($DB, $q);

if(!$dbconn){
die("Connection failed.");
}else
{
if(($res = mysql_DB_query($DB, $q))){
confirm();
}else{
inputerror();
}
}

This works if I call one Product_ID and echo it in a field name Price_Ex, but not to update all prices. When i run this script it puts all prices the same.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Erick is offline Offline
2 posts
since Aug 2004
Oct 2nd, 2004
0

Re: Update entire Mysql DataBase with PhP

Include the update sql statement in the while loop. At the moment it only updates the last $kind in the table.
tip
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tip is offline Offline
13 posts
since Sep 2004
Oct 15th, 2004
0

Re: Update entire Mysql DataBase with PhP

$q = "select * from DB_Product where Kind = $Kind ";

if(!($res = mysql_DB_query($DB, $q)))
die("query failed.");

$res = mysql_db_query($DB, $q);

while($row = mysql_fetch_object($res)) {

$Product_ID=$row->Product_ID;
$Kind=$row->Kind;
$Price_Ex=$row->Price_Ex;
$Price_Ex_1 = $Price_Ex *10/100;
$Price_Ex_2 = $Price_Ex + $Price_Ex_1;
}

$q = "update DB_Product set Price_Ex=$Price_Ex_2
where Kind = $Kind ";

if(!($res = mysql_DB_query($DB, $q)))
die("query failed.");

$res = mysql_db_query($DB, $q);

if(!$dbconn){
die("Connection failed.");
}else
{
if(($res = mysql_DB_query($DB, $q))){
confirm();
}else{
inputerror();
}
}


///////////////////////////////////////////////////////////////////////////
as your $Price_Ex_2 is double type remove qoutes from it
if your $kind is not string type then its ok that you gave but if it is string type make sure that it is qouted

thank you
Reputation Points: 10
Solved Threads: 0
Light Poster
billah_norm is offline Offline
25 posts
since Sep 2004
Jan 11th, 2010
-1
Re: Update entire Mysql DataBase with PhP
$q = "select * from DB_Product where Kind = $Kind ";

if(!($res = mysql_DB_query($DB, $q)))
die("query failed.");

$res = mysql_db_query($DB, $q);

while($row = mysql_fetch_object($res)) {

$Product_ID=$row->Product_ID;
$Kind=$row->Kind;
$Price_Ex=$row->Price_Ex;
$Price_Ex_1 = $Price_Ex *10/100;
$Price_Ex_2 = $Price_Ex + $Price_Ex_1;
}

$q = "update DB_Product set Price_Ex=$Price_Ex_2
where Kind = $Kind ";

if(!($res = mysql_DB_query($DB, $q)))
die("query failed.");

$res = mysql_db_query($DB, $q);

if(!$dbconn){
die("Connection failed.");
}else
{
if(($res = mysql_DB_query($DB, $q))){
confirm();
}else{
inputerror();
}
}


///////////////////////////////////////////////////////////////////////////
as your $Price_Ex_2 is double type remove qoutes from it
if your $kind is not string type then its ok that you gave but if it is string type make sure that it is qouted

thank you
I have 5 PHP programs that work as web sites allowing
adding rows, deleting row and updating single rows
window XP Prof SP3
(1) pilot's logbook access MySQL
(2) pilot's logbook access Oracle
(3) pilot's logbook access sql server 2008 express
Fedora 12
(1) pilot's logbook access MySQL
(2) pilot's logbook access Oracle

I can email

Voltaire: If God did not exist, it would be necessary for us to invent Him
GOD: If Voltaire did not exist, it would be necessary for us to invent him
Reputation Points: 9
Solved Threads: 0
Newbie Poster
landonmkelsey is offline Offline
21 posts
since Aug 2009
Jan 11th, 2010
0
Re: Update entire Mysql DataBase with PhP
all you need is this query...
PHP Syntax (Toggle Plain Text)
  1. <?php $sql = mysql_query( "UPDATE price SET prod_price = (prod_price * .10)" ); ?>
Reputation Points: 32
Solved Threads: 63
Posting Pro in Training
vaultdweller123 is offline Offline
489 posts
since Sep 2009
Jan 11th, 2010
0
Re: Update entire Mysql DataBase with PhP
all you need is this query...
should be
PHP Syntax (Toggle Plain Text)
  1. <?php $sql = mysql_query( "UPDATE price SET prod_price = (prod_price * 1.10)" ); ?>
+ 10% = 1.1 otherwise yeah
Last edited by almostbob; Jan 11th, 2010 at 3:02 pm.
Reputation Points: 562
Solved Threads: 368
Posting Maven
almostbob is offline Offline
2,970 posts
since Jan 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: User add to list using ?
Next Thread in PHP Forum Timeline: Send text from php script to web page





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC