By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,348 Members | 1,397 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,348 IT Pros & Developers. It's quick & easy.

mysql php problem with multple values under one variable

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.