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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:58:04+00:00 2026-06-10T15:58:04+00:00

Little problem about sending PHP array to javascript function, i did homework looked everywhere

  • 0

Little problem about sending PHP array to javascript function, i did homework looked everywhere and i know its not reliable to do this, but at this moment i do not know any other way , so try to just advice me how to finish it anyway.

I got php code executing first , idea is on page load i get some data from MySQL , i filled php array with IDs from that select statement.

<?php
include('config.php');
$TicketExist = "select BetSlipID,probatip1.betslips.MatchID as GameID, 
TipID,tim1.Name AS HomeTeam ,tim2.Name AS AwayTeam, UserID 
from probatip1.betslips
inner join probatip1.matches matches on probatip1.betslips.MatchID = matches.MatchID
inner join probatip1.teams tim1 on matches.HomeTeamID = tim1.TeamID
inner join probatip1.teams tim2 on matches.AwayTeamID = tim2.TeamID
where UserID = 1";

$TicketResult = mysql_query($TicketExist);
$TicketNum = mysql_numrows($TicketResult);

mysql_close();

if($TicketNum != 0)
{
$s=0;
while($s < $TicketNum)
{       

    $GameID = mysql_result($TicketResult,$s,"GameID");
    $TipID = mysql_result($TicketResult,$s,"TipID");    
    $ArrayIDs[$s] = $GameID;
    echo "<script>window.onload=GetInfo($GameID,$TipID); </script>";
    $s++;
}
} 
?>

So i got it everything i want filled and wrote on my page , idea now is on user click , to call javascript to take this ‘$ArrayIDs’ and execute code from script

Here is code im calling script

<ul>
<li 
id="ConfirmButton" name="Insert" method="post" 
onclick="GetAllIDs(<?php $ArrayIDs ?>)"><a>POTVRDI</a></li>
</ul>

And my script code

function GetAllIDs(Ticket) {
$("td.ID").each(function () {

    var MatchID = $(this).attr('id');
    var lab = "Label";

    var Label = lab + MatchID;

    var Final = document.getElementById(Label);

    var TipID;

    if (Final.innerHTML == '1') {
        TipID = 1;
    }
    else if (Final.innerHTML == 'X') {
        TipID = 2;
    }
    else if (Final.innerHTML == '2') {
        TipID = 3;
    }
    else {
        return;
    }


    var request_type;
    var browser = navigator.appName;


    if (browser == "Microsoft Internet Explorer") {
        request_type = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else {
        request_type = new XMLHttpRequest();
    }

    var http = request_type;

    var AlreadyPlayed = false;

    if (Ticket != null) {
        var TicketExists = Ticket;
        for (var i = 0; i < TicketExists.length; i++) {
            if (TicketExists[i] == MatchID) {
                AlreadyPlayed = true;
                break;
            }
        }
    }

    if (http != null) {

        if (AlreadyPlayed == true) {
            http.open('get', 'update.php?MatchID=' + MatchID + 
            '&TipID=' + TipID + '&UserID=' + 1, true);
        }
        else {
            http.open('get', 'insert.php?MatchID=' + MatchID + 
            '&TipID=' + TipID + '&UserID=' + 1, true);
        }
        http.send(null);
    }
});

if (Ticket == null) {
    alert('Tiket je napravljen');
}
else {
    alert('Tiket je promenjen');
}
}

With this posted code when i am debugging code with firebug in mozzila i get that my ‘Ticket’ parameter that suppose to be ‘$ArrayIDs’ is undefined.

Reason why i want to make array and send it to javascript onclick event is to check if user already placed a bet on some game , if he did i want to send all data for update and if he did not yet placed bet on some game to send data for insert in database.
So i need array and before anything just to check MatchID with all IDs in my array, so i know what to do.

Thanks all in advance for helping out

  • 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-10T15:58:06+00:00Added an answer on June 10, 2026 at 3:58 pm

    Your script could do with a bit of cleanup, but in essence you need to change

    onclick="GetAllIDs(<?php $ArrayIDs ?>)">
    

    to

    onclick="GetAllIDs(<?php echo json_encode($ArrayIDs) ?>)">
    

    I’d also reccomend not outputting

    "<script>window.onload=GetInfo($GameID,$TipID); </script>";
    

    for each row in mysql, instead create a single array of the values and create one script after the loop. Using mysql_fetch_row instead of mysql_numrows and mysql_result is probably neater.

    while ($row = mysql_fetch_row($result)) {
        //...do things here...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little problem about using jQuery (I really do not know jQuery
Hello I know all about http://www.php.net/manual/en/function.http-build-query.php to do this however I have a little
I have a little problem about needing Activity/Application everywhere... More precisely I have classes
I have a little problem about the sort direction of a specific column in
I have a little problem about Google Maps. I'm using Geocoding (xml) for getting
i'm new to c++ and having a little problem understanding about c++'s casting. According
I am little bit confused about following problem & their solutions: i have 2
I have a little problem with Jquery getJSON function. my json here { entries:
Here's a little problem I've been thinking about for a while now that I
I have a little problem with my if statement when date.name is about this

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.