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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:50:08+00:00 2026-06-11T07:50:08+00:00

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

  • 0

This is my php code:

<?php
require('connection.php');
$query="select title,content from blogs";
echo '<html><head>';
echo '<link rel="stylesheet" href="blog.css" />';
echo '<script type="text/javascript" src="blog.js"></script></head><body>';
$i=0;
if($result=$mysqli->query($query))
{
while($news=$result->fetch_row())
{
echo "<br /><br /><strong>". $news[0]."</strong><br /><br />";
if(strlen($news[1])>60)
{
    $d=0;
    $content=explode(" ",$news[1]);
    foreach($content as $c)
    {
        if($d<=60)
        {
            echo $c." ";
            $d++;
        }
        else
        {
            if($d==61)
            {

                echo "<div id=a$i style='visibility:hidden'>";
                echo "<a href='#' onclick='toggle(a".$i.")' style='visibility:visible'>Show/Hide</a>";

                $i++;

                $d++;
            }
            echo $c." ";
            $d++;
            if($d==count($content)+1)
            {
                echo "</div>";
            }

        }


    }
}
else
echo $news[1]."<br /><br />";

}
$result->close();
echo "</body></html>";

}
?>

This is my JavaScript code:

function toggle(id)
{

    //document.getElementById('mcontent').value=x++;
    //if(x%2==0)
    document.getElementById(id).style.visibility="visible";
    //else
    //document.getElementById('mcontent').style.visibility="hidden";
};

The show hide button is not working.My strategy is to limit text which contains more than 60 words with the show hide button.Once the user clicks the button the hidden div becomes visible and that contains the extra text(namely the text after 60 word count).Div element should always start with a letter so I have append letter ‘a’ before that.Please help me fix this.

Note:
Don’t need Jquery solutions or suggestion.I need only to debug the above code.

  • 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-11T07:50:10+00:00Added an answer on June 11, 2026 at 7:50 am

    You’re missing quotes in your call to toggle.

    This would call toggle(a0) instead of toggle("a0").

    Try this :

    echo "<a href='#' onclick=\"toggle('a".$i."')\" style='visibility:visible'>Show/Hide</a>";
    

    As I always find painful to deal with this level of imbricated quotes, I prefer to avoid inlined javascript in PHP. You can defer the addition of handlers even without jQuery, using document.getElementById('...').onclick=....

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

Sidebar

Related Questions

I have this php code $jsonArray = array(); $sql = SELECT ID,CLIENT FROM PLD_SERVERS;
I'm wondering what the PHP equivalent to this code is: require zlib foo =
I have this PHP code to highlight the Query on search results. if (isset($_REQUEST['k'])){
I've got this php code to send the users information from the contact form
I have this code: require 'facebook.php'; $facebook = new Facebook(array( 'appId' => 'xxxxxxx', 'secret'
I have this code: require(class.XMLHttpRequest.php); function hot($news){ $url=https://localhost/search.aspx?search=.$news.; $ajax=new XMLHttpRequest(); $ajax->setRequestHeader(Cookie,Cookie: host); $ajax->open(GET,$url,true); $ajax->send(null);
This is my php code require(class.phpmailer.php); $mail = new PHPMailer(); $mail->IsSMTP(); // telling the
I wrote this code require('Database.class.php'); function get_info (){ $db = new Database($config['server'], $config['user'], $config['pass'],
My tweeting from my app works fine -- here's the code: require_once('twitteroauth/twitteroauth.php'); require_once('config.php'); $connection
Please see this below PHP code: <?php require '../src/facebook.php'; $facebook = new Facebook(array( 'appId'

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.