JSON data ophalen jquery

Gestart doorDylan19 reacties37 weergaven

20 berichten · pagina 2 van 2

Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
(Dylanquote)
Dylanh (link):
Antonn schreef:
Eerdere citaten tonen
Dylanh schreef:
{"[b][u]all[/u][/b]":{"id":["64","65"],"code":["AqCeTZ3Q","CTRtldIw"],"file_match":["voorbeeld.php","Handeler.rar"],"file_size":["30","146693"],"expire":["1386543600","1386543600"],"ip":["dada",""],"can_used":["0","1"],"opmerking":["<script>",""]},"id":["65"],"active":{"code":["CTRtldIw"],"file_match":["Handeler.rar"],"file_size":["146693"],"expire":["1386543600"],"ip":[""],"can_used":["1"],"opmerking":[""]},"expired":{"id":["64"],"code":["AqCeTZ3Q"],"file_match":["voorbeeld.php"],"file_size":["30"],"expire":["1386543600"],"ip":["dada"],"can_used":["0"],"opmerking":["<script>"]}}
[/spoiler]
Die JSON code is ook heel brak trouwens. Elke string/integer staat in een onnodige array.

toevoeging op 8 december 2013, 16:51:02:
En bij id 2 parameters geven omdat je 2 resultaten hebt moet ook niet.

Resultaat 1 = {id: 1, naam: "lol"}
Resultaat 2 = {id: 2, naam: "appel"}
Resultaat 3 = {id: 3, naam: "berg"}
Resultaat 4 = {id: 4, naam: "dwerg"}
=>
{resultcount: 4, results: {{id: 1, naam: "lol"}, {id: 2, naam: "appel"}, {id: 3, naam: "berg"}, {id: 4, naam: "dwerg"}}}

Jij hebt

Resultaat = {id: {"1", "2", "3", "4"}, naam: {"lol", "appel", "berg", "dwerg"}}

Dan komen we bij de PHP van json.php:

Codeblok (voorbeeld.php):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62


session_start();
include_once mysqli.class.php;
include config.php;

$mysql = new DBconnection($host, $user, $password, $database);
header(Content-Type: application/json);
if(isset($_SESSION[logged]) && $_SESSION[logged] === TRUE) {
$json = array();
$query = $mysql->query("SELECT * FROM code");
if($query->num_rows == 0) {
$json[all][message] = Geen downloads gevonden.;
}
else {
while($row = $query->fetch_assoc()) {
$json[all][id][] = htmlentities($row[id], ENT_QUOTES);
$json[all][code][] = htmlentities($row[code], ENT_QUOTES);
$json[all][file_match][] = htmlentities($row[file_match], ENT_QUOTES);
$json[all][file_size][] = htmlentities($row[file_size], ENT_QUOTES);
$json[all][expire][] = htmlentities($row[expire], ENT_QUOTES);
$json[all][ip][] = htmlentities($row[ip], ENT_QUOTES);
$json[all][can_used][] = htmlentities($row[can_used], ENT_QUOTES);
$json[all][opmerking][] = htmlentities($row[opmerking], ENT_QUOTES);
}
}


$query = $mysql->query("SELECT * FROM code WHERE can_used != 0 AND expire >=".strtotime(date("d-m-Y"))."");
if($query->num_rows == 0) {
$json[active][message] = Geen actieve downloads gevonden.;
}
else {
while($row = $query->fetch_assoc()) {
$json[active][id][] = htmlentities($row[id], ENT_QUOTES);
$json[active][code][] = htmlentities($row[code], ENT_QUOTES);
$json[active][file_match][] = htmlentities($row[file_match], ENT_QUOTES);
$json[active][file_size][] = htmlentities($row[file_size], ENT_QUOTES);
$json[active][expire][] = htmlentities($row[expire], ENT_QUOTES);
$json[active][ip][] = htmlentities($row[ip], ENT_QUOTES);
$json[active][can_used][] = htmlentities($row[can_used], ENT_QUOTES);
$json[active][opmerking][] = htmlentities($row[opmerking], ENT_QUOTES);
}
}


$query = $mysql->query("SELECT * FROM code WHERE can_used = 0 OR expire < ".strtotime(date("d-m-Y"))."");
if($query->num_rows == 0) {
$json[expired][message] = Geen verlopen downloads gevonden.;
}
else {
while($row = $query->fetch_assoc()) {
$json[expired][id][] = htmlentities($row[id], ENT_QUOTES);
$json[expired][code][] = htmlentities($row[code], ENT_QUOTES);
$json[expired][file_match][] = htmlentities( $row[file_match], ENT_QUOTES);
$json[expired][file_size][] = htmlentities($row[file_size], ENT_QUOTES);
$json[expired][expire][] = htmlentities($row[expire], ENT_QUOTES);
$json[expired][ip][] = htmlentities($row[ip], ENT_QUOTES);
$json[expired][can_used][] = htmlentities($row[can_used], ENT_QUOTES);
$json[expired][opmerking][] = htmlentities($row[opmerking], ENT_QUOTES);
}
}

echo json_encode($json);
}
else {
$json = array(message=> you are not logged in...);
echo json_encode($json);
}

