I need to create an dynamic array which will be sent via $("#ratings").load("ratingscalculator.php?Myarray="+myarray) and then used in a select query

$result = $database->connection->prepare("SELECT *, (SELECT COUNT(*)+1 FROM TABLE WHERE kampanj > t.kampanj and (kampanjnamn = 'Kampanjnamn_1' or kampanjnamn = 'Kampanjnamn_7' or kampanjnamn = 'Kampanjnamn_3' or kampanjnamn = 'Kampanjnamn_4' )) as 'rank', 
(SELECT COUNT(*) FROM TABLE where (kampanjnamn = 'Kampanjnamn_1' or kampanjnamn = 'Kampanjnamn_7' or kampanjnamn = 'Kampanjnamn_3' or kampanjnamn = 'Kampanjnamn_4') ) as 'counting'
FROM TABLE t
where kampanjnamn='$valtkampanjnamn'"); 

So it's this bit that I need to dynamically create somehow (kampanjnamn = 'Kampanjnamn_1' or kampanjnamn = 'Kampanjnamn_7' or kampanjnamn = 'Kampanjnamn_3' or kampanjnamn = 'Kampanjnamn_4' ) (this is just an example on what it would contain as it is user selectable)

So I want to create an array of all elements with the class "focused" and get their data-attribute "kampanjnamn".

My best guess would be something like this inside a click function:

$('.focused').each(function () {

    var Myarray = [];
    Myarray = $(this).data('kampanjnamn');
}

this gives me the error "Myarray is not defined". If I put window. infront instead of var it send the variable as a single object and not an array...

So my first question maybe should have been: Is it even possible to send an array with .load?

Recommended Answers

All 2 Replies

Member Avatar for diafol

To add to an array use .push

Also, you have scoped the variable inside the function so it's not available outside if that's where you need it. Just place the var Myarray = [] outside in that case.

Nice, thank you!

This was the last part to get the where clause to work

$whereClauses = explode(",", $_GET["jmfkampanjer"]);
$where = '';
if (count($whereClauses) > 0) {
    $where = 'WHERE kampanj > t.kampanj and (kampanjnamn = "'.implode('" or kampanjnamn = "',$whereClauses).'")';
}                       

Cheers!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.