mysql php problem with multple values under one variable

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-06-2003
Larryd
 
Posts: n/a
Default 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.
Reply With Quote
  #2 (permalink)  
Old 08-07-2003
Marcus
 
Posts: n/a
Default Re: mysql php problem with multple values under one variable

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


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:31 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0