?>

Moet het dan zo,
$json[][all][id].. nee dat kan niet. Hoe dan?

$json[xxxx][xxxx][] = $var;
heb jij overal
Waarom die [] steeds op het einde? nooo
$json[xxxx][xxxx] = $var;
had het dus gewoon moeten zijn
0
Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Antonn schreef:
(Dylanquote)
Dylanh (link):
[/quote]
Eerdere citaten tonen
Antonn schreef:
Eerdere citaten tonen
Dylanh schreef:
{"[b][u]all[/u][/b]":{"id":["64","65"],"code":["AqCeTZ3Q","CTRtldIw"],"file_match":["voorbeeld.php","Handeler.rar"],"file_size":["30","146693"],"expire":["1386543600","1386543600"],"ip":["dada",""],"can_used":["0","1"],"opmerking":["<script>",""]},"id":["65"],"active":{"code":["CTRtldIw"],"file_match":["Handeler.rar"],"file_size":["146693"],"expire":["1386543600"],"ip":[""],"can_used":["1"],"opmerking":[""]},"expired":{"id":["64"],"code":["AqCeTZ3Q"],"file_match":["voorbeeld.php"],"file_size":["30"],"expire":["1386543600"],"ip":["dada"],"can_used":["0"],"opmerking":["<script>"]}}
[/spoiler]
Die JSON code is ook heel brak trouwens. Elke string/integer staat in een onnodige array.

toevoeging op 8 december 2013, 16:51:02:
En bij id 2 parameters geven omdat je 2 resultaten hebt moet ook niet.

Resultaat 1 = {id: 1, naam: "lol"}
Resultaat 2 = {id: 2, naam: "appel"}
Resultaat 3 = {id: 3, naam: "berg"}
Resultaat 4 = {id: 4, naam: "dwerg"}
=>
{resultcount: 4, results: {{id: 1, naam: "lol"}, {id: 2, naam: "appel"}, {id: 3, naam: "berg"}, {id: 4, naam: "dwerg"}}}

Jij hebt

Resultaat = {id: {"1", "2", "3", "4"}, naam: {"lol", "appel", "berg", "dwerg"}}

Dan komen we bij de PHP van json.php:

Codeblok (voorbeeld.php):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62


session_start();
include_once mysqli.class.php;
include config.php;

