
- You are not logged in. | Login
February 21, 2007 9:03 am
- mellis
- Member


Comparison of parameter??™s values within a cycle
Help me please with an idea for such a relative case:
$result = SQL_Query('select * from tablename where conditions order by parameter');
$num_results = mysql_num_rows($result);
for ($i=0; $i <$num_results; $i++) {
$row = mysql_fetch_array($result);
echo $row["parameter"].', ';
}I??™d like to do it in a way which enables evading parameter??™s displaying in case it is equal. I.e. instead of "5, 5, 5, 5, 7, 7, 7, 9, 9, 9", for instance, I??™d like to have displayed "5, -, -, -, 7, -, -, 9, -, -,". I should compare the current parameter??™s value with the previous one. But how can I do this?
I hope someone helps me.
February 21, 2007 9:07 am
- franzkafka
- Member


Re: Comparison of parameter??™s values within a cycle
You are to memorize current value within a variable.
February 21, 2007 9:16 am
- mellis
- Member


Re: Comparison of parameter??™s values within a cycle
Sure, but I need to change it somehow by every iteration. And how should I do this? I need to manage variables of variables somehow but what should I do?
February 21, 2007 9:20 am
- franzkafka
- Member


Re: Comparison of parameter??™s values within a cycle
You are to memorize them within variable.
February 21, 2007 9:25 am
- Conker
- Member


Re: Comparison of parameter??™s values within a cycle
The last string of the cycle should be
$temp = $row["parameter"];
By the output you are to compare $temp and $row["parameter"] against their equality.
February 21, 2007 9:28 am
- mellis
- Member


Re: Comparison of parameter??™s values within a cycle
But if I do so they will always be equal. In each iteration $temp will take the current value of parameter. But I need $temp which is equal to the previous value.
February 21, 2007 9:34 am
- franzkafka
- Member


Re: Comparison of parameter??™s values within a cycle
Instead of pondering you??™d better do what I say.
February 21, 2007 9:39 am
- mellis
- Member


Re: Comparison of parameter??™s values within a cycle
I??™ve managed it, thanks.
if($row["parameter"]!=$temp) echo $row["parameter"].', '; else echo '_, '; $temp=$row["parameter"];
Something like this.
February 21, 2007 9:49 am
- Conker
- Member


Re: Comparison of parameter??™s values within a cycle
Sure but??¦ You are to declare $temp before cycle or you will get a warning.


