473,387 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

mysql php problem with multple values under one variable

I am new at php/mysql. I am having trouble with looping. What Im
trying to do is have multiple part numbers under 1 variable. If i just
put $pnum = thepartnumber and echo $fprice, it will take the 1st value
and carry it down till the end. Below is my current code.

:code begin:

<?
$connection = mysql_connect("localhost","user","pass")
or die("Unable to connect to localhost");

$db = mysql_select_db(database)
or die("Unable to connect to database");

while($pnum = 3)
{
$i = 1;
$pnum = '749125';
$pnum = $pnum +$i;
$result = mysql_query("SELECT * FROM products WHERE part_num =
'$pnum'");
$price = mysql_result($result,0,"cost");
$fprice = ceil($price * 1.2);
$pnum = '749125';
echo "<br>";
echo $fprice;
$pnum = '749126';
echo "<br>";
echo $fprice;

}
?>

:code end:

what am i doing wrong. btw I did get it to work so it would grab just
1 part numbers price without the loop, but I need it to get multiple
part numbers. Any help is appricated.
Jul 16 '05 #1
1 1996
Larryd wrote:
I am new at php/mysql. I am having trouble with looping. What Im
trying to do is have multiple part numbers under 1 variable. If i just
put $pnum = thepartnumber and echo $fprice, it will take the 1st value
and carry it down till the end. Below is my current code.

:code begin:

<?
$connection = mysql_connect("localhost","user","pass")
or die("Unable to connect to localhost");

$db = mysql_select_db(database)
or die("Unable to connect to database");

while($pnum = 3)
{
$i = 1;
$pnum = '749125';
$pnum = $pnum +$i;
$result = mysql_query("SELECT * FROM products WHERE part_num =
'$pnum'");
$price = mysql_result($result,0,"cost");
$fprice = ceil($price * 1.2);
$pnum = '749125';
echo "<br>";
echo $fprice;
$pnum = '749126';
echo "<br>";
echo $fprice;

}
?>

:code end:

what am i doing wrong. btw I did get it to work so it would grab just
1 part numbers price without the loop, but I need it to get multiple
part numbers. Any help is appricated.

I am not totally sure I understand your question/problem, but my best
understanding is that your loop is causing you to always pull the same
part number's informaton? If this is so and you are having problems
incrementing, I would pull the $i = 1 line outside of the while loop.
Otherwise everytime you are starting the loop again you are reassigning
the value 1 to $i, so of course you will get the same value again and
again. After you do this, at the last line of the loop type $i++ to
increment the counter for the next iteration.

Marcus
Jul 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alexander Ross | last post by:
I want a cookie that can have about 5 values. I was told to do something like this: to set the cookie the first time: setcookie("questions",$_POST,time()+60*60*24,"/","",0); then to add valus...
2
by: Christopher Kang | last post by:
I had a question about python and mysql, but I want to first thank those who taught me about the factory method, it was exactly what I needed. Anyway, I have a problem where I am pulling...
0
by: I.P. | last post by:
Hi, it's my story. I have two 4.0.14 mysql server on one machine with win XP Professional polish version. First acts as master: on port 3300 Second acts as slave: on port 3301 below my...
0
by: I.P. | last post by:
No one has replied to my post. ----- Original Message ----- From: "I.P." <jancio_wodnik@wp.pl> To: <mysql@lists.mysql.com> Sent: Monday, August 18, 2003 1:01 PM Subject: mysql 4.0.14 +...
2
by: RootShell | last post by:
Hello First of all i know that PHP is a server side, and JavaScript is a Client side programming language, but i need to know if there is any way i can add the variable "countDownInterval" from...
1
by: PowerLifter1450 | last post by:
I've been having a very rough time installinig mySQL on Linux. I have been following the instructions form here: http://www.hostlibrary.com/installing_apache_mysql_php_on_linux Everytime I get to...
5
by: strawberry | last post by:
In the function below, I'd like to extend the scope of the $table variable such that, once assigned it would become available to other parts of the function. I thought 'global $table;' would solve...
2
by: Boujii | last post by:
Greetings, I have been attempting to make a drop down menu of countries. From this menu I wish to create a variable in order to INPUT into mysql database. I have no trouble making the drop down menu,...
1
ssnaik84
by: ssnaik84 | last post by:
Hi Guys, Last year I got a chance to work with R&D team, which was working on DB scripts conversion.. Though there is migration tool available, it converts only tables and constraints.. Rest of...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.