Jump to content

Can you help figure this out?


CrashOkami

Recommended Posts

Hello everyone.

 

So I got an image slider which I want to display news with descriptions etc, and everything's fine, but I can't make the main image a link to the article, because I get mixed up with "echo". I'm a beginner, so I'm asking for your help  :D

 

The code is:

 

<li>

  <h3><?php echo "$slide_title[5]"; ?></h3>

<span><?php echo "$slide_image[5]"; ?></span>

<p><?php echo "$slide_sdesc[5]";?></p>

<?php "<a href=\"news.php?News_ID=".$News_ID."\">Read the article</a>";?>

<?php echo '<img src="'. $slide_image[5].'" alt ="$slide_title[5]" width="125" height="75"/>' ;?>

</li>

 

As you see, everything is alright code-wise, but it doesn't work how it should. Because, where <a href> ends (@ Read the article </a>), is the wrong place to end. </a> should be placed just before the </li>, and after the "echo img" line of code. Meaning, it should look like this (it's wrong, I know, just to help you understand):

 

<li>

  <h3><?php echo "$slide_title[5]"; ?></h3>

<span><?php echo "$slide_image[5]"; ?></span>

<p><?php echo "$slide_sdesc[5]";?></p>

<?php "<a href=\"news.php?News_ID=".$News_ID."\">Read the article

<?php echo '<img src="'. $slide_image[5].'" alt ="$slide_title[5]" width="125" height="75"/>' ;?>

</a>";?>

</li>

 

Thank you for your help :)

Link to comment
Share on other sites

Please use code tags round your code.

 

Did you mean something like this?

<?php  
echo <<< TXT
    <ul>
        <li>  
        <h3>{$slide_title[5]}</h3> 
        <span>{$slide_image[5]}</span> 
        <p>$slide_sdesc[5]</p> 
        <a href="news.php?News_ID=$News_ID">Read the article
        <img src="$slide_image[5]" alt="{$slide_title[5]}" width="125" height="75"/></a>
        </li>
    </ul>
TXT;
?>

Link to comment
Share on other sites

I'm sorry, I forgot to preview it and now I can't edit it to display it properly.

 

Yes, in the structure you posted it, although that piece of code is not functioning for some reason. I've not included the LI in the php code, just the variables inside it.

 

<li>
  	<h3><?php echo "$slide_title[5]"; ?></h3>
<span><?php echo "$slide_image[5]"; ?></span>
        <p><?php echo "$slide_sdesc[5]";?></p>
<?php "<a href=\"news.php?News_ID=".$News_ID."\">Read the article</a>";?>
<?php echo '<img src="'. $slide_image[5].'" alt ="$slide_title[5]" width="125" height="75"/>' ;?>
</li>

 

I need it to be like this, but change the last 2 lines (not including </li>), so that </a> is placed after the <img /> tag. I need to make the <img /> line a link to the article - of course, if there's any other method of doing it, it's absolutely welcome. I just can't think of one.

Link to comment
Share on other sites

I've an update on the code. I think I've figured out the php, but I get some (I believe) minor issues, which I can't figure out.

 

284. <?php echo "<a href=news.php?News_ID=".$News_ID.'>
285. <img src="'.$slide_image[5].'" alt ='$slide_title[5]' width='125' height='75'>";
286. echo "'>Read the article</a>'";?>

 

I've numbered the lines for a reason. I get error message:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in C:\xampp\htdocs\starblindsite\index.php on line 285. Am I close to fixing this? Thanks!

Link to comment
Share on other sites

Nevermind, got it to work. It's prompting me to my news template now, all fields entered. In case anyone needs help with the matter, I'll post the correct code below:

 

<li>
  			<h3><?php echo "$slide_title[5]"; ?></h3>
		<span><?php echo "$slide_image[5]"; ?></span>
		<p><?php echo "$slide_sdesc[5]";?></p>
		<?php echo "<a href=news.php?News_ID=".$News_ID.">
		<img src=".$slide_image[5]." alt ='$slide_title[5]' width='125' height='75'>
		echo Read the article</a>";?>
	</li>

 

Of course, it's using my variables, but they're easy to figure out. Also, please excuse my double post, I hope it's no problem. Cheers!

Link to comment
Share on other sites

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.