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
https://forums.phpfreaks.com/topic/264323-can-you-help-figure-this-out/
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;
?>

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.

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!

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!

Archived

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

×
×
  • 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.