Re: temporary error

From: Date: Thu, 21 Feb 2008 15:35:43 +0000
Subject: Re: temporary error
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-269789@lists.php.net to get a copy of this message
Mirco Soderi wrote: > In my opinion, variable names are a personal choice, I think the time > you loose when writing the name (about a second is long less than the > time you gain when, months later, you go and modify the code and you > have clear the content and meaning of each variable. > > In the original code there were no sintax errors, I added some errors > when pasting here. Sorry. > > I have found that in the first execution, it was the > $logQueryInserimentoDatiAllenamentoCalciPiazzati that evaluated to > false. After having removed the two-field key that I had originally > defined for that table and having added an autoincrement key, the > problem seems to be solved. > > Do you find any reason for that? > > > ""Mirco Soderi"" <m.soderi@alice.it> ha scritto nel messaggio > news:39.96.21621.F728DB74@pb1.pair.com... >> Consider the following code: >> >> $sqlQueryInserimentoDatiAllenamentoCalciPiazzati = "INSERT INTO ... >> etc etc ...." $queryInserimentoDatiAllenamentoCalciPiazzati = >> mysql_query($sqlQueryInserimentoDatiAllenamentoCalciPiazzati); >> if($queryInserimentoDatiAllenamentoCalciPiazzati) { // do something >> } if($queryInserimentoDatiAllenamentoCalciPiazzati) { >> $logQueryInserimentoDatiAllenamentoCalciPiazzati = >> mysql_query("insert into log ... etc etc ..."); >> if($logQueryInserimentoDatiAllenamentoCalciPiazzati) { // do >> something } } if($queryInserimentoDatiAllenamentoCalciPiazzati && >> $logQueryInserimentoDatiAllenamentoCalciPiazzati) { // do something >> } >> >> 1st execution: $queryInserimentoDatiAllenamentoCalciPiazzati && >> $logQueryInserimentoDatiAllenamentoCalciPiazzati, where clause of >> last conditional statement, evaluates to false even if both queries >> are correctly executed. >> >> I modify as follows: >> >> $sqlQueryInserimentoDatiAllenamentoCalciPiazzati = "INSERT INTO ... >> etc etc ...." $queryInserimentoDatiAllenamentoCalciPiazzati = >> mysql_query($sqlQueryInserimentoDatiAllenamentoCalciPiazzati); >> if($queryInserimentoDatiAllenamentoCalciPiazzati) { // do something >> } else echo("error message 1"); >> if($queryInserimentoDatiAllenamentoCalciPiazzati) { >> $logQueryInserimentoDatiAllenamentoCalciPiazzati = >> mysql_query("insert into log ... etc etc ..."); >> if($logQueryInserimentoDatiAllenamentoCalciPiazzati) { // do >> something } else echo("error message 2"); } >> if($queryInserimentoDatiAllenamentoCalciPiazzati && >> $logQueryInserimentoDatiAllenamentoCalciPiazzati) { // do something >> } >> >> 2nd execution: $queryInserimentoDatiAllenamentoCalciPiazzati && >> $logQueryInserimentoDatiAllenamentoCalciPiazzati, where clause of >> last conditional statement, evaluates to true. >> >> Now, I modify again, back to the original version: >> >> $sqlQueryInserimentoDatiAllenamentoCalciPiazzati = "INSERT INTO ... >> etc etc ...." $queryInserimentoDatiAllenamentoCalciPiazzati = >> mysql_query($sqlQueryInserimentoDatiAllenamentoCalciPiazzati); >> if($queryInserimentoDatiAllenamentoCalciPiazzati) { // do something >> } if($queryInserimentoDatiAllenamentoCalciPiazzati) { >> $logQueryInserimentoDatiAllenamentoCalciPiazzati = >> mysql_query("insert into log ... etc etc ..."); >> if($logQueryInserimentoDatiAllenamentoCalciPiazzati) { // do >> something } } if($queryInserimentoDatiAllenamentoCalciPiazzati && >> $logQueryInserimentoDatiAllenamentoCalciPiazzati) { // do something >> } >> >> 3rd execution: $queryInserimentoDatiAllenamentoCalciPiazzati && >> $logQueryInserimentoDatiAllenamentoCalciPiazzati, where clause of >> last conditional statement, evaluates to true. >> >> Do you know any reason for that? Glad to see that you found your problem. Variables may be easier to read with some underscores. Personally, here is what I use as a counter in most all of my code, instead of $i++; which isn't always clear. $Super_Cala_Fraga_Listic_Ex_Peal_Ado_Tio_Us_Counter = $Super_Cala_Fraga_Listic_Ex_Peal_Ado_Tio_Us_Counter + ($Super_Cala_Fraga_Listic_Ex_Peal_Ado_Tio_Us_Counter / $Super_Cala_Fraga_Listic_Ex_Peal_Ado_Tio_Us_Counter); If you wan to shorten a bit you can use a constant as the counter increment like so: define('Increment_Super_Cala_Fraga_Listic_Ex_Peal_Ado_Tio_Us_Counter', 1); $Super_Cala_Fraga_Listic_Ex_Peal_Ado_Tio_Us_Counter = $Super_Cala_Fraga_Listic_Ex_Peal_Ado_Tio_Us_Counter + Increment_Super_Cala_Fraga_Listic_Ex_Peal_Ado_Tio_Us_Counter; -Shawn

« previous php.general (#269789) next »