Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9190069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:22:39+00:00 2026-06-17T20:22:39+00:00

I am trying to set each image name as a hyperlink. But problem is

  • 0

I am trying to set each image name as a hyperlink. But problem is I am receiving 3 errors, 2 are undefined erros and the other one is expecting 1 parameter.

Current code which is not working:

    <table id="tableqanda" cellpadding="0" cellspacing="0">
    <thead>
    <tr>
        <th width="11%" class="image">Image</th>
    </tr>
    </thead>
    </table>
    <div id="tableqanda_onthefly_container">
    <table id="tableqanda_onthefly" cellpadding="0" cellspacing="0">
    <tbody>
        <?php
        
function imageName( $imgitem ) {
    return htmlspecialchars($imgitem); //432
}

        
          foreach ($arrQuestionId as $key=>$question) {
        echo '<tr class="tableqandarow">'.PHP_EOL;
        echo '<td width="11%" class="imagetd">';
        
        if (empty($arrImageFile[$key])) {
            echo '&nbsp;';
        } else {
    echo '<ul class="qandaul"><li><a href="previewImage.php?imgId=[' . $imgitem . ']" target="_blank">'; //line 456
    echo implode('</li>\n<li></a><a href="previewImage.php?imgId=[' . $imgitem . ']" target="_blank">', imageName($arrImageFile[$key]) ); //line 457
    echo '</li></ul></a>';
        }
        echo '</td>';
        echo '</tr>'.PHP_EOL;
        }
?>
    </tbody>
    </table>
    </div>

Errors received:

Warning: htmlspecialchars() expects parameter 1 to be string, array given in … on line 432

Notice: Undefined variable: imgitem in … on line 456

Notice: Undefined variable: imgitem in … on line 457


Formatted Code:

<table id="tableqanda" cellpadding="0" cellspacing="0">
    <thead>
        <tr>
            <th width="11%" class="image">Image</th>
        </tr>
    </thead>
</table>
<div id="tableqanda_onthefly_container">
    <table id="tableqanda_onthefly" cellpadding="0" cellspacing="0">
        <tbody>
            <?php
                function imageName( $imgitem ) {
                    return htmlspecialchars($imgitem); //432
                }
                foreach ($arrQuestionId as $key=>$question) {
                    echo '<tr class="tableqandarow">'.PHP_EOL;
                    echo '<td width="11%" class="imagetd">';
                    if (empty($arrImageFile[$key])) {
                        echo '&nbsp;';
                    } else {
                        echo '<ul class="qandaul"><li><a href="previewImage.php?imgId=[' . $imgitem . ']" target="_blank">'; //line 456
                        echo implode('</li>\n<li></a><a href="previewImage.php?imgId=[' . $imgitem . ']" target="_blank">', imageName($arrImageFile[$key]) ); //line 457
                        echo '</li></ul></a>';
                    }
                    echo '</td>';
                    echo '</tr>'.PHP_EOL;
                }
            ?>
        </tbody>
    </table>
</div>

var_dump results:

From the var_dump specified the results are below:

array(2) { 
  [72]=> array(2) { 
    [0]=> string(16) "Lighthouse_4.jpg" 
    [1]=> string(12) "Tulips_3.jpg" 
  } 
  [73]=> array(1) { 
    [0]=> string(16) "Hydrangeas_3.jpg" 
  } 
}
int(73)

UPDATE:

With Praveen’s code I am getting an error stating:

Fatal error: Cannot redeclare imageName() (previously declared in ...:451) in ... on line 451

Below is code:

<table id="tableqanda" cellpadding="0" cellspacing="0">
    <thead>
        <tr>
            <th width="11%" class="image">Image</th>
        </tr>
    </thead>
