•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,583 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,610 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 8753 | Replies: 4
![]() |
•
•
Join Date: Aug 2004
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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.
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.
•
•
Join Date: Nov 2003
Posts: 20
Reputation:
Rep Power: 6
Solved Threads: 1
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
•
•
•
•
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.
•
•
Join Date: Aug 2004
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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.
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.
•
•
Join Date: Sep 2004
Posts: 25
Reputation:
Rep Power: 5
Solved Threads: 0
$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
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
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- php5 and phpmyadmin?? (PHP)
- Trying to update entire column in database (PHP)
- retrieving image from mysql database using php (PHP)
- Php code confusion. Not sure how to describe (PHP)
Other Threads in the PHP Forum
- Previous Thread: PHP vs. Pearl
- Next Thread: how can i compressed any file as zip by php


Linear Mode