This is a discussion on mysql php problem with multple values under one variable within the PHP Language forums, part of the PHP Programming Forums category; I am new at php/mysql. I am having trouble with looping. What Im trying to do is have multiple ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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. |
|
|||
|
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 |