icue Posted July 3, 2012 Share Posted July 3, 2012 Hi, Could I get some help with a syntax error that I can't seem to find? The following is an original section from a script I found to create a live search: while ($result = $query ->fetch_object()) { if($result->cat_id != $catid) { // check if the category changed echo '<span class="category">'.$result->cat_name.'</span>'; $catid = $result->cat_id; $id = $result->cat_id; } echo '<a class=\"fancybox fancybox.iframe\" href="'.$result->url.'"</a>'; echo '<img width="40" height="40" src="images/all/'.$result->img.'" alt="" />'; I need to be able to pass the value of id to the page opened by the fancybox, so I added the following: $id = $result->id; after line 5 ($id = $result->cat_id;) and, ?venue_name=$id as in the line below. echo '<a class=\"fancybox fancybox.iframe\" href=".$result->url.?venue_name=$id."</a>'; This does not work because it gives venue_name the value $id and not the numeric value of $id. I have tried various combination of quotes as in the line below: echo '<a class=\"fancybox fancybox.iframe\" href="'.$result->url.'?'venue_name=$id'"</a>'; but now I am getting syntax errors unexpected T_STRING, expecting ',' or ':' The url for the page is stored in the database (pop_up.php) but I would like to be able to include it in the script so I don't have to enter it multiple times in the database. Could someone please offer some advice. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/265159-help-with-a-syntax-error/ Share on other sites More sharing options...
boompa Posted July 3, 2012 Share Posted July 3, 2012 Check your single quotes and concatenation on this line: echo '<a class=\"fancybox fancybox.iframe\" href=".$result->url.?venue_name=$id."</a>'; Quote Link to comment https://forums.phpfreaks.com/topic/265159-help-with-a-syntax-error/#findComment-1358822 Share on other sites More sharing options...
icue Posted July 3, 2012 Author Share Posted July 3, 2012 Hi, I have tried many combinations of quote and concatenation but still getting an error. This is what I have at the moment but still getting errors. echo '<a class=\"fancybox fancybox.iframe\" href="'.$result->url.'?'venue_name=$id'"</a>'; Could someone please help. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/265159-help-with-a-syntax-error/#findComment-1358837 Share on other sites More sharing options...
Jessica Posted July 3, 2012 Share Posted July 3, 2012 Please use code tags. <?php echo '<a class=\"fancybox fancybox.iframe\" href="'.$result->url.'?'venue_name=$id'"</a>'; ?> You might be able to see the error with the syntax highlighting helping you. Strings are red. You have text that should be within the string that isn't red. You also aren't concatenating the second variable. Also, you don't have to escape a double quote when your string is in single quotes. Quote Link to comment https://forums.phpfreaks.com/topic/265159-help-with-a-syntax-error/#findComment-1358838 Share on other sites More sharing options...
Pikachu2000 Posted July 3, 2012 Share Posted July 3, 2012 And why are you escaping double quotes in a single-quoted string? Quote Link to comment https://forums.phpfreaks.com/topic/265159-help-with-a-syntax-error/#findComment-1358872 Share on other sites More sharing options...
icue Posted July 3, 2012 Author Share Posted July 3, 2012 Hi, Thanks everyone I finally got it working with the following: <?php echo '<a class="fancybox fancybox.iframe" href="'.$result->url.'?venue_name='.$id.'"</a>'; ?> I am still very new to PHP so I am making a lot of mistakes. My database has well over 100 entries and growing so could someone please give me a pointer as to how I can include the url in the script instead of the database. Assuming that I posted enough code in my original post. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/265159-help-with-a-syntax-error/#findComment-1358899 Share on other sites More sharing options...
Pikachu2000 Posted July 3, 2012 Share Posted July 3, 2012 Please, when posting code, enclose it within the forum's . . . BBCode tags. It makes is easier for the people trying to help you to provide better answers when the code is easily readable. Quote Link to comment https://forums.phpfreaks.com/topic/265159-help-with-a-syntax-error/#findComment-1358906 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.