Jump to content

Recommended Posts

so is there any way to fetch what array to fetch the data from in the Function input?

 

this is what i got so far

 

function onHoverCounter( ChampID )
{
var show1 = ChampID[1];
$("#"+show1).addClass('counter');
}

 

ChampID is fetched from

 

<a href="?champion=ahri"><div class="champion apcarry mid" id="ahri" onmouseover="onHoverCounter(this.id);" onmouseout="onmouseoutCounter(this.id);"><img src="img/champions/ahri.jpg"> Ahri </div></a>

Edited by Pentacore

so is there any way to fetch what array to fetch the data from in the Function input?

Depends: has anyone really been far even as decided to use even go to want to do look more like?

 

On a more serious note,

What?

Depends: has anyone really been far even as decided to use even go to want to do look more like?

 

On a more serious note,

What?

 

ya i just read that through.. sorry about that

 

what i mean is i want to get the name of the array that the function use, by using the Fucntion input, is there a way to do that?

You're still not making sense, not to me anyway.

 

You're passing the element ID to the method and then attempting to add a class to the element. There is no array involved so I've no idea what you're referring to when you talk about "the array that the function usesssss"

As cpd said, there is no array at the moment (which is probably what is confusing us, and you).  Your onHoverCounter() function takes the id of the <div> that you're attaching it to, e.g. ahri.  This is a string value, not an array.

 

Your function then gets the second letter of that string when doing ChampID[1] (JS, like PHP, allows you to access individual letters in a string by their zero-based offset).  So in your example, show1 contains the string h.

As cpd said, there is no array at the moment (which is probably what is confusing us, and you). Your onHoverCounter() function takes the id of the <div> that you're attaching it to, e.g. ahri. This is a string value, not an array.

 

Your function then gets the second letter of that string when doing ChampID[1] (JS, like PHP, allows you to access individual letters in a string by their zero-based offset). So in your example, show1 contains the string h.

 

You're still not making sense, not to me anyway.

 

You're passing the element ID to the method and then attempting to add a class to the element. There is no array involved so I've no idea what you're referring to when you talk about "the array that the function usesssss"

 

oh srry i forgot to include this part, the array's exists and is created through PHP

 

$counters;
$mysqli = new mysqli($host, $sqluser, $sqlpass, "counters");
foreach (glob("img/champions/*.jpg") as $filename)
{
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$path = $filename;
$file = basename($path);
$file = basename($path, ".jpg");
$search = "SELECT * FROM counters WHERE `IMG_Name`='".$file."'";
if ($searchresult = mysqli_query($mysqli, $search)) {


/* fetch associative array */
while ($row = mysqli_fetch_assoc($searchresult)) {
${$file}["1"] = $row["Counter 1"];
${$file}["2"] = $row["Counter 2"];
${$file}["3"] = $row["Counter 3"];
${$file}["4"] = $row["Counter 4"];
${$file}["5"] = $row["Counter 5"];
${$file}["6"] = $row["Counter 1"];
${$file}["7"] = $row["Counter 2"];
${$file}["8"] = $row["Counter 3"];
${$file}["9"] = $row["Counter 4"];
${$file}["10"] = $row["Counter 5"];
${$file}["11"] = $row["Good With 1"];
${$file}["12"] = $row["Good With 2"];
${$file}["13"] = $row["Good With 3"];
${$file}["14"] = $row["Good With 4"];
${$file}["15"] = $row["Good With 5"];
}
}
echo $file." = ".json_encode(${$file})." ,";
}
?>

 

And an example of an array that gets created:

 

var ahri = {"1":"ryze","2":"fizz","3":"Akali","4":"LeBlanc","5":"Diana","6":"ryze","7":"fizz","8":"Akali","9":"LeBlanc","10":"Diana","11":"Jax","12":"Irelia","13":"Shen","14":"Ezreal","15":"Amumu"}

Edited by Pentacore

Using variable variables, as you are, seems a lot like going out of your way to make life more difficult. Why not use a nested array like $files[$file][1]. This will allow you to have a nice, single, object in Javascript containing all of the information for all of the files.

 

If you just want to take what you have right now and do something with it, it sounds like you're looking for a way to reference the ahri variable from the this.id string.  Assuming the variables are created in the window-level scope (it looks like they are) then you can, inside your onHoverCounter() function, use something like window[ChampID] to refer to that variable by name. For example:

 

var file = window[ChampID];
var show1 = file[1];
...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.