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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:44:54+00:00 2026-06-11T09:44:54+00:00

This is my php with jquery code: <?php require(‘connection.php’); $query=select title,content from blogs; echo

  • 0

This is my php with jquery code:

<?php
require('connection.php');
$query="select title,content from blogs";
echo '<html><head>';
echo '<link rel="stylesheet" href="blog.css" />';
echo '<script src="jquery.js"></script>';
//echo '<script src="blogs.js"></script>';
echo "</head><body>";
$i=0;
if($result=$mysqli->query($query))
{
while($news=$result->fetch_row())
{
echo "<br/><br />"."<strong ><h2 onclick='$(document).ready(function() {
    $(this).click(function(){ $(\"#a".$i."\").toggle(\"slow\");});});'>". $news[0]."</h2></strong>"."<br/><br />";
echo "<div id='a".$i."'>".$news[1]."</div>";
$i++;
}
$result->close();
echo "</body></html>";
}
?>

This works but not stable. When I click the first heading it toggles for 2 to 3 times like an animation. When I click the second heading the first and second headings content toggles.This is the function call in the source code of the output php.

<strong ><h2 onclick='$(document).ready(function() {
    $(this).click(function(){ $("#a0").toggle("slow");});});'>HELLO WORLD</h2></strong>

Please let me know why it happens like this?I am new to jquery so I use it inline.I know it is a bad practice to do so and eliminates the biggest advantage of using jquery.

  • 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-11T09:44:55+00:00Added an answer on June 11, 2026 at 9:44 am

    Here’s your cleaned up code:

    <!DOCTYPE html>
    <html>
      <head>
        <link rel="stylesheet" href="blog.css" />
        <script src="jquery.js"></script>
        <!--<script src="blogs.js"></script>-->
        <script>
          $(function(){
            $('h2').click(function(){
              $(this).next().toggle('slow')
            })
          })
        </script>
      </head>
      <body>';
    <?php
      require('connection.php');
      $query="select title,content from blogs";
      $i=0;
      if($result=$mysqli->query($query)) {
        while($news=$result->fetch_row()) {
          echo "
        <h2><strong>{$news[0]}<strong></h2>
        <div id='a$i'>{$news[1]}</div>";
          $i++;
        }
        $result->close();
      }
    ?>
      </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my php code: <?php require('connection.php'); $query=select title,content from blogs; echo '<html><head>'; echo
I have the following jquery code: jQuery(function(){ jQuery(select#rooms).change(function(){ var options = ''; jQuery.getJSON(/admin/selection.php,{id: jQuery(this).val(),
I have this jQuery code: $(document).ready(function() { $.ajax({ url: pages/+page+.php, cache: false }).done(function( html
I'm folowing this tutorial to create php/jquery based chat application. In short, this code
I need help to use jConfirm with this existing code (php & Jquery &
How can I do this in Javascript/jQuery from PHP? I am trying to populate
I have different php output in jQuery-based tabs. This output is formed from database
I have this server side SLIM code: require 'Slim/Slim.php'; $app = new Slim(); //$app->config('debug',
How can I this PHP function include in jquery .html? PHP function: function trim_text($string,
I know how I would achieve this using PHP, but with jQuery / JavaScript

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.