1

I have a problem because I cannot call my data that I want to retrieve on a video src and image src. here is my code. image and video src are not showing. can someone give me the correct syntax, please? thanks

few questions, do I need to concatenate something? do my rows[''] are concatenate correctly?

but my main problem here is I cannot click or change any videos that are retrieved or stored. how can I fix the onClick? thanks

    <?php 


echo '<li>
<a href="javascript:void();" onClick="document.getElementById("vid_frame").src="images/promvid/pal/<?php row['videos']  ?>">

<span class="vid-thumb">
<img width=72 src="images/promvid/philippines.jpg"/<?php row['image']  ?>
</span>

<div class="desc">Philippines<?php  row['title']  ?>
</div></a></li>';

     ?>

MY ERROR

Parse error: syntax error, unexpected 'videos' (T_STRING), expecting ',' or ';

Sayed Mohd Ali
  • 2,156
  • 3
  • 12
  • 28

3 Answers3

1

You cannot use PHP tags inside PHP tags you need to concatenate the string part with variable using echo.

 <?php 


    echo '<li>
    <a href="javascript:void();" onClick="document.getElementById("vid_frame").src="images/promvid/pal/'.$row['videos'].'">

    <span class="vid-thumb">
    <img width=72 src="images/promvid/philippines.jpg"/'.$row['image'].' </span>

    <div class="desc">Philippines'.$row['title'].'    </div></a></li>';

         ?>
Sayed Mohd Ali
  • 2,156
  • 3
  • 12
  • 28
1

This below code may help you.

In php we need use the variable by using $

echo '<li>
        <a href="javascript:void();" 
            onClick="document.getElementById("vid_frame").src="images/promvid/pal/"'.$row["videos"].'>

            <span class="vid-thumb">
                <img width=72 src="images/promvid/philippines.jpg/"'.$row['image'].'>
            </span>

            <div class="desc">Philippines'.$row['title'].'</div>
        </a>
    </li>';
Ramya
  • 199
  • 10
0

You are using bad practice and run into errors. You cannot have <?php ?> tags within <?php ?> tags.

Write clean code and make good practice to a habit.

  • PHP is an embedded language. Do not try to generate all HTML by PHP echo. Embed peaces of PHP code into a surrounding HTML template. You can even close PHP tags within a block of loop constructs.

  • Variables standing alone in a PHP tag are not output, except you are using shot-open tags <?=$variable?>. Short-open tags should not be used since most server configurations do not enable them.

  • Inline JavaScript is old school and considered to be bad practice. First of all inline on-handlers might be removed from the standards some day. Use event listeners instead.

  • You have block elements div inside the inline element a. This is valid only in HTML5. Ensure that your document type explicitly is HTML5 by prepending <!DOCTYPE html> as the very first line in the document.

  • Links doing nothing has been widely discussed if the href attribute should be # or javascript:void(0);. I tend to the latter. void is a keyword, however, the function style is fine. Regardless to the code style there has to be an argument.

    • even better: Do not use non-linking links at all. Use links with a valid fallback URL instead. In the event handler you can call the preventDefault() method wich will prevent the href action, i.e. location change.

PHP site:

<head>
  <title>Non-Empty Title</title>

<body>

  <ul>

  <?php
    // fake query result
    $rows =
    [
      [
        'videos'              => 'phillippines.mpeg4',
        'image'               => 'philippines.jpg' ,
        'title'               => 'Philippines'     ,
        'noscript-frame-page' => 'philippines.html',
      ],
      [
        'videos'              => 'usa.mpeg4',
        'image'               => 'usa.jpg' ,
        'title'               => 'USA'     ,
        'noscript-frame-page' => 'usa.html',
      ]
    ];

    // fake fetch row
    foreach ($rows as $row)
    {
  ?>

    <li>
      <a class="video-ref"
         href="<?php echo $row['noscript-frame-page'];?>"
         data-video-src="images/promvid/pal/<?php echo $row['videos'];?>"
         target="video-frame"
      >
        <span class="vid-thumb">
          <img width=72 src="images/promvid/"<?php echo $row['image'];?>
        </span>

        <div class="desc"><?php echo $row['title'];?>
        </div>
      </a>
    </li>

  <?php
    }
  ?>

  </ul>

  <noscript>
    <iframe id="video-frame" name="video-frame" src="start-video-page.html"></iframe>
  </noscript>

  <div id="debug">DEBUG OUTPUT</div>

  <script src="my-script.js"></script>

my-script.js

document.addEventListener('DOMContentLoaded', evt =>
{
  "use strict";
  const VideoLinkListener = evt =>
  {
    const videoSrc = evt.currentTarget.getAttribute('data-video-src');
    if(videoSrc)
    {
      document.getElementById('debug').innerHTML = videoSrc;  // document.getElementById('vid_frame').src=videoSrc;

      // do not change location to link's href
      evt.preventDefault();
    }
  };

  document.querySelectorAll('a.video-ref').forEach( link => link.addEventListener('click', VideoLinkListener) );
});
Pinke Helga
  • 6,378
  • 2
  • 22
  • 42