Jump to content

Archived

This topic is now archived and is closed to further replies.

Gruzin

need help with parse error

Recommended Posts

Here is my echo, but think I don't write it right. hope u can help, thanks.

<?php echo '<img alt="" src="'.$imageArr[$imageShow].'">'."".'<a href='".$imageLink[$imageShow]."'>'; ?>

P.S output:

[color=red]Parse error: parse error, unexpected '\"', expecting ',' or ';' in /users/3d_cn/html/banner.php on line 44[/color]

Share this post


Link to post
Share on other sites
[code]echo "<img alt=\"\" src=\"{$imageArr[$imageshow]}\"> <a href=\"{$imagelink[$imageshow]}\">";[/code]

Share this post


Link to post
Share on other sites
Did that solution work? I can see why yours didn't work in the first place but it is hard to find because of the way you use your quotes.

After your href you drop out of your php string before the double quote goes in. And something similar later on too.

Most importantly, you don't need to drop out of strings to include variables which is what businessman was showing.
His code looks even simpler if you combine your quoting methods so you don't have to escape them:

[code]echo '<img alt="" src="{$imageArr[$imageshow]}"> <a href="{$imagelink[$imageshow]}">';[/code]

or

[code]echo "<img alt='' src='{$imageArr[$imageshow]}'> <a href='{$imagelink[$imageshow]}'>";[/code]

I'm not even certain you need the curly braces either. They are for more complicated structures, so possibly. But if the array index isn't a variable then you don't, so possibly not. Can't check right now for you. Try it:

[code]echo "<img alt='' src='$imageArr[$imageshow]'> <a href='$imagelink[$imageshow]'>";[/code]

Sam.

Share this post


Link to post
Share on other sites
well I've tryed that but it doesn't work....

It displays the picture with red cross and an underscore with link:{$imagelink[$imageshow]} (I see it on the status bar)

Share this post


Link to post
Share on other sites
Try using the last posted by Sam:
[code]
<?php
echo "<img alt='' src='$imageArr[$imageshow]'> <a href='$imagelink[$imageshow]'>";
?>
[/code]

because that should work.

Share this post


Link to post
Share on other sites
I tryed but it doesn't work, what's my mistake:(

here is the code:

<?php
$imageArr = array();
$imageArr[1] = "http://www.3d.caucasus.net/apartments/banners/banner1.jpg";
$imageArr[2] = "http://www.3d.caucasus.net/apartments/banners/banner2.jpg";
$imageArr[3] = "http://www.3d.caucasus.net/apartments/banners/banner3.jpg";

$imageLink[1] = "http://www.one.com";
$imageLink[2] = "http://www.two.com";
$imageLink[3] = "http://www.three.com";

$imageShow = array_rand($imageArr);
?>

<?php echo "<img alt='' src='$imageArr[$imageshow]'> <a href='$imagelink[$imageshow]'>"; ?>

P.S Here you can see the site, with that error:
http://www.3d.caucasus.net

Share this post


Link to post
Share on other sites
The problem is to do with capitalisation. $imageshow is not the same as $imageShow.

change the line to:
<?php echo "<img alt='' src='$imageArr[$imageShow]'> <a href='$imageLink[$imageShow]'>"; ?>

Share this post


Link to post
Share on other sites
I've done it but the picture is not linked........

Share this post


Link to post
Share on other sites
New topic because?

This is your html. You need to nest the image inside of the link tags:
<?php echo "<a href='$imageLink[$imageShow]'><img alt='' src='$imageArr[$imageShow]'></a>";

Share this post


Link to post
Share on other sites
sorry for the new topic, it's not my fault, I was trying to post and there was an error (I"ll remove this topic)

Here u can see the result, think it's not working correctly, thanks anyway

http://www.3d.caucasus.net

Share this post


Link to post
Share on other sites
Topic has been merged. Please do not post now topics for no reason.

Share this post


Link to post
Share on other sites
Just remove the [/url] part. This forum puts it on after you have a url for some reason.

Share this post


Link to post
Share on other sites
ok thanks guys, Think I have to work on myself

Share this post


Link to post
Share on other sites
I assumed you had a </a> somewhere later. Do you?

Share this post


Link to post
Share on other sites

×

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.