[PHP] Problem with a while loop

2004-10-07 Thread Richard Kurth
I am having a problem with a while loop
if I put in a number with 0's in front of it it converts the number
two the first whole number. such as 1 would be 1 02200 would be
2200. Then it starts the count down starting with that number.

How can I make it not remove the 0's in front of the number these are
needed to search a certain database .

The following script would look like this when run
1
2
3
4
I needed it to look like this
1
2
3

?php
$startnumber=1;
$stopnumber=02200;

$i = $startnumber;
echo $i;

while ($i = $stopnumber):
echo br ;
echo $i;

++$i;
endwhile;
? 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Problem with a while loop

2004-10-07 Thread djoseph

 The following script would look like this when run
 1
 2
 3
 4
 I needed it to look like this
 1
 2
 3

You're going to want to use printf or sprintf to format the numbers.

example: printf( %05d, $i ); 

this would print out your number, then left fill it will the zeros you want.

-Dan Joseph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Problem with a while loop

2004-10-07 Thread Richard Kurth
Hello djoseph,

Thursday, October 7, 2004, 11:34:22 AM, you wrote:


 The following script would look like this when run
 1
 2
 3
 4
 I needed it to look like this
 1
 2
 3

dtrc You're going to want to use printf or sprintf to format the numbers.

dtrc example: printf( %05d, $i ); 

dtrc this would print out your number, then left fill it will the zeros you want.

dtrc -Dan Joseph

 This is the actual script I need it to work in.
 I still am not sure how I would use printf or sprintf I don't want
 to pad the numbers I need the loop to leave the number alone.
 The startnumber and stopnumber will always change. some times they
 will start with a whole number and sometimes they will start with
 just one 0. As you can see with this range of number it starts with
 1 it needs to add 1 to that number to make it 2 when it gets
 into the 100 it needs to look like this 00100.


$startnumber=1;
$stopnumber=02200;

while ($i = $stopnumber):
echo $i;
echo div align='center'strong$i/strong/div;
echo br;
flush();
// get a web page into an array and print it out
$fcontents = file (http://sos.state.nv.us/corp_nme.asp?corpnum=X$year; . $i . 0);
while (list ($line_num, $line) = each ($fcontents)) {
if ($line_num==40){
$f=strip_tags($line);
echo $f;



..other code


++$i;
endwhile;


-- 
Best regards,
 Richardmailto:[EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Problem with a while loop

2004-10-07 Thread Janet Valade
Richard Kurth wrote:
I am having a problem with a while loop
if I put in a number with 0's in front of it it converts the number
two the first whole number. such as 1 would be 1 02200 would be
2200. Then it starts the count down starting with that number.
How can I make it not remove the 0's in front of the number these are
needed to search a certain database .
The following script would look like this when run
1
2
3
4
I needed it to look like this
1
2
3
?php
$startnumber=1;
$stopnumber=02200;
$i = $startnumber;
echo $i;
while ($i = $stopnumber):
echo br ;
echo $i;
++$i;
endwhile;
? 

Here's the problem. You set the number originally as a string. However, 
as soon as you tell PHP to add the number, it becomes an integer. It 
must. You can't add strings.

If you need to use the number as a string inside the loop, you will have 
to convert it back to a string. You can do this with sprintf, as in:

$str_num = sprintf(%05.0f,$i);
You can use var_dump($varname) to see what kind of data is stored in 
$varname.

Janet
--
Janet Valade -- janet.valade.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] problem with a while loop

2004-05-06 Thread Jessica Mays
From: [EMAIL PROTECTED]
Subject:problem with a while loop
Date:   May 6, 2004 11:25:28 AM EDT
To:   [EMAIL PROTECTED]
Hey everybody!
I am new to php (and mySQL) and I am working on a php page that links 
up to a mySQL database.  My current code works up to a point, BUT what 
happens is that I try to have a while loop and check a variable with an 
inner while loop but it only catches after the first complete cycle.

Basically, some producers will only call up one row, but you always get 
2 at the minimum with this code below.  I have tried lots of different 
things which all lead to the second row endlessly repeating or the page 
not loading at all.

Any ideas?  Please email me directly since I am on the digest. Thanks
Jessica
(Also, I am new to this list and if this email is in the wrong format I 
apologize.)

CODE :
?
  $query = select * from wine where REGION like 'California' order by 
PRODUCE,DESCRIPT,VINTAGE;

  $result = mysql_query($query);
  $num_results = mysql_num_rows($result);
  echo pNumber of wines found: .$num_results./p;
  $i =0;
  while ($i  $num_results)   {
$row = mysql_fetch_array($result);
$producer = $row[PRODUCE];
		echo table  width=\400\ border=\0\ cellspacing=\0\ 
cellpadding=\2\ bgcolor=\#cc\tr bgcolor=\#FF\td 
colspan=\4\ class=\bigtext\;
 	echo stripslashes($row[PRODUCE]);
		echo /td/tr;
		
		$color = #cc;
		echo tr  bgcolor=$colortd width=\50\;

// id number
echo stripslashes($row[INVID]);
echo /tdtd;
// vintage
 echo stripslashes($row[VINTAGE]);
 echo  ;

// description
echo stripslashes($row[DESCRIPT]);
echo  ;
// bottle size
if ($row[BOTSIZE] != 750ml){
echo span class=\bottlesize_sm\;
echo stripslashes($row[BOTSIZE]);
echo /span;
}

if ($row[NOTES] != ){
echo bri;
echo stripslashes($row[NOTES]);
echo /i;
}

echo /td;

// list price
echo td align=\right\ width=\60\;
 echo stripslashes($row[WINENUM]);
 echo /td;

// sale price
echo td align=\right\ width=\60\;
 echo stripslashes($row[SALEPRICE]);
echo /td;


while (  $producer == $row[PRODUCE]) {

if ($color == #ccdd99)
$color = #cc;
else
$color = #ccdd99;

$row = mysql_fetch_array($result);

echo tr bgcolor=$colortd width=\50\;

// id number
echo stripslashes($row[INVID]);
echo /tdtd;

// vintage
 echo stripslashes($row[VINTAGE]);
 echo  ;

// description
echo stripslashes($row[DESCRIPT]);
echo  ;
// bottle size
if ($row[BOTSIZE] != 750ml){
echo span class=\bottlesize_sm\;
echo stripslashes($row[BOTSIZE]);
echo /span;
}

if ($row[NOTES] != ){
echo bri;
echo stripslashes($row[NOTES]);
echo /i;
}

echo /td;

// list price
echo td align=\right\ width=\60\;
 echo stripslashes($row[WINENUM]);
 echo /td;

// sale price
echo td align=\right\ width=\60\;
 echo stripslashes($row[SALEPRICE]);
echo /td;

++$i;
}

echo /tr/tablepnbsp;/p;
++$i;
  }


?


Re: [PHP] problem with a while loop

2004-05-06 Thread John Nichel
Jessica Mays wrote:
From:   [EMAIL PROTECTED]
Subject: problem with a while loop
Date: May 6, 2004 11:25:28 AM EDT
To:   [EMAIL PROTECTED]
Hey everybody!
I am new to php (and mySQL) and I am working on a php page that links up 
to a mySQL database.  My current code works up to a point, BUT what 
happens is that I try to have a while loop and check a variable with an 
inner while loop but it only catches after the first complete cycle.

Basically, some producers will only call up one row, but you always get 
2 at the minimum with this code below.  I have tried lots of different 
things which all lead to the second row endlessly repeating or the page 
not loading at all.

Any ideas?  Please email me directly since I am on the digest. Thanks
Jessica
(Also, I am new to this list and if this email is in the wrong format I 
apologize.)

CODE :
?
  $query = select * from wine where REGION like 'California' order by 
PRODUCE,DESCRIPT,VINTAGE;

  $result = mysql_query($query);
  $num_results = mysql_num_rows($result);
  echo pNumber of wines found: .$num_results./p;
  $i =0;
  while ($i  $num_results)   {
$row = mysql_fetch_array($result);
 $producer = $row[PRODUCE];
snip
Try changing the above from
while ($i  $num_results)   {
$row = mysql_fetch_array($result);
To
while ( $row = mysql_fetch_array($result) ) {
--
John C. Nichel
KegWorks.com
716.856.9675
[EMAIL PROTECTED]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] problem with a while loop

2004-05-06 Thread John W. Holmes
From: Jessica Mays [EMAIL PROTECTED]
 I am new to php (and mySQL) and I am working on a php page that links
 up to a mySQL database.  My current code works up to a point, BUT what
 happens is that I try to have a while loop and check a variable with an
 inner while loop but it only catches after the first complete cycle.

while ($i  $num_results)   {

 $row = mysql_fetch_array($result);

   $producer = $row[PRODUCE];
[snip]
 while (  $producer == $row[PRODUCE]) {

 $row = mysql_fetch_array($result);
[snip]
 ++$i;
 }

 ++$i;
}

You posted too much code to go through easily. It took me a while to figure
out what you were doing. The code above is what it really could have been
condensed to...

Anyhow, the first time through, you're inner while() loop is always going to
execute and keep executing until you pull a new produce value from the
result set. At that time, the new produce row is currently in $row, the
inner while() loop fails and control passes back to your outer loop.
However, at that time you call mysql_fetch_array() again in your outer loop
and you just lost the row that cause the inner loop to teminate.

What you want, if I can read right, is to only display the part in your
outer while() loop when produce changes.

$producer = '';
while($row = mysql_fetch_array($result))
{
  if($row['produce'] != $producer)
  {
//display outer while() loop HTML here
$producer = $row['produce'];
  }
  //display inner while() loop HTML here.
}

Hope that helps.

---John Holmes...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] problem with a while loop

2004-05-06 Thread John W. Holmes
From: John Nichel [EMAIL PROTECTED]

$i =0;
 
while ($i  $num_results)   {
 
  $row = mysql_fetch_array($result);
 
   $producer = $row[PRODUCE];
 snip

 Try changing the above from

 while ($i  $num_results)   {

  $row = mysql_fetch_array($result);

 To

 while ( $row = mysql_fetch_array($result) ) {

Same thing, really. It's a little more efficient than keeping a count, but
not the cause of any of the problems. :)

---John Holmes...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] problem with a while loop

2004-05-06 Thread John Nichel
John W. Holmes wrote:

Same thing, really. It's a little more efficient than keeping a count, but
not the cause of any of the problems. :)
---John Holmes...
Chris!  John is picking on me!
;)
--
John C. Nichel
KegWorks.com
716.856.9675
[EMAIL PROTECTED]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] problem with a while loop

2004-05-06 Thread John W. Holmes
From: John Nichel [EMAIL PROTECTED]

  Same thing, really. It's a little more efficient than keeping a count,
but
  not the cause of any of the problems. :)
 
  ---John Holmes...

 Chris!  John is picking on me!

I thought we agreed that Chris is the one that cannot be trusted??

---John Holmes...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] problem with a while loop

2001-10-26 Thread Richard Kurth

 I am trying to get the data out of the while loop if I echo $email
 inside the } it gives me all of the data but if I echo it out side of
 the loop it only gives me one record even though I know there is
 more. How can I get this to work

$query = SELECT * FROM members Where Company  LIKE '%$search1%';
$result=mysql_db_query($dbName,$query);
while ($row = mysql_fetch_array($result)) {
$email= $row[lname] .   . lt; . $row[E_mail_1] . gt; . ;;
}


echo $email;

-- 
Best regards,
 Richard  mailto:[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] problem with a while loop

2001-10-26 Thread Niklas Lampén

What happens there is this:

$email = 1. row;
$email = 2. row;
$email = 3. row;
echo $email;

You really need to put echo $email inside the loop or use '.=' to set up
values to $email.


Niklas


-Original Message-
From: Richard Kurth [mailto:[EMAIL PROTECTED]] 
Sent: 26. lokakuuta 2001 10:11
To: php
Subject: [PHP] problem with a while loop


 I am trying to get the data out of the while loop if I echo $email
inside the } it gives me all of the data but if I echo it out side of
the loop it only gives me one record even though I know there is  more.
How can I get this to work

$query = SELECT * FROM members Where Company  LIKE '%$search1%';
$result=mysql_db_query($dbName,$query);
while ($row = mysql_fetch_array($result)) {
$email= $row[lname] .   . lt; . $row[E_mail_1] . gt; . ;;
}


echo $email;

-- 
Best regards,
 Richard  mailto:[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED] To
contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] problem with a while loop

2001-10-26 Thread David Robley

On Fri, 26 Oct 2001 16:40, Richard Kurth wrote:
  I am trying to get the data out of the while loop if I echo $email
  inside the } it gives me all of the data but if I echo it out side of
  the loop it only gives me one record even though I know there is
  more. How can I get this to work

 $query = SELECT * FROM members Where Company  LIKE '%$search1%';
 $result=mysql_db_query($dbName,$query);
 while ($row = mysql_fetch_array($result)) {
 $email= $row[lname] .   . lt; . $row[E_mail_1] . gt; . ;;
 }


 echo $email;

You would probably want to append the values to $email in your loop, 
then. As it is, you are overwriting the value in $email each pass through 
the loop.
-- 
David Robley  Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES  Flinders University, SOUTH AUSTRALIA  

   I'm fascinated by the way memory diffuses fact.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] problem with a while loop

2001-10-26 Thread Richard Baskett

Or you can do something like:
$query = SELECT * FROM members Where Company  LIKE '%$search1%';
$result = mysql_db_query($dbName, $query);
$numRows = mysql_num_rows($result);

for ($i=0; $i$numRows; $i++) {
  $row = mysql_fetch_array($result);
  $email[] = $row[email];
}

OR

while ($row = mysql_fetch_array($result)) {
  $email[] = $row[email];
}

This just puts all your emails into an array.  You can do whatever you want
within either loop and it'll do it to every element.  It's pretty limitless,
or like I did you can stick everything you want into an array to use later..
whatever your fancy :)

The reason you only get one email when you echo it outside the loop is that
mysql_fetch_array only grabs one row, so you loop through and if you echo
inside the loop you'll see every row outputted, while outside the loop
you'll only get the last row outputted. (not sure if outputted is a word :)
Anyways so now that you understand it a little more, you can do whatever you
want to each element in the row inside the loop... I hope that helps!

Rick

 your while loop is working fine -- it's just that you're re-setting the value
 of $email every time it loops through.
 
 I'm not sure what you're trying to accomplish, but you might try something
 like:
 
 $query = SELECT * FROM members Where Company  LIKE '%$search1%';
 $result=mysql_db_query($dbName,$query);
 while ($row = mysql_fetch_array($result)) {
 $email[$row['lname']] =  $row[E_mail_1]
 } //untested code -- probably missing some quotes somewhere.
 
 
 that will give you an array with lname as the key and e_mail_1 as your value.
 You can then loop through it and format it however you want.
 
 hth
 
 --kurt 
 
 On Friday 26 October 2001 00:10, Richard Kurth wrote:
  I am trying to get the data out of the while loop if I echo $email
  inside the } it gives me all of the data but if I echo it out side of
  the loop it only gives me one record even though I know there is
  more. How can I get this to work
 
 $query = SELECT * FROM members Where Company  LIKE '%$search1%';
 $result=mysql_db_query($dbName,$query);
 while ($row = mysql_fetch_array($result)) {
 $email= $row[lname] .   . lt; . $row[E_mail_1] . gt; . ;;
 }
 
 
 echo $email;
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]