PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
$query = "SELECT `field` FROM `table`";
/*
here my DB Connection Abstraction that returns
the resource $results
*/
sql_select($query,$results);
/* HERE IS WHAT I MEAN */
while($my_row = mysql_fetch_array($results)){
// DO SOMETHING
}
I Want to avoid the "Assignment In Condition" Horrible coding thing with something better/cleaner.
Every suggestion will be appreciate!!!!
$query = "SELECT `field` FROM `table`";
sql_select($query,$results);
// This fetch the first data of the resourse into an array
while($my_row){
// DO SOMETHING
// once the first data is used it gets the next one if available so it would be at the end of the cycle
$my_row = mysql_fetch_array($results);
}
$query = "SELECT `field` FROM `table`";
sql_select($query,$results);
// This fetch the first data of the resourse into an array
$my_row = mysql_fetch_array($results);
while($my_row){
// DO SOMETHING
// once the first data is used it gets the next one if available so it MUST be at the end of the cycle
$my_row = mysql_fetch_array($results);
}
I'll third that. There are special features in PHP specifically for making assignments in conditions more practical. Assignments in condition generally improve readability as long as they remain simple. They also reduce duplication...in short they are good practise, like I said, as long as they are simple
Everah wrote:Why are you not into assignment during the conditional?
I was testing some scripts on an agency and the develope under Zend Studio so whe I debug or analyze the script the advise "Assignment In Condition" blabla comes out. I agree that readibility is better using assignment with condition and I still havent decide if I want to change my scripting method but it makes me curious about what advantages would give me the alternative method.
First off, I wouldn't rely on the Zend Studio debugger messages to that extent. If you comment your code, any decent developer would have no problem understanding what you are doing when assigning during the condition check. I do it all the time and it makes perfect sense to me.
Everah wrote:First off, I wouldn't rely on the Zend Studio debugger messages to that extent. If you comment your code, any decent developer would have no problem understanding what you are doing when assigning during the condition check. I do it all the time and it makes perfect sense to me.
I agree about that but sometimes I have to work with different teams and just have to adapt to the environment and development standards they use (even though if I think they took ....call them "funny" desitions).
Can any of you suggest me a good debugging environment? I know is up to your development target and customs but I'm always testing new ways of work (on non working hours)
I'm developing under Apache 1.3.33, PHP 4.3.10 everithing running on Windows (got to move quickly to Linux but I work many hours on Win graph applications)
Last edited by Jaxolotl on Mon May 21, 2007 11:25 am, edited 1 time in total.