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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:23:02+00:00 2026-06-15T16:23:02+00:00

there are currently three posts but when onclick alerts only one post.If I echo

  • 0

there are currently three posts but when onclick alerts only one post.If I echo the posts insite the loop,then all three posts are shown,however if I alert them,then onlyone posts is show.plz help or suggest any alternative approach.

  $sql=mysqli_query($db3,"SELECT * from user where  id='$id'");
            $num_rows=mysqli_num_rows($sql);

            while($row=mysqli_fetch_array($sql)){

                $posts=$row['posts'];
            }


            ?>
        <span onclick=u(<?php echo $posts; ?>)> <?php echo $num_rows  ?> </span>

        <script type="text/javascript">
            function u(posts) {
                alert(posts);
            }
        </script>
        <?php

Update

Here is second query
After using the array approach ,If i use fancy box with $num rows to show all posts in the fancybox .I am again getting the only one result on the fancybox.Plz help

            $posts[] = $row['posts'];

}
foreach ($posts as $af){

                echo "<div id='#modelbox_id'>$af</div>";}

            ?>


            <a href="#modelbox_id" class="modelbox"><?php   echo $num_rows; ?></a>

            <?php
  • 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-15T16:23:04+00:00Added an answer on June 15, 2026 at 4:23 pm

    It is because you are assigning a single post row into the $posts variable, and then overwriting that variable with a new value on each iteration of the while loop.

    Try something like this instead:

    $posts = array();
    while($row=mysqli_fetch_array($sql)){
        $posts[] = $row['posts'];
    }
    

    Then you will need to print each value of the $posts array.

    For example, you could implode the array into a string:

    <span onclick=u(<?php echo implode(', ', $posts); ?>)> ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to measure the popularity of a post but there's no current system
(I know there are post about data visualization, but none of them completely answered
There Currently is a local debate as to which code is more readability We
Is there currently a way to generate XML files containing tables compatible with Microsoft
Is there currently a way to subscribe to an event of a wrapped set,
I have been using the storyboard to make an application and currently there are
we are using data sets as our data access layer. currently there are some
There is currently this Prototype code that does a PUT: new Ajax.Request(someUrl, { method:
I currently have three classes User , UserProfile , and Vendor . User is
I know that there are currently questions on SO already pertaining to saving jQuery

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.