Xtremer360 Posted June 20, 2012 Share Posted June 20, 2012 Any ideas on how to fix this line with syntax errors present? <?php $image_properties=array( 'src'=> if ( ! empty ($this->session->userdata('avatar') ) ) { 'assets/peach/img/sprites/userinfo/'.$this->session->userdata('avatar').'; } else { 'assets/peach/img/sprites/userinfo/avatars/avatar.png'; } , 'height' => '80px', 'width' => '80px', 'alt' => 'Avatar' ); ?> Quote Link to comment Share on other sites More sharing options...
ultimatum Posted June 20, 2012 Share Posted June 20, 2012 $this->session->userdata('avatar').'; } In here take out period and semi-colon after ('avatar') Besides that placing conditions inside an array makes it much harder to read the code. Quote Link to comment Share on other sites More sharing options...
cpd Posted June 20, 2012 Share Posted June 20, 2012 Yeah, it's called debugging and you don't do it by sticking the whole thing on one line. Split everything up as follows: <?php $image_properties=array( 'src'=> if(!empty ($this->session->userdata('avatar') ) ) { 'assets/peach/img/sprites/userinfo/'.$this->session->userdata('avatar').'; } else { 'assets/peach/img/sprites/userinfo/avatars/avatar.png'; }, 'height' => '80px', 'width' => '80px', 'alt' => 'Avatar' ); ?> Having spaced it out I can see you have a wack-off if statement in the middle of your bloody array. Not allowed, you've got to use an inline-if statement: <?php $image_properties=array( 'src'=> (!empty ($this->session->userdata('avatar') ) ) : 'assets/peach/img/sprites/userinfo/'.$this->session->userdata('avatar') ? 'assets/peach/img/sprites/userinfo/avatars/avatar.png'), 'height' => '80px', 'width' => '80px', 'alt' => 'Avatar' ); ?> Quote Link to comment Share on other sites More sharing options...
cpd Posted June 21, 2012 Share Posted June 21, 2012 <?php $image_properties=array( 'src'=> (!empty ($this->session->userdata('avatar') ) ) ? 'assets/peach/img/sprites/userinfo/'.$this->session->userdata('avatar') : 'assets/peach/img/sprites/userinfo/avatars/avatar.png'), 'height' => '80px', 'width' => '80px', 'alt' => 'Avatar' ); ?> Sorry I put the colon and question mark the wrong way round. You also had an addition concatenation symbol and single apostrophe somewhere around the previous if statement; that's now been taken out. Quote Link to comment Share on other sites More sharing options...
xyph Posted June 21, 2012 Share Posted June 21, 2012 Still messed it up. Too many closing brackets on line 4 Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted June 21, 2012 Author Share Posted June 21, 2012 Yeah I'm still stuck on what the real solution should be? Quote Link to comment Share on other sites More sharing options...
xyph Posted June 21, 2012 Share Posted June 21, 2012 It's been provided, and I've noted the single mistake in the code, which any code-highlighting editor makes obvious Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted June 21, 2012 Author Share Posted June 21, 2012 I corrected this line but not it says there's an issue on the line below it. 'src' => (!empty ($this->session->userdata('avatar') Quote Link to comment Share on other sites More sharing options...
xyph Posted June 21, 2012 Share Posted June 21, 2012 That's not corrected. After 1,300 posts, you really should be getting this kinda stuff. This is an issue that's pretty much solved for you if you're using an editor that matches brackets. Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted June 21, 2012 Author Share Posted June 21, 2012 I've added and subtracted braces for that line only and still keep getting an error Quote Link to comment Share on other sites More sharing options...
xyph Posted June 21, 2012 Share Posted June 21, 2012 Then you're doing something wrong. <?php $check = TRUE; $array = array( 'key' => ($check ? 'foo' : 'bar'), 'cas' => 'bah' ); print_r($array); ?> returns Array ( [key] => foo [cas] => bah ) It's a PEBCAK issue. You haven't even told us what error you're getting, nor the code you're trying. Best of luck. Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted June 21, 2012 Author Share Posted June 21, 2012 I'm still trying to figure out the syntax error in this code just like my post has said: $image_properties = array( 'src' => (!empty ($this->session->userdata('avatar') : 'assets/peach/img/sprites/userinfo/'.$this->session->userdata('avatar') ? 'assets/peach/img/sprites/userinfo/avatars/avatar.png'), 'height' => '80px', 'width' => '80px', 'alt' => 'Avatar' ); ?> Quote Link to comment Share on other sites More sharing options...
xyph Posted June 21, 2012 Share Posted June 21, 2012 Try counting. Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted June 21, 2012 Author Share Posted June 21, 2012 Okay so now there's an issue with : 'assets/peach/img/sprites/userinfo/'.$this->session->userdata('avatar') <?php $image_properties = array( 'src' => (!empty ($this->session->userdata('avatar') : 'assets/peach/img/sprites/userinfo/'.$this->session->userdata('avatar') ? 'assets/peach/img/sprites/userinfo/avatars/avatar.png'), 'height' => '80px', 'width' => '80px', 'alt' => 'Avatar' ) ); Quote Link to comment Share on other sites More sharing options...
xyph Posted June 21, 2012 Share Posted June 21, 2012 No, there isn't. You've thrown a closing bracket in the wrong place. You're more than welcome to keep guessing the solution, but I think I'm through with saying you've guessed wrong. Best of luck, my suggestion is to hire a programmer if you want the job done, or go back to the basics if you actually want to learn. Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted June 21, 2012 Author Share Posted June 21, 2012 I'm so confused here. Quote Link to comment Share on other sites More sharing options...
Jessica Posted June 21, 2012 Share Posted June 21, 2012 If you're having that much trouble with this one, try formatting it more simply at first. This is a complex line of code the way you have it and you aren't able to spot the error. Here's your code made more simple IMO. I left in your error, and moved the ternary stuff out of the array and into an if. Do you see the error now? <?php $src = 'assets/peach/img/sprites/userinfo/avatars/avatar.png'; if(!empty($this->session->userdata('avatar'))){ $src = 'assets/peach/img/sprites/userinfo/'.$this->session->userdata('avatar'); } $image_properties = array( 'src' => $src, 'height' => '80px', 'width' => '80px', 'alt' => 'Avatar' ) ); Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted June 21, 2012 Author Share Posted June 21, 2012 I honestly wish I did but I don't I'm starring at it and simply don't. Quote Link to comment Share on other sites More sharing options...
Jessica Posted June 21, 2012 Share Posted June 21, 2012 Then rewrite it from scratch, no copying and pasting, and maybe you won't make the same mistake. Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted June 21, 2012 Author Share Posted June 21, 2012 I tried this but got a "cannot use method return value" error on that src line: $image_properties = array( 'src' => (!empty ($this->session->userdata('avatar') ) ) ? 'assets/peach/img/sprites/userinfo/'.$this->session->userdata('avatar') : 'assets/peach/img/sprites/userinfo/avatars/avatar.png') 'height' => '80px', 'width' => '80px', 'alt' => 'Avatar' ); Quote Link to comment Share on other sites More sharing options...
Jessica Posted June 21, 2012 Share Posted June 21, 2012 Well that's an entirely new error, and you should be able to compare the old one to see the original error. empty() works on variables, and you're using a method which probably returns nothing if it's empty. So there's no variable. Quote Link to comment Share on other sites More sharing options...
xyph Posted June 21, 2012 Share Posted June 21, 2012 Well that's an entirely new error, and you should be able to compare the old one to see the original error. empty() works on variables, and you're using a method which probably returns nothing if it's empty. So there's no variable. Or he's not counting the parentheses Quote Link to comment Share on other sites More sharing options...
Jessica Posted June 21, 2012 Share Posted June 21, 2012 Ah, I saw the one extra one was gone and didn't see the new one. I think OP should abandon the ternary operator for this. Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted June 21, 2012 Author Share Posted June 21, 2012 Topic solved! Solution: <?php $avatar = $this->session->userdata('avatar'); $image_properties = array( 'src' => (!empty ($avatar) ) ? 'assets/peach/img/sprites/userinfo/avatars/'.$this->session->userdata('avatar') : 'assets/peach/img/sprites/userinfo/avatars/avatar.png', 'height' => '80px', 'width' => '80px', 'alt' => 'Avatar' ); ?> Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted June 21, 2012 Author Share Posted June 21, 2012 Why won't it let me mark it as solved? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.