</table>
<div id="tableqanda_onthefly_container">
    <table id="tableqanda_onthefly" cellpadding="0" cellspacing="0">
        <tbody>
  //line 451          <?php function imageName( $imgitem ) { return htmlspecialchars($imgitem);
            } foreach ($arrQuestionId as $key=>$question) { echo '
            <tr class="tableqandarow">'.PHP_EOL; echo '
                <td width="11%" class="imagetd">'; function imageName( $imgitem ) { return htmlspecialchars($imgitem);
                    function getImgLink ( $imgKey ) { return $imgKey[0]; if (empty($arrImageFile[$key]))
                    { echo '&nbsp;'; } else { echo '
                    <ul class="qandaul">
                        <li>
                            <a href="previewImage.php?imgId=[' . getImgLink($arrImageFile($key)) . ']"
                            target="_blank">'; echo implode('</li>\n
                        <li>
                            </a>
                            <a href="previewImage.php?imgId=[' . getImgLink($arrImageFile($key)) . ']"
                            target="_blank">', imageName($arrImageFile[$key]) ); echo '</li>
                    </ul>
                    </a>'; } echo '</td>'; } } echo '</tr>'.PHP_EOL; } ?></tbody>
    </table>
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:22:40+00:00Added an answer on June 17, 2026 at 8:22 pm

    There are many errors!!!

    1. Where have you defined $imgitem?
    2. Why are you implodeing a string?
    3. Why are you closing the function prematurely, and using the variables there in the code out of the function?
    4. Where is the $arrImageFile defined?
    5. Finally, What are you trying to do?

    Other errors…

    function imageName( $imgitem ) {
        return htmlspecialchars($imgitem); //432
    }
    ///////////////////////////////////////////////////////////////////
    // You are closing the function here, hence the $imgitem's scope //
    ///////////////////////////////////////////////////////////////////
    
    
              foreach ($arrQuestionId as $key=>$question) {
            echo '<tr class="tableqandarow">'.PHP_EOL;
            echo '<td width="11%" class="imagetd">';
    
            if (empty($arrImageFile[$key])) {
                echo '&nbsp;';
            } else {
        echo '<ul class="qandaul"><li><a href="previewImage.php?imgId=[' . $imgitem . ']" target="_blank">'; //line 456
    ////////////////////////////////////////////////////
    // The $imgitem's variable is not accessible here //
    ////////////////////////////////////////////////////
    
        echo implode('</li>\n<li></a><a href="previewImage.php?imgId=[' . $imgitem . ']" target="_blank">', imageName($arrImageFile[$key]) ); //line 457
    ////////////////////////////////////////////////////////////////////////////
    // Why are you trying to implode something like this? Not a right syntax! //
    ////////////////////////////////////////////////////////////////////////////
        echo '</li></ul></a>';
            }
            echo '</td>';
            echo '</tr>'.PHP_EOL;
            }
    

    Update

    <table id="tableqanda" cellpadding="0" cellspacing="0">
        <thead>
            <tr>
                <th width="11%" class="image">Image</th>
            </tr>
        </thead>
    </table>
    <div id="tableqanda_onthefly_container">
        <table id="tableqanda_onthefly" cellpadding="0" cellspacing="0">
            <tbody>
                <?php
                    function imageName( $imgitem ) {
                        return htmlspecialchars($imgitem); //432
                    }
    ----------------^
    ///////////////////////////////////////////////////////////////////
    // You are closing the function here, hence the $imgitem's scope //
    ///////////////////////////////////////////////////////////////////
    
                    foreach ($arrQuestionId as $key=>$question) {
                        echo '<tr class="tableqandarow">'.PHP_EOL;
                        echo '<td width="11%" class="imagetd">';
                        if (empty($arrImageFile[$key])) {
                            echo '&nbsp;';
                        } else {
                            echo '<ul class="qandaul"><li><a href="previewImage.php?imgId=[' . $imgitem . ']" target="_blank">'; //line 456
    -------------------------------------------------------------------------------------------^
    /////////////////////////////////////
    // Where have you defined $imgitem //
    /////////////////////////////////////
    
                            echo implode('</li>\n<li></a><a href="previewImage.php?imgId=[' . $imgitem . ']" target="_blank">', imageName($arrImageFile[$key]) ); //line 457
    ------------------------------------------------------------------------------------------^
    /////////////////////////////////////
    // Where have you defined $imgitem //
    /////////////////////////////////////
    
                            echo '</li></ul></a>';
                        }
                        echo '</td>';
                        echo '</tr>'.PHP_EOL;
                    }
                ?>
            </tbody>
        </table>
    </div>
    

    Based on the output of var_dump, I feel that you need to add another function to get the links of the image, as it is always present in the 0th index.

    function getImgLink ( $imgKey )
    {
        return $imgKey[0];
    }
    

    And now, use it this way:

    <a href="previewImage.php?imgId=[' . getImgLink($arrImageFile($key)) . ']" target="_blank">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a set of thumbnails, each one separately downscaled from the
I'm trying to set up a query that shows the first post of each
Trying to set it so if a certain condition is met then one of
Im trying to set the certificate friendly name during the certificate request/acceptance process. I
I'm trying to set up a page that looks like the image below. Here's
Im trying set the single table inheritance model type in a form. So i
Trying to set up a self signed certificate, for our intranet's web services site.
Trying to set up a dependency in C++ with a parent-child relationship. The parent
Trying to set up a new project, and running into a weird issue. I
Trying to set a flag in the post to allow processing or not. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.