Re: [PHP] conditional statement inside while loop?

2005-09-02 Thread z a p a n
Murray, Miles, Cristea  Jim: Thanks a lot, I got it figured out.  Peace, -z

 Hello everyone,
 
 I'm using a while loop to display a list of people contained in my
 database.
 I'd like to assign different font colors to each depending on which city
 they're from, but I can't seem to get an if/elseif/else statement to work
 inside the while loop.  Is there another way to do this?
 
 Hi Zach,
 
 There should be no reason why you can't use if/elseif/else within your while
 loop. The fact that you're experiencing problems strongly suggests that you
 have a combination of conditionals in your if/elseif/else that is
 effectively ignoring the data being returned from your recordset.
 
 It may be something as simple as using = in your if statement instead of
 == (ie, so the conditional is always true, because you're using the
 assignment = operator instead of the evaluative == operator), or a
 combination of conditions, each of which are accurate but which when placed
 together cause problems.
 
 To get an idea where your problem is occurring, try going from simple to
 complex. Start with something like the following pseudo-code:
 
 while ($row = get_data_from_your_recordset){
 if (strlen($row['a_recordset_field'])  0){
 echo Data found:  . $row['a_recordset_field'] . br /;
 } else {
 echo Data not foundbr /;
 }
 }
 
 The assumption being made above is that you will be using a field from your
 recordset that contains data that is ordinarily longer than 0 bytes.
 
 Doing the above will demonstrate that at the very least you are returning a
 valid recordset and that conditional statements work within while loops. If
 even this fails, then check the SQL that is being used to populate the
 recordset, and make sure that you are using the same field names in your PHP
 code as is being returned from the table by the recordset.
 
 Once the above is working, add back in your actual conditional(s), one by
 one. You're looking for the point where 'working' code becomes 'broken'
 code. Most of the time when you debug in this way it becomes obvious why the
 code isn't behaving the way you expect it to. If there's still any confusion
 at that point, at least you will be in a better position to supply actual
 code to the list, so we can work out the real problem.
 
 Much warmth,
 
 Murray
 ---
 Lost in thought...
 http://www.planetthoughtful.org


-- 

fourthcity 2005 ; slow yr roll. --- http://www.fourthcity.net/


 quick links:
 http://www.fourthcity.net/   [fct]
 http://www.zapan.net/[  zapan]
 http://www.laptopbattle.org/ [ battle]
 http://www.postermidget.com/ [ midget]


  +
   +
 +
 + +
 +
 +


 much love! from the fourthcity studios  

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



RE: [PHP] conditional statement inside while loop?

2005-09-01 Thread Jim Moseby
 I'm using a while loop to display a list of people contained 
 in my database.
 I'd like to assign different font colors to each depending on 
 which city
 they're from, but I can't seem to get an if/elseif/else 
 statement to work
 inside the while loop.  Is there another way to do this?

Something like this maybe?:

pseoudcode
while($row=mysql_fetch_array($result){
  switch($row['city']){
case 'bejing':
  $bgcolor='#FF';
  break;
case 'tokyo':
   $bgcolor='#00FF00';
   break;
{...}
  }//switch
}//while
/pseoudcode

JM

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



Re: [PHP] conditional statement inside while loop?

2005-09-01 Thread Miles Thompson

At 03:52 PM 9/1/2005,  z a p a n  wrote:

Hello everyone,

I'm using a while loop to display a list of people contained in my database.
I'd like to assign different font colors to each depending on which city
they're from, but I can't seem to get an if/elseif/else statement to work
inside the while loop.  Is there another way to do this?

Thanks in advance,
Zach


That should work, just try a simple if() at first. If it is not working, 
back up, simplify, just do  simple echo to tell you where you are.


Better yet, this sounds like an excellent spot to use switch ... case ... 
break.


If you have an editor that can match braces take advantage of that feature. 
You may not be exactly where you think you are.


So, no answer, but hopefully the suggestions are helpful.

Cheers - Miles 


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



RE: [PHP] conditional statement inside while loop?

2005-09-01 Thread Murray @ PlanetThoughtful
 Hello everyone,
 
 I'm using a while loop to display a list of people contained in my
 database.
 I'd like to assign different font colors to each depending on which city
 they're from, but I can't seem to get an if/elseif/else statement to work
 inside the while loop.  Is there another way to do this?

Hi Zach,

There should be no reason why you can't use if/elseif/else within your while
loop. The fact that you're experiencing problems strongly suggests that you
have a combination of conditionals in your if/elseif/else that is
effectively ignoring the data being returned from your recordset.

It may be something as simple as using = in your if statement instead of
== (ie, so the conditional is always true, because you're using the
assignment = operator instead of the evaluative == operator), or a
combination of conditions, each of which are accurate but which when placed
together cause problems.

To get an idea where your problem is occurring, try going from simple to
complex. Start with something like the following pseudo-code:

while ($row = get_data_from_your_recordset){
if (strlen($row['a_recordset_field'])  0){
echo Data found:  . $row['a_recordset_field'] . br /;
} else {
echo Data not foundbr /;
}
}

The assumption being made above is that you will be using a field from your
recordset that contains data that is ordinarily longer than 0 bytes.

Doing the above will demonstrate that at the very least you are returning a
valid recordset and that conditional statements work within while loops. If
even this fails, then check the SQL that is being used to populate the
recordset, and make sure that you are using the same field names in your PHP
code as is being returned from the table by the recordset.

Once the above is working, add back in your actual conditional(s), one by
one. You're looking for the point where 'working' code becomes 'broken'
code. Most of the time when you debug in this way it becomes obvious why the
code isn't behaving the way you expect it to. If there's still any confusion
at that point, at least you will be in a better position to supply actual
code to the list, so we can work out the real problem.

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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