Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/265159-help-with-a-syntax-error/
Share on other sites

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

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.