Godoploid_Design Posted May 3, 2011 Share Posted May 3, 2011 I know this has to be something simple but I can not figure out for the life of me why this keeps happening. I have used these syntaxs many times before and never got this result. <?php $ifav = explode(","$ufav); foreach($ifav as& $f) { $cfavor = mysql_query("SELECT * FROM company WHERE cid = '$f'"); while($cfav = mysql_fetch_array($cfavor)) { $fcid = $cfav['cid']; $fcname = $cfav['cname']; $fcity = $cfav['city']; $fstate = $cfav['state']; $favorite .= '<p>' . $fcid . '. <a target="_blank" href="list.php?cid=' . $fcid . '">' . $fcname . '</a> ' . $fcity . ', ' . $fstate . '</p>'; } } ?> I have a column in a database where there are comma separated values. I wanted to take those values($ufav) and explode them into separate values where I could then take action on them. For this I ran an explode() then a foreach loop grabbing the exploded values where i queried the database multiple times in order to grab all of the information related to the comma separated values. From there I put the information into a variable and then echoed it out into the page where I required this entire value. Everytime I run this code I get this error: Parse error: syntax error, unexpected T_VARIABLE in /home/content/11/7370211/html/sites/searchapartmentsonline/development/includes/user/fav.php on line 3 Which is this line of code: $ifav = explode(","$ufav); This has to be simple and has driven absolutely nuts because I can't figure out for the life of me why this code is returning this error. If you could help I would greatly appreciate it! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/235402-i-keep-getting-a-unexpected-t-variable-error/ Share on other sites More sharing options...
gizmola Posted May 3, 2011 Share Posted May 3, 2011 Yes it is simple. explode Notice that you need arguments and a COMMA between them. Quote Link to comment https://forums.phpfreaks.com/topic/235402-i-keep-getting-a-unexpected-t-variable-error/#findComment-1209756 Share on other sites More sharing options...
Godoploid_Design Posted May 3, 2011 Author Share Posted May 3, 2011 Thanks Gizmola, after looking at what you said I went through and rechecked my syntax. I moved all of the code from inline to a require file and somehow must have deleted the comma somehow thanks!!! Quote Link to comment https://forums.phpfreaks.com/topic/235402-i-keep-getting-a-unexpected-t-variable-error/#findComment-1209760 Share on other sites More sharing options...
gizmola Posted May 3, 2011 Share Posted May 3, 2011 Sure. A decent editor that supports PHP should offer color syntax highlighting where errors like that will jump out at you. In this case you'd need one that has function definitions for the standard libraries. Quote Link to comment https://forums.phpfreaks.com/topic/235402-i-keep-getting-a-unexpected-t-variable-error/#findComment-1209762 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.