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

  • SEARCH
  • Home
  • 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 512695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:20:46+00:00 2026-05-13T07:20:46+00:00

i am calling a javascript for image gallery and php on a single page.

  • 0

i am calling a javascript for image gallery and php on a single page.
let me show you some code to make things clear:

PHP

echo "<form method = post action = 'user_submit.php'>";

// get possible answers using question ID
$query = "SELECT aid, atitle FROM answers WHERE qid = '$qid' ORDER BY aid ASC";
$result = mysql_query($query) or die("ERROR: $query.".mysql_error());

if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_object($result)) {
echo "<div id=captionbox style='width: 110px;float:left;color:#FFF;text-align:center;'>";
echo "<a href='#' class='thumb' ><img class='thumb-img' src='images/roadies/th".$row->aid.".jpg' /> </a>";
echo "<input  type = hidden name = aid id = rd".$row->aid." value = ".$row->aid.">".$row->atitle."</input>";
        echo "</div>";
                    }

echo "<input type = hidden name = qid value = '".$qid."'>";
echo "<br/>";
echo "<input type = submit name = submit value = 'Vote!'>";
                }

  echo '</form>';

}

the above code fetches object ids and places jpeg images accordingly (thumbnails).
now when i click on these thumbnails the javascript opens an overlay to display the large version. i want to pass the value of $row->aid to javascript.

then from the javascript i want to fill out a form and pass the $row->aid and the form to user_submit.php to add it to the DB.

i am new to php. please help me out.

  • 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-13T07:20:46+00:00Added an answer on May 13, 2026 at 7:20 am

    You can write a variable, object or array literal declaration to your javascipt file or to a <script> element in a HTML file, as kiamlaluno correctly said. but i would suggest, (1) use the var keyword and (2) consider using a separate namespace.

    If you have several things to tell the JS, it’s handy to put them in a PHP hash and json_encode() and then write the encoded string to your output. This takes care of the namespace and correct escaping of the data. For example:

    <?php
    $jsdata = array(
        'this' => "It\"s gone.\nWhat?",
        'that' => array(1,3,2),
        'another' => 0x2f );
    $jsdata = json_encode($jsdata);
    ?>
    <html>
    <head></head>
    <body>
    <script type="text/javascript">
        var thedata = <?php echo "$jsdata;" ?>
        window.console.log(thedata);
    </script>
    </body>
    </html>
    

    Try that and look at the javascript console to see if it works.

    EDIT: Another reason I like this approach is because you can use PHP’s array handling conveniences to construct an arbitrarily complex $jsdata while not worrying about escaping issues and only consuming one global JS object name.

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

Sidebar

Related Questions

I'm calling some JavaScript from within my PHP code, but I want the second
I do code verification image in PHP and i show it in another page
I'm calling url_for() inside these javascript tags: <script type=text/javascript> $.post('<?php echo url_for('category_set_representative_image', array('sf_subject' =>
In my JavaScript code I am first calling a function to update an image:
I am using a javascript code to print an image with some text as
I am calling a Javascript function in my html page from a Flash movie
Possible Duplicate: calling ASP function from javascript okay running this code : <script type=text/javascript>
Sometimes JavaScript doesn't make sense to me, consider the following code that generates a
I used webView to show javaScript,one image was included in the javaScrip,but the webView
Follow on from: Javascript wait for image to load before calling Ajax function initResources()

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.