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 6764029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:32:46+00:00 2026-05-26T14:32:46+00:00

I just asked another question here: global variable and reduce database accesses in PHP+MySQL

  • 0

I just asked another question here: global variable and reduce database accesses in PHP+MySQL
I am using PHP+MySQL. The page accesses to the database and retrieve all the item data, and list them. I was planning to open a new page, but now I want to show a pop div using javascript instead. But I have no idea how to utilize the variables of PHP in the new div. Here is the code:

<html>
</head>
<script type="text/javascript">
function showDiv() {
    document.getElementById('infoDiv').style.visibility='visible';
}
function closeDiv() {
    document.getElementById('infoDiv').style.visibility='hidden';
}
</script>
</head>
<body>
<ul>
<?php foreach ($iteminfos as $iteminfo): ?>
    <li><a href="javascript:showDiv()"><?php echo($iteminfo['c1']); ?></a></li>
<?php endforeach;?>
</ul>
<div id="infoDiv" style="visibility: hidden;">
    <h1><?php echo($c1) ?></h1>
    <p><?php echo($c2) ?></p>
    <p><a href="javascript:closeDiv()">Return</a></p>
</div>
</body>
</html>

“iteminfos” is the results from database, each $iteminfo has two value $c1 and $c2. In “infoDiv”, I want to show the details of the selected item. How to do that?

Thanks for the help!

A further question: if I want to use, for example, $c1 as text, $c2 as img scr, $c1 also as img alt; or $c2 as a href scr, how to do that?

  • 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-05-26T14:32:47+00:00Added an answer on May 26, 2026 at 2:32 pm

    Try this:

    <?php foreach ($iteminfos as $iteminfo): ?>
      <li>
        <a href="javascript:showDiv(<?php echo(json_encode($iteminfo)) ?>)">
          <?php echo($iteminfo['c1']); ?>
        </a>
      </li>
    <?php endforeach;?>
    

    Also, modify showDiv to take your row data:

    function showDiv(row) {
      document.getElementById('infoDiv').style.visibility='visible';
      document.getElementById('infoDiv').innerHTML = row['c1'];
    }
    

    Basically, you have to consider that the javascript runs in the browser long after the PHP scripts execution ended. Therefore, you have to embed all the data your javascript might need into the website or fetch it at runtime (which would make things slower and more complicated in this case).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know I asked a related question earlier. I just had another thought. using
In another question , I asked something similar but I ended up just posting
As a result of another question I asked here I want to use a
This may be the silliest question i have ever asked here, but i just
This question has been asked here in one form or another but not quite
This is an offshoot question that's related to another I asked here . I'm
Just asked a question about linking Boost libraries in the make file. Thanks to
Just asked how to check if an internet connection exists using javascript and got
I just asked this question . Which lead me to a new question :)
yesterday I just asked following question. How to customize tableView Section View - iPhone

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.