mysql php problem with multple values under one variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Larryd

    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","use r","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("SE LECT * FROM products WHERE part_num =
    '$pnum'");
    $price = mysql_result($r esult,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.
  • Marcus

    #2
    Re: mysql php problem with multple values under one variable

    Larryd wrote:[color=blue]
    > 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","use r","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("SE LECT * FROM products WHERE part_num =
    > '$pnum'");
    > $price = mysql_result($r esult,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.[/color]


    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


    Comment

    Working...