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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:41:15+00:00 2026-05-31T02:41:15+00:00

I am calling data from a database and I would like to put an

  • 0

I am calling data from a database and I would like to put an ‘add’ button next to each line of data so that when clicked on will open a jquery dialog box. At the moment it only works for the first ‘add’.
Here is my code:

    $wgOut->addScript('<script type="text/javascript"> 

    ( function($) {
        $(document).ready(function() {
        $(function() {          
        $( "#alignment" )
            .dialog({
                autoOpen: false,
                title: "Align Images",
                //draggable: false,
                resizable: false,
                buttons: {"Okay": function() {$(this).dialog("close");}},

        });

        $("#imageSetting")
            .click(function() {
            $( "#alignment" ).dialog("open");
        });
        });     
        }); 
    } ) ( jQuery );

</script>'); 

$wgOut->addHTML('<div id="alignment">'); 
  $out = self::alignment();   
  $wgOut->addHtml($out);
$wgOut->addHTML('</div>');
//$wgOut->addHTML('<button id="imageSetting">Add</button>');


 $dbr = wfGetDB( DB_SLAVE );
 $results = $dbr->query("SELECT DISTINCT  img_name, img_description, img_width, img_height, img_user_text, img_timestamp
        FROM wiki_image
        ORDER BY img_timestamp ASC
    "); 

$uploaded = array();
while( $row = $dbr->fetchObject( $results ) ) {
$uploaded[] = array( $row->img_name, $row->img_width, $row->img_height, $row->img_user_text, $row->img_description);        
}


$wgOut->addHtml('<table><tr><td></td><th>Name</th><th>Thumbnail</th><th>Dimensions</th><th>User</th><th>Comment</th></tr>'); 

foreach($uploaded as $upload){
$wgOut->addHTML('<tr><td><button id="imageSetting">Add</button></td><td>');     
$wgOut->addHTML($upload[0]);
$wgOut->addHtml('</td><td>'); 
$wgOut->addHtml('thumnail image'); 
$wgOut->addHtml('</td><td>'); 
$wgOut->addHTML($upload[1]); 
$wgOut->addHTML('x'); 
$wgOut->addHTML($upload[2]); 
$wgOut->addHtml('</td><td>');
$wgOut->addHTML($upload[3]); 
$wgOut->addHtml('</td><td>');
$wgOut->addHtml('comment');
$wgOut->addHtml('</td><td>'); 
}

$wgOut->addHtml('</table>');
}

How do I make the ‘add’ button in the foreach loop call the jquery dialog for each line of data?

  • 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-31T02:41:17+00:00Added an answer on May 31, 2026 at 2:41 am

    the foreach loop is probably outputting Add buttons with identical ids, if that is the case change the code so that the Add buttons should have identical class and attach an event listner to that class like

    foreach($uploaded as $upload){
    $wgOut->addHTML('<tr><td><button class="imageSetting">Add</button></td><td>');     
    $wgOut->addHTML($upload[0]);
    $wgOut->addHtml('</td><td>'); 
    $wgOut->addHtml('thumnail image'); 
    $wgOut->addHtml('</td><td>'); 
    $wgOut->addHTML($upload[1]); 
    $wgOut->addHTML('x'); 
    $wgOut->addHTML($upload[2]); 
    $wgOut->addHtml('</td><td>');
    $wgOut->addHTML($upload[3]); 
    $wgOut->addHtml('</td><td>');
    $wgOut->addHtml('comment');
    $wgOut->addHtml('</td><td>'); 
    }
    
    $wgOut->addHtml('</table>');
    }
    

    modify the selector as

    $(".imageSetting").click(function() {
                $( "#alignment" ).dialog("open");
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would you go about calling several methods in the data access layer from
I would like to know if after calling functions the data I have in
I have a PHP script that works by calling items from a database based
I would like to create an nsobject that will have all of my methods
I am calling asp.net action from proxy to fill the store data. I am
Calling image = Image.open(data) image.thumbnail((36,36), Image.NEAREST) will maintain the aspect ratio. But I need
I am calling a service that return JSON data. Script: $.ajax({ type: "POST", url:
I am calling an API that returns JSON data. I am using json.loads to
I am calling 5 external servers to retrieve XML-based data for each request for
I am calling my database which contains a datetime datatype. The date looks like

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.