473,503 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

no curly braces ;(

5 New Member
Hi everybody,
I'm a PHP beginner, so please forgive me for this question.

I am working on code someone else wrote a long time ago. The code was written without curly braces in many places, which for the most has been ok. However I am getting an error message that -for the code snippet I posted below- would read like this:
Notice: Undefined variable: f in ... on line 3.
Precisely a section that has a couple of loops and conditionals without braces. I am wondering if adding them will solve things. My problem is that I am very uncertain about where to add those braces since I don't know how many statements are within an IF or FOR that is not using the braces.

Could someone help me/show me where they would go on these lines of code? I'd appreciate it a lot.
Thanks so much,

Mauricio

Expand|Select|Wrap|Line Numbers
  1. for($x = 0;$x < $index;$x++)
  2.     if($arr[$x] == $this->clistarray[0][$i]) $f = 1;
  3. if($f) continue;
  4. $arr[$index++] = $this->clistarray[0][$i];
  5. if($articleadded == 0) 
  6.     {
  7.         $articleadded = 1;
  8.         $this->enter_article($today);
  9.     }    
  10. printf("<br><b>Article has keyword </b> %s corresponding to country_id %d",$this->clistarray[1][$i],$this->clistarray[0][$i]);
  11. $t = $this->clistarray[0][$i];
  12. $insvpmainquery = "INSERT INTO `vpmain` ( `vpmain_id` , `article_id` , `country_id` ) VALUES ('', '$this->articleid', '$t')";
  13. mysql_query($insvpmainquery);
  14.  
Jan 31 '08 #1
2 1582
Markus
6,050 Recognized Expert Expert
Expand|Select|Wrap|Line Numbers
  1. for($x = 0;$x < $index;$x++)
  2.     if($arr[$x] == $this->clistarray[0][$i]) $f = 1;
  3. if($f) continue;
  4. $arr[$index++] = $this->clistarray[0][$i];
  5. if($articleadded == 0) 
  6.     {
  7.         $articleadded = 1;
  8.         $this->enter_article($today);
  9.     }    
  10. printf("<br><b>Article has keyword </b> %s corresponding to country_id %d",$this->clistarray[1][$i],$this->clistarray[0][$i]);
  11. $t = $this->clistarray[0][$i];
  12. $insvpmainquery = "INSERT INTO `vpmain` ( `vpmain_id` , `article_id` , `country_id` ) VALUES ('', '$this->articleid', '$t')";
  13. mysql_query($insvpmainquery);
  14.  
Here's my shot:

Expand|Select|Wrap|Line Numbers
  1. for($x = 0;$x < $index;$x++)
  2. {
  3.     if($arr[$x] == $this->clistarray[0][$i]) 
  4.     {
  5.         $f = 1;
  6.     }
  7.     if($f)
  8.     {
  9.         continue;
  10.     }
  11.     $arr[$index++] = $this->clistarray[0][$i];
  12.     if($articleadded == 0) 
  13.     {
  14.         $articleadded = 1;
  15.         $this->enter_article($today);
  16.     }    
  17. printf("<br><b>Article has keyword </b> %s corresponding to country_id %d",$this->clistarray[1][$i],$this->clistarray[0][$i]);
  18. $t = $this->clistarray[0][$i];
  19. $insvpmainquery = "INSERT INTO `vpmain` ( `vpmain_id` , `article_id` , `country_id` ) VALUES ('', '$this->articleid', '$t')";
  20. mysql_query($insvpmainquery);
  21.  
Jan 31 '08 #2
mauricioarango
5 New Member
thanks so much for your suggestion.
I tried implementing it, but then I got another series of errors. This is part of a larger project, so there are many interconnected operations. Thus, any change here provokes something else elsewhere.
I am tempted to leave things as they are: The code I have is uncommented, and sometimes doesn't use the curly braces, so it is really hard to guess what's things are supposed to do and at times, it is hard to read.
Thanks for everything though.
Feb 1 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

21
12922
by: deko | last post by:
Do I need to use curly brackets in PHP if .. else statements? other constructs? Does it matter? What are Best Practices? Why? thanks in advance... This seems to work WITHOUT curly brackets:...
8
6821
by: Ken in Melbourne Australia | last post by:
If I use the curly bracket syntax (referred to as the complex syntax) within a string, how do I get to call a function within it? The php manual says that the first (or previous) character for...
0
2946
by: Dustin D. | last post by:
Let's say I have a text file with the following: food { fruits { apples oranges pears } dairy { ice_cream {
1
2090
by: Geathaa | last post by:
Hello everyone, I'm using Xalan for some XSLT transformations. I could have sworn that some template I wrote worked some time ago, but suddenly it doesnt seem to work any more ...? Whatever the...
6
6620
by: STF | last post by:
While reading the C++ tutorial in this page: http://www.cplusplus.com/doc/tutorial/tut2-2.html I'm astonished to learn that we could omit curly brackets in function declaration for single...
4
3666
by: JavaGeekRoyR | last post by:
Hello all.. In the VS.Net IDE, is there a way to auto-format your code (such that the curly braces for code blocks automatically align, code is automatically indented to proper levels etc)? If...
5
3552
by: krbyxtrm | last post by:
Hi is there a way to 'manage' function execution using macros? #define MY_CALL_MACRO(MacroName) { g_MacroStack.push_back(MacroName); <some code here...>} such that when i use the...
5
8897
by: TJ | last post by:
I'd like to know how the preprocessor treats curly braces, as compared to how it treats parentheses. What happens if I pass this: { a_function( arg1, arg2, arg3 ) } as an argument to a...
3
5346
by: Grande News | last post by:
Hi, I've got some PHP code that looks like this $cura= ord($data{$pnum*2}); $curb = ord($data{$pnum*2+1}); Notice the curly braces -- does using them make any difference, or will square...
0
7074
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7322
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7451
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.