$mysql = new DBconnection($host, $user, $password, $database);
header(Content-Type: application/json);
if(isset($_SESSION[logged]) && $_SESSION[logged] === TRUE) {
$json = array();
$query = $mysql->query("SELECT * FROM code");
if($query->num_rows == 0) {
$json[all][message] = Geen downloads gevonden.;
}
else {
while($row = $query->fetch_assoc()) {
$json[all][id][] = htmlentities($row[id], ENT_QUOTES);
$json[all][code][] = htmlentities($row[code], ENT_QUOTES);
$json[all][file_match][] = htmlentities($row[file_match], ENT_QUOTES);
$json[all][file_size][] = htmlentities($row[file_size], ENT_QUOTES);
$json[all][expire][] = htmlentities($row[expire], ENT_QUOTES);
$json[all][ip][] = htmlentities($row[ip], ENT_QUOTES);
$json[all][can_used][] = htmlentities($row[can_used], ENT_QUOTES);
$json[all][opmerking][] = htmlentities($row[opmerking], ENT_QUOTES);
}
}


$query = $mysql->query("SELECT * FROM code WHERE can_used != 0 AND expire >=".strtotime(date("d-m-Y"))."");
if($query->num_rows == 0) {
$json[active][message] = Geen actieve downloads gevonden.;
}
else {
while($row = $query->fetch_assoc()) {
$json[active][id][] = htmlentities($row[id], ENT_QUOTES);
$json[active][code][] = htmlentities($row[code], ENT_QUOTES);
$json[active][file_match][] = htmlentities($row[file_match], ENT_QUOTES);
$json[active][file_size][] = htmlentities($row[file_size], ENT_QUOTES);
$json[active][expire][] = htmlentities($row[expire], ENT_QUOTES);
$json[active][ip][] = htmlentities($row[ip], ENT_QUOTES);
$json[active][can_used][] = htmlentities($row[can_used], ENT_QUOTES);
$json[active][opmerking][] = htmlentities($row[opmerking], ENT_QUOTES);
}
}


$query = $mysql->query("SELECT * FROM code WHERE can_used = 0 OR expire < ".strtotime(date("d-m-Y"))."");
if($query->num_rows == 0) {
$json[expired][message] = Geen verlopen downloads gevonden.;
}
else {
while($row = $query->fetch_assoc()) {
$json[expired][id][] = htmlentities($row[id], ENT_QUOTES);
$json[expired][code][] = htmlentities($row[code], ENT_QUOTES);
$json[expired][file_match][] = htmlentities( $row[file_match], ENT_QUOTES);
$json[expired][file_size][] = htmlentities($row[file_size], ENT_QUOTES);
$json[expired][expire][] = htmlentities($row[expire], ENT_QUOTES);
$json[expired][ip][] = htmlentities($row[ip], ENT_QUOTES);
$json[expired][can_used][] = htmlentities($row[can_used], ENT_QUOTES);
$json[expired][opmerking][] = htmlentities($row[opmerking], ENT_QUOTES);
}
}

echo json_encode($json);
}
else {
$json = array(message=> you are not logged in...);
echo json_encode($json);
}

?>

Moet het dan zo,
$json[][all][id].. nee dat kan niet. Hoe dan?

$json[xxxx][xxxx][] = $var;
heb jij overal
Waarom die [] steeds op het einde? nooo
$json[xxxx][xxxx] = $var;
had het dus gewoon moeten zijn

Nu klopt het niet meer omdat ik er dan alleen maar 1 krijg. Die [] moet er wel bij.
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Dylanh schreef:
Eerdere citaten tonen
Antonn schreef:
(Dylanquote)
Dylanh (link):
[/quote]
Eerdere citaten tonen
Antonn schreef:
Eerdere citaten tonen
Dylanh schreef:
{"[b][u]all[/u][/b]":{"id":["64","65"],"code":["AqCeTZ3Q","CTRtldIw"],"file_match":["voorbeeld.php","Handeler.rar"],"file_size":["30","146693"],"expire":["1386543600","1386543600"],"ip":["dada",""],"can_used":["0","1"],"opmerking":["<script>",""]},"id":["65"],"active":{"code":["CTRtldIw"],"file_match":["Handeler.rar"],"file_size":["146693"],"expire":["1386543600"],"ip":[""],"can_used":["1"],"opmerking":[""]},"expired":{"id":["64"],"code":["AqCeTZ3Q"],"file_match":["voorbeeld.php"],"file_size":["30"],"expire":["1386543600"],"ip":["dada"],"can_used":["0"],"opmerking":["<script>"]}}
[/spoiler]
Die JSON code is ook heel brak trouwens. Elke string/integer staat in een onnodige array.

toevoeging op 8 december 2013, 16:51:02:
En bij id 2 parameters geven omdat je 2 resultaten hebt moet ook niet.

Resultaat 1 = {id: 1, naam: "lol"}
Resultaat 2 = {id: 2, naam: "appel"}
Resultaat 3 = {id: 3, naam: "berg"}
Resultaat 4 = {id: 4, naam: "dwerg"}
=>
{resultcount: 4, results: {{id: 1, naam: "lol"}, {id: 2, naam: "appel"}, {id: 3, naam: "berg"}, {id: 4, naam: "dwerg"}}}

Jij hebt

Resultaat = {id: {"1", "2", "3", "4"}, naam: {"lol", "appel", "berg", "dwerg"}}
[/quote]

Dan komen we bij de PHP van json.php:

Codeblok (voorbeeld.php):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62


session_start();
include_once mysqli.class.php;
include config.php;

$mysql = new DBconnection($host, $user, $password, $database);
header(Content-Type: application/json);
if(isset($_SESSION[logged]) && $_SESSION[logged] === TRUE) {
$json = array();
$query = $mysql->query("SELECT * FROM code");
if($query->num_rows == 0) {
$json[all][message] = Geen downloads gevonden.;
}
else {
while($row = $query->fetch_assoc()) {
$json[all][id][] = htmlentities($row[id], ENT_QUOTES);
$json[all][code][] = htmlentities($row[code], ENT_QUOTES);
$json[all][file_match][] = htmlentities($row[file_match], ENT_QUOTES);
$json[all][file_size][] = htmlentities($row[file_size], ENT_QUOTES);
$json[all][expire][] = htmlentities($row[expire], ENT_QUOTES);
$json[all][ip][] = htmlentities($row[ip], ENT_QUOTES);
$json[all][can_used][] = htmlentities($row[can_used], ENT_QUOTES);
$json[all][opmerking][] = htmlentities($row[opmerking], ENT_QUOTES);
}
}


$query = $mysql->query("SELECT * FROM code WHERE can_used != 0 AND expire >=".strtotime(date("d-m-Y"))."");
if($query->num_rows == 0) {
$json[active][message] = Geen actieve downloads gevonden.;
}
else {
while($row = $query->fetch_assoc()) {
$json[active][id][] = htmlentities($row[id], ENT_QUOTES);
$json[active][code][] = htmlentities($row[code], ENT_QUOTES);
$json[active][file_match][] = htmlentities($row[file_match], ENT_QUOTES);
$json[active][file_size][] = htmlentities($row[file_size], ENT_QUOTES);
$json[active][expire][] = htmlentities($row[expire], ENT_QUOTES);
$json[active][ip][] = htmlentities($row[ip], ENT_QUOTES);
$json[active][can_used][] = htmlentities($row[can_used], ENT_QUOTES);
$json[active][opmerking][] = htmlentities($row[opmerking], ENT_QUOTES);
}
}


$query = $mysql->query("SELECT * FROM code WHERE can_used = 0 OR expire < ".strtotime(date("d-m-Y"))."");
if($query->num_rows == 0) {
$json[expired][message] = Geen verlopen downloads gevonden.;
}
else {
while($row = $query->fetch_assoc()) {
$json[expired][id][] = htmlentities($row[id], ENT_QUOTES);
$json[expired][code][] = htmlentities($row[code], ENT_QUOTES);
$json[expired][file_match][] = htmlentities( $row[file_match], ENT_QUOTES);
$json[expired][file_size][] = htmlentities($row[file_size], ENT_QUOTES);
$json[expired][expire][] = htmlentities($row[expire], ENT_QUOTES);
$json[expired][ip][] = htmlentities($row[ip], ENT_QUOTES);
$json[expired][can_used][] = htmlentities($row[can_used], ENT_QUOTES);
$json[expired][opmerking][] = htmlentities($row[opmerking], ENT_QUOTES);
}
}

echo json_encode($json);
}
else {
$json = array(message=> you are not logged in...);
echo json_encode($json);
}

?>

Moet het dan zo,
$json[][all][id].. nee dat kan niet. Hoe dan?

$json[xxxx][xxxx][] = $var;
heb jij overal
Waarom die [] steeds op het einde? nooo
$json[xxxx][xxxx] = $var;
had het dus gewoon moeten zijn

Nu klopt het niet meer omdat ik er dan alleen maar 1 krijg. Die [] moet er wel bij.

Ohh het zit in een while zie ik ja.

Die htmlentities zijn trouwens ook nergens voor nodig.

Codeblok (voorbeeld.php):

1
2
3
4
5
6
7
8

$json[active][id][] = htmlentities($row[id], ENT_QUOTES);
$json[active][code][] = htmlentities($row[code], ENT_QUOTES);
$json[active][file_match][] = htmlentities($row[file_match], ENT_QUOTES);
$json[active][file_size][] = htmlentities($row[file_size], ENT_QUOTES);
$json[active][expire][] = htmlentities($row[expire], ENT_QUOTES);
$json[active][ip][] = htmlentities($row[ip], ENT_QUOTES);
$json[active][can_used][] = htmlentities($row[can_used], ENT_QUOTES);
$json[active][opmerking][] = htmlentities($row[opmerking], ENT_QUOTES);

kan je vervangen door

Codeblok (voorbeeld.php):

1

$json[active][] = $row;
0
Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Nope want als. je dan
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Dylanh schreef:
Nope want als. je dan
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren