RE: [PHP] IF inside LOOP?

2002-07-17 Thread Ford, Mike [LSS]

 -Original Message-
 From: César Aracena [mailto:[EMAIL PROTECTED]]
 Sent: 15 July 2002 03:04

 This is what I have so far:
  
 for ($m=0; $m$num_rows2; $m++)
 {
 $row2 = mysql_fetch_array($result2);
  
 echo $row2[devlanguage];
  
 if ($m  $num_rows2)
 {
 echo , ;
 }
 else
 {
 echo .;
 }
 }

My approach to this is like this:

   for ($m=0; $m$num_rows2; $m++)
   {
  $row2 = mysql_fetch_array($result2);

  if ($m0) echo ', ';
  echo $row2[devlanguage];
   }
   echo '.';

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

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




RE: [PHP] IF inside LOOP?

2002-07-14 Thread Martin Towell

try using this if statement instead

if ($m  $num_rows2 - 1)

or even use the ?: operator

echo ($m  $num_rows2 - 1 ? ,  : .);


-Original Message-
From: César Aracena [mailto:[EMAIL PROTECTED]]
Sent: Monday, July 15, 2002 12:04 PM
To: PHP General List
Subject: [PHP] IF inside LOOP?


Hi all.
 
I've been fooling around with a LOOP which should show one or more text
string stored in separate rows in a DB. The trick would we to separate
them with commas (,) when there's another string to show or end it with
a period (.) if no other row is found according to the SELECT criteria.
This is what I have so far:
 
for ($m=0; $m$num_rows2; $m++)
{
$row2 = mysql_fetch_array($result2);
 
echo $row2[devlanguage];
 
if ($m  $num_rows2)
{
echo , ;
}
else
{
echo .;
}
}
 
The problem is that the LOOP stops as it's told to do, keeping the ELSE
statement from doing it's work, resulting in comma separated string as
it should, but also add an extra comma at the end of it instead of a
period. What approach should I use?
 
Thanks in advance,
 
 mailto:[EMAIL PROTECTED] Cesar Aracena
CE / MCSE+I
Neuquen, Argentina
+54.299.6356688
+54.299.4466621
 

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




RE: [PHP] IF inside LOOP? -- SOLVED

2002-07-14 Thread César Aracena

Thanks for two things Martin: First for teaching me about the -1
operation (which seems logic now) and second, for getting me into the
?: operator. I've read something about it in the books, but didn't
tough it was really useful 'till now.

It worked perfectly. C.

 -Original Message-
 From: Martin Towell [mailto:[EMAIL PROTECTED]]
 Sent: Sunday, July 14, 2002 11:05 PM
 To: 'César Aracena'; PHP General List
 Subject: RE: [PHP] IF inside LOOP?
 
 try using this if statement instead
 
 if ($m  $num_rows2 - 1)
 
 or even use the ?: operator
 
 echo ($m  $num_rows2 - 1 ? ,  : .);
 
 
 -Original Message-
 From: César Aracena [mailto:[EMAIL PROTECTED]]
 Sent: Monday, July 15, 2002 12:04 PM
 To: PHP General List
 Subject: [PHP] IF inside LOOP?
 
 
 Hi all.
 
 I've been fooling around with a LOOP which should show one or more
text
 string stored in separate rows in a DB. The trick would we to separate
 them with commas (,) when there's another string to show or end it
with
 a period (.) if no other row is found according to the SELECT
criteria.
 This is what I have so far:
 
 for ($m=0; $m$num_rows2; $m++)
 {
 $row2 = mysql_fetch_array($result2);
 
 echo $row2[devlanguage];
 
 if ($m  $num_rows2)
 {
 echo , ;
 }
 else
 {
 echo .;
 }
 }
 
 The problem is that the LOOP stops as it's told to do, keeping the
ELSE
 statement from doing it's work, resulting in comma separated string as
 it should, but also add an extra comma at the end of it instead of a
 period. What approach should I use?
 
 Thanks in advance,
 
  mailto:[EMAIL PROTECTED] Cesar Aracena
 CE / MCSE+I
 Neuquen, Argentina
 +54.299.6356688
 +54.299.4466621
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



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