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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:23:11+00:00 2026-05-23T06:23:11+00:00

I am trying to use specific numeric results from a mysql_fetch_array within a while

  • 0

I am trying to use specific numeric results from a mysql_fetch_array within a while loop to execute a Javascript function (Ajax). A basic snippet of my php code is as follows:

while ($data = mysql_fetch_array($result)) 
{
$link = $data['id']; //example results will be 12345
echo '<span id="val" onclick="goto()">'.$link.'</span>'; //lists 12345, and makes each clickable
}

Part of my Javascript code is as follows:

function goto(str)
{
   Ajax...
   var idval = document.getElementById('val').innerHTML; //grabs 1,2,3,4, or 5 based on which number was clicked
   Ajax...
}

What I am trying to do here is query multiple records from MySql, list the results using a while loop, make each result clickable, and pass the inner html to a variable for Ajax.

My problem is that when I click any of the results from the while loop list, I pass only the first result of the mysql fetch array. For example, the while loop will list 12345. when I try clicking 3, I get 1 as the inner html; when I try clicking 5, I get 1 as the inner html; and so on… It always gets the first result, which is 1.

I tried imploding and exploding the mysql fetch array, however the inner html always ends up being the first row of the array results. I need to break up the array somehow, so that each row is independent, not just visually, but programmatically so I can get it using getElementById.innerHTML.

I really appreciate anyones help. Your suggestions and hopefully an answer will really help make my php projects much more useful.

  • 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-23T06:23:12+00:00Added an answer on May 23, 2026 at 6:23 am

    First, change your php script to look like this:

    while ($data = mysql_fetch_array($result)) 
    {
        $link = $data['id']; //example results will be 12345
        echo '<span id="val'.$link.'" onclick="goto('.$link.')">'.$link.'</span>';
    }
    

    Then, use the following javascript code:

    function goto(link)
    {
        Ajax...
        var idval = document.getElementById('val'+link).innerHTML; 
        Ajax...
    }
    

    But I am not sure about what str means in your javascript code and why function goto takes 1 arguments (str) while is called with no arguments (onclick="goto()").

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

Sidebar

Related Questions

I am trying to use delegate to call a function, when a specific set
I'm trying to use a value from onsubmit() in php. More specific: An HTML
I am trying to use a .each loop to find specific elements in a
While trying to use LINQ to SQL I encountered several problems. I have table
I trying to use ImageInfo and Jython to get information from a image on
My problem is that I am trying to use a specific JTidy version with
I'm trying to use the IE specific conditional statements to alter class settings based
I'm trying to use ant to use XSLT to preprocess three specific stylesheets in
I am trying to use the ps -o command to get just specific info
Is there a way to use culture specific characters in a WPF-StringFormat? I'm trying

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.