ajax array php

Get help using Construct 2

Post » Sun Sep 11, 2016 9:24 am

Guys, help ? There are online databases. As can be realized through the Ajax a chip that for each row from the database to create items in the ListBox C2 c columns of data?
Those. how to make the right script and how to handle the Ajax response?
All the catch is that initially only known variables A, B, C. Accordingly, you need to at the touch of a button the request was sent to the database, and received a response from the figures in response made to the ListBox. In response Ajax - an array of JSON, but I can not load the array into the project, and the more processed.
The whole life is in the movement.Stopped - fell asleep to hell...
B
14
S
3
G
1
Posts: 122
Reputation: 1,694

Post » Sun Sep 11, 2016 5:03 pm

any ideas?
The whole life is in the movement.Stopped - fell asleep to hell...
B
14
S
3
G
1
Posts: 122
Reputation: 1,694

Post » Mon Sep 12, 2016 6:00 am

a couple of question did you import the files for ajax to get the files from ? and can you not use rex csv to array for this very same function since his is like the exact thing you are trying to do and it build the array through imported excel files.
B
51
S
24
G
6
Posts: 391
Reputation: 7,820

Post » Mon Sep 12, 2016 8:13 am

no-no.
you missed thing.
i have an online SQL DataBase. And i need to import all table data in some rows into c2 project as listbox items.
a little explaine - i have such rows as UserName and his contact. so i want to import this data into project on construct2 as listbox items. for each tabledata (userName and UserContact) separate listbox item.
Can anyone help me with it?
The whole life is in the movement.Stopped - fell asleep to hell...
B
14
S
3
G
1
Posts: 122
Reputation: 1,694

Post » Mon Sep 12, 2016 8:26 am

p.s. i don't request any files from my server. all i need - is just request table data from table rows from online SQL DataBase, fetch an array of it, convert as json, recieve this as AJAX.LastData, push it into array in project and for each xy add a lie to list box with array.y-text.
i need a correct php script, which will make it happens
The whole life is in the movement.Stopped - fell asleep to hell...
B
14
S
3
G
1
Posts: 122
Reputation: 1,694

Post » Mon Sep 12, 2016 5:35 pm

up
The whole life is in the movement.Stopped - fell asleep to hell...
B
14
S
3
G
1
Posts: 122
Reputation: 1,694

Post » Tue Sep 13, 2016 12:12 am

Axiomaltd wrote:i have an online SQL DataBase. And i need to import all table data in some rows into c2 project as listbox items.
a little explaine - i have such rows as UserName and his contact. so i want to import this data into project on construct2 as listbox items. for each tabledata (userName and UserContact) separate listbox item.


maybe you can use CSV instead JSON...

Persons table (userName; userContact)
Image

PHP file
Code: Select all
<?php
$servername = "yourServerName.com";
$username = "yourUserName";
$password = "yourPassword";
$dbname = "yourDatabaseName";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT  userName, userContact FROM Persons";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo  $row["userName"]. "#" . $row["userContact"] . PHP_EOL;
    }
} else {
    echo "0 results";
}
$conn->close();
exit;
?>


CSV2Array Plugin

Image

dataCSV2Array.capx
Image
B
64
S
23
G
7
Posts: 1,483
Reputation: 10,827

Post » Wed Sep 14, 2016 6:12 am

Thanx man! Guess, i can use it for a while. But it's not exactly what i'm looking for. =/
The whole life is in the movement.Stopped - fell asleep to hell...
B
14
S
3
G
1
Posts: 122
Reputation: 1,694

Post » Wed Sep 14, 2016 3:42 pm

Json to Array

Persons table (userName; userContact)
Image

PHP file
Code: Select all
<?php
$servername = "yourServerName.com";
$username = "yourUserName";
$password = "yourPassword";
$dbname = "yourDatabaseName";

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$size = array(4,2,1);

$sql = "SELECT  userName, userContact FROM Persons";
$result = $conn->query($sql);

$response = array(
    "c2array" => true,
    "size" => $size,
    "data" => array()
);

while ( $row = $result->fetch_assoc() ) {
    $response['data'][] = array(
        array($row['userName']),
        array($row['userContact'])
    );
}

echo json_encode($response);
$conn->close();
exit();
?>

Image

jsonPHP2Array.capx
Image
B
64
S
23
G
7
Posts: 1,483
Reputation: 10,827

Post » Wed Sep 14, 2016 7:17 pm

Bro! YOU ARE THE GREATEST!!!!
Thank you very-very much!!!
It's that i'm looking for =))))

Haw i can up you reputation? Can't see any button =/
The whole life is in the movement.Stopped - fell asleep to hell...
B
14
S
3
G
1
Posts: 122
Reputation: 1,694

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests