Toon posts:

[MYSQL] Query met joins maar geen resultaat.

Pagina: 1
Acties:

Verwijderd

Topicstarter
Ik heb hier een join van 3 tabellen, die dus niet werkt.

Ik kan de fout zelf niet vinden, het enige wat ik wel weet is dat hij wel werkt als ik
[php]
WHERE
bestelling_bezorgadres.klant_id=" . $klant_id . " AND
bestelling_factuuradres.klant_id=" . $klant_id . " AND
bestelling_gegevens.klant_id=" . $klant_id . "
[/php

weg haal. Hier zal dus ook wel de fout zitten maar ik kan het zelf niet vinden.
Alle tabellen hebben btw een klant_id en in alle tabellen zitten gegevens.
$klant_id wordt 100% zeker door gegeven aan mijn query.

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
$query = mysql_query ("SELECT 
                            bestelling_bezorgadres.voornaam             as ba_voornaam, 
                            bestelling_bezorgadres.achternaam           as ba_achternaam, 
                            bestelling_bezorgadres.straatnaam           as ba_straatnaam, 
                            bestelling_bezorgadres.huisnummer           as ba_huisnummer, 
                            bestelling_bezorgadres.postcode_postbus     as ba_postcode_postbus, 
                            bestelling_bezorgadres.woonplaats           as ba_woonplaats, 

                            bestelling_factuuradres.voornaam            as bf_voornaam, 
                            bestelling_factuuradres.achternaam          as bf_achternaam, 
                            bestelling_factuuradres.straatnaam          as bf_straatnaam, 
                            bestelling_factuuradres.huisnummer          as bf_huisnummer, 
                            bestelling_factuuradres.postcode_postbus    as bf_postcode_postbus, 
                            bestelling_factuuradres.woonplaats          as bf_woonplaats, 

                            bestelling_gegevens.totaal_incl_korting     as totaal 

                       FROM 
                            bestelling_bezorgadres, 
                            bestelling_factuuradres, 
                            bestelling_gegevens 
                       WHERE 
                            bestelling_bezorgadres.klant_id=" . $klant_id . " AND 
                            bestelling_factuuradres.klant_id=" . $klant_id . " AND 
                            bestelling_gegevens.klant_id=" . $klant_id . "");

Als ik dit na mijn query doe geef hij dus niets terug.
PHP:
1
<? echo  $var["ba_achternaam"]; ?> 

  • GX
  • Registratie: Augustus 2000
  • Laatst online: 14-05-2025

GX

Nee.

Helpt het als je de laatste punt en quotes weghaalt? die staan er naar mijn mening vrij nutteloos bij.. (maar ik ben er dan ook bijna een jaartje uit)

  • justmental
  • Registratie: April 2000
  • Niet online

justmental

my heart, the beat

Wat staat er in $klant_id op het moment van uitvoeren?
Wat doet de query als je hem in mysql uitvoert?

Vreemde query trouwens.

Who is John Galt?


  • Sybr_E-N
  • Registratie: December 2001
  • Nu online
Eerste waar ik aan denk zijn NULL waardes, als die in je joins komen dan geeft MySQL meestal geen resultaat. Maar ik weet niet of dat zo is natuurlijk, hoe ziet de bewuste tabel structuur eruit?

  • momania
  • Registratie: Mei 2000
  • Laatst online: 14:57

momania

iPhone 30! Bam!

En is klant_id in de database wel een getal?

Neem je whisky mee, is het te weinig... *zucht*


  • Facer
  • Registratie: Januari 2002
  • Niet online

Facer

Ken net.....

Voor zover ik weet moet je een INNER JOIN gebruiken om tabellen aan elkaar te koppelen (relaties maken) mogelijk dat je dat mist. FF op mysql.org zoeken hoe het ookalweer precies moest

URL: http://www.mysql.com/doc/en/JOIN.html

[ Voor 13% gewijzigd door Facer op 28-10-2003 20:03 . Reden: url toegevoegd ]


  • dArtagnan
  • Registratie: Mei 2002
  • Laatst online: 15-07 20:09

dArtagnan

Een voor allen, allen voor een

Gebruik je wel mysql_fetch_array?
PHP:
1
2
3
4
$query = mysql_query('query');
$var = mysql_fetch_array($query);

echo $var["ba_achternaam"];


Verander
SQL:
1
2
3
4
WHERE
   bestelling_bezorgadres.klant_id=" . $klant_id . " AND
   bestelling_factuuradres.klant_id=" . $klant_id . " AND
   bestelling_gegevens.klant_id=" . $klant_id . "");

eens in (met ' komma's erbij dus):
SQL:
1
2
3
4
WHERE
   bestelling_bezorgadres.klant_id=' " . $klant_id . " ' AND
   bestelling_factuuradres.klant_id=' " . $klant_id . " ' AND
   bestelling_gegevens.klant_id=' " . $klant_id . " ' ");


Meer informatie over joins: http://www.w3schools.com/sql/sql_join.asp

[ Voor 41% gewijzigd door dArtagnan op 28-10-2003 20:03 ]


Verwijderd

Topicstarter
Bij deze de structuur:

#
# Tabel structuur voor tabel `bestelling_bezorgadres`
#

CREATE TABLE bestelling_bezorgadres (
bezorgadres_id int(10) unsigned NOT NULL auto_increment,
klant_id int(10) NOT NULL default '0',
voornaam tinytext NOT NULL,
achternaam tinytext NOT NULL,
straatnaam tinytext NOT NULL,
huisnummer tinytext NOT NULL,
postcode_postbus tinytext NOT NULL,
woonplaats tinytext NOT NULL,
land tinytext NOT NULL,
PRIMARY KEY (bezorgadres_id)
) TYPE=MyISAM;

#
# Tabel structuur voor tabel `bestelling_factuuradres`
#

CREATE TABLE bestelling_factuuradres (
klant_id int(10) unsigned NOT NULL auto_increment,
voornaam tinytext NOT NULL,
achternaam tinytext NOT NULL,
straatnaam tinytext NOT NULL,
huisnummer tinytext NOT NULL,
postcode_postbus tinytext NOT NULL,
woonplaats tinytext NOT NULL,
land tinytext NOT NULL,
email tinytext NOT NULL,
timestamp int(10) NOT NULL default '0',
PRIMARY KEY (klant_id)
) TYPE=MyISAM;

#
# Tabel structuur voor tabel `bestelling_gegevens`
#

CREATE TABLE bestelling_gegevens (
bestelling_id int(10) unsigned NOT NULL auto_increment,
klant_id int(10) NOT NULL default '0',
korting tinytext NOT NULL,
betaal_keuze tinytext NOT NULL,
cadeaupapier tinytext NOT NULL,
priority_behandeling tinytext NOT NULL,
verzekering tinytext NOT NULL,
verzendkosten tinytext NOT NULL,
totaal_incl_korting tinytext NOT NULL,
hoe_gevonden tinytext NOT NULL,
commentaar text NOT NULL,
bevesteging tinytext NOT NULL,
acceptgiro_verstuurd tinytext NOT NULL,
afgehandeld tinytext NOT NULL,
PRIMARY KEY (bestelling_id)
) TYPE=MyISAM;

Verwijderd

Topicstarter
$klant_id is 100 zeker een getal ;)

Verwijderd

Topicstarter
Koraalduivel schreef op 28 oktober 2003 @ 20:02:
Gebruik je wel mysql_fetch_array?
PHP:
1
2
3
4
$query = mysql_query('query');
$var = mysql_fetch_array($query);

echo $var["ba_achternaam"];


Verander
SQL:
1
2
3
4
WHERE
   bestelling_bezorgadres.klant_id=" . $klant_id . " AND
   bestelling_factuuradres.klant_id=" . $klant_id . " AND
   bestelling_gegevens.klant_id=" . $klant_id . "");

eens in (met ' komma's erbij dus):
SQL:
1
2
3
4
WHERE
   bestelling_bezorgadres.klant_id=' " . $klant_id . " ' AND
   bestelling_factuuradres.klant_id=' " . $klant_id . " ' AND
   bestelling_gegevens.klant_id=' " . $klant_id . " ' ");


Meer informatie over joins: http://www.w3schools.com/sql/sql_join.asp
Maakt niet uit... zelfde resultaat.

  • dArtagnan
  • Registratie: Mei 2002
  • Laatst online: 15-07 20:09

dArtagnan

Een voor allen, allen voor een

Ik heb de query getest en bij mij werkt hij gewoon.
SQL:
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
SELECT 
bestelling_bezorgadres.voornaam AS ba_voornaam, 
bestelling_bezorgadres.achternaam AS ba_achternaam, 
bestelling_bezorgadres.straatnaam AS ba_straatnaam, 
bestelling_bezorgadres.huisnummer AS ba_huisnummer, 
bestelling_bezorgadres.postcode_postbus AS ba_postcode_postbus, 
bestelling_bezorgadres.woonplaats AS ba_woonplaats, 
bestelling_factuuradres.voornaam AS bf_voornaam, 
bestelling_factuuradres.achternaam AS bf_achternaam, 
bestelling_factuuradres.straatnaam AS bf_straatnaam, 
bestelling_factuuradres.huisnummer AS bf_huisnummer, 
bestelling_factuuradres.postcode_postbus AS bf_postcode_postbus, 
bestelling_factuuradres.woonplaats AS bf_woonplaats, 
bestelling_gegevens.totaal_incl_korting AS totaal
FROM 
bestelling_bezorgadres, 
bestelling_factuuradres, 
bestelling_gegevens
WHERE 
bestelling_bezorgadres.klant_id = '1'
AND 
bestelling_factuuradres.klant_id = '1' 
AND
bestelling_gegevens.klant_id = '1' 
LIMIT 0 , 30

[ Voor 95% gewijzigd door dArtagnan op 28-10-2003 20:21 ]


Verwijderd

Topicstarter
Koraalduivel schreef op 28 October 2003 @ 20:20:
Ik heb de query getest en bij mij werkt hij gewoon.
SQL:
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
SELECT 
bestelling_bezorgadres.voornaam AS ba_voornaam, 
bestelling_bezorgadres.achternaam AS ba_achternaam, 
bestelling_bezorgadres.straatnaam AS ba_straatnaam, 
bestelling_bezorgadres.huisnummer AS ba_huisnummer, 
bestelling_bezorgadres.postcode_postbus AS ba_postcode_postbus, 
bestelling_bezorgadres.woonplaats AS ba_woonplaats, 
bestelling_factuuradres.voornaam AS bf_voornaam, 
bestelling_factuuradres.achternaam AS bf_achternaam, 
bestelling_factuuradres.straatnaam AS bf_straatnaam, 
bestelling_factuuradres.huisnummer AS bf_huisnummer, 
bestelling_factuuradres.postcode_postbus AS bf_postcode_postbus, 
bestelling_factuuradres.woonplaats AS bf_woonplaats, 
bestelling_gegevens.totaal_incl_korting AS totaal
FROM 
bestelling_bezorgadres, 
bestelling_factuuradres, 
bestelling_gegevens
WHERE 
bestelling_bezorgadres.klant_id = '1'
AND 
bestelling_factuuradres.klant_id = '1' 
AND
bestelling_gegevens.klant_id = '1' 
LIMIT 0 , 30
Bij mij werkt hij ook wel als ik hem run in mijn PHPmyAdmin alleen ik krijg geen resultaten... jij wel ?

  • dArtagnan
  • Registratie: Mei 2002
  • Laatst online: 15-07 20:09

dArtagnan

Een voor allen, allen voor een

Verwijderd schreef op 28 October 2003 @ 20:23:
[...]


Bij mij werkt hij ook wel als ik hem run in mijn PHPmyAdmin alleen ik krijg geen resultaten... jij wel ?
Ik krijg wel resultaten.
Dan kloppen er een aantal id's niet in je tabellen. Ik heb namelijk overal bij id 1 ingevuld en ik kreeg een resultaat.

Verwijderd

Topicstarter
Koraalduivel schreef op 28 October 2003 @ 20:25:
[...]


Ik krijg wel resultaten.
Dan kloppen er een aantal id's niet in je tabellen. Ik heb namelijk overal bij id 1 ingevuld en ik kreeg een resultaat.
Dat is dan erg raar want dit werkt wel:

PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
SELECT 
bestelling_bezorgadres.voornaam AS ba_voornaam, 
bestelling_bezorgadres.achternaam AS ba_achternaam, 
bestelling_bezorgadres.straatnaam AS ba_straatnaam, 
bestelling_bezorgadres.huisnummer AS ba_huisnummer, 
bestelling_bezorgadres.postcode_postbus AS ba_postcode_postbus, 
bestelling_bezorgadres.woonplaats AS ba_woonplaats, 
bestelling_factuuradres.voornaam AS bf_voornaam, 
bestelling_factuuradres.achternaam AS bf_achternaam, 
bestelling_factuuradres.straatnaam AS bf_straatnaam, 
bestelling_factuuradres.huisnummer AS bf_huisnummer, 
bestelling_factuuradres.postcode_postbus AS bf_postcode_postbus, 
bestelling_factuuradres.woonplaats AS bf_woonplaats, 
bestelling_gegevens.totaal_incl_korting AS totaal
FROM 
bestelling_bezorgadres, 
bestelling_factuuradres, 
bestelling_gegevens


Dus hier ligt het dan volgens mij niet aan?

Verwijderd

Topicstarter
Ik heb het probleem al ;( Tabel bestelling_bezorgadres heeft maar éé row met een klant_id '3'

..... ben er dus uit... stom..

Verwijderd

Topicstarter
Okee... ik heb nu dit:

PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
$query = mysql_query ("SELECT
                            bestelling_bezorgadres.voornaam             as ba_voornaam,
                            bestelling_bezorgadres.achternaam           as ba_achternaam,
                            bestelling_bezorgadres.straatnaam           as ba_straatnaam,
                            bestelling_bezorgadres.huisnummer           as ba_huisnummer,
                            bestelling_bezorgadres.postcode_postbus     as ba_postcode_postbus,
                            bestelling_bezorgadres.woonplaats           as ba_woonplaats,

                            bestelling_factuuradres.voornaam            as bf_voornaam,
                            bestelling_factuuradres.achternaam          as bf_achternaam,
                            bestelling_factuuradres.straatnaam          as bf_straatnaam,
                            bestelling_factuuradres.huisnummer          as bf_huisnummer,
                            bestelling_factuuradres.postcode_postbus    as bf_postcode_postbus,
                            bestelling_factuuradres.woonplaats          as bf_woonplaats,
                            bestelling_gegevens.totaal_incl_korting     as totaal
                       FROM
                            bestelling_bezorgadres,
                            bestelling_factuuradres,
                            bestelling_gegevens
                       WHERE
                            bestelling_bezorgadres.klant_id  = " . $klant_id . " or bestelling_bezorgadres.klant_id  = "" AND
                            bestelling_factuuradres.klant_id = " . $klant_id . " or bestelling_factuuradres.klant_id = "" AND
                            bestelling_gegevens.klant_id     = " . $klant_id . " or bestelling_gegevens.klant_id     = "" ") or report_mysql_error ("SELECT bestelling_factuuradres, bestelling_artikelen, bestelling_gegevens JOIN bestelling_afronden.php");


Om ook tabellen op te vragen als er geen waarden is maar dat werkt niet, is btw ook niet echt netjes hoe ik het nu probeer.

Weet iemand misschien hoe ik dit netjes doe?
dus dat hij alleen de gegevens van bestelling_bezorgadres en bestelling_factuuradres op haalt als bestelling_gegevens geen overeenkomstig klant_id heeft?

  • marty
  • Registratie: Augustus 2002
  • Laatst online: 27-03-2023
Verwijderd schreef op 28 October 2003 @ 20:32:
[...]


Dat is dan erg raar want dit werkt wel:

PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
SELECT 
bestelling_bezorgadres.voornaam AS ba_voornaam, 
bestelling_bezorgadres.achternaam AS ba_achternaam, 
bestelling_bezorgadres.straatnaam AS ba_straatnaam, 
bestelling_bezorgadres.huisnummer AS ba_huisnummer, 
bestelling_bezorgadres.postcode_postbus AS ba_postcode_postbus, 
bestelling_bezorgadres.woonplaats AS ba_woonplaats, 
bestelling_factuuradres.voornaam AS bf_voornaam, 
bestelling_factuuradres.achternaam AS bf_achternaam, 
bestelling_factuuradres.straatnaam AS bf_straatnaam, 
bestelling_factuuradres.huisnummer AS bf_huisnummer, 
bestelling_factuuradres.postcode_postbus AS bf_postcode_postbus, 
bestelling_factuuradres.woonplaats AS bf_woonplaats, 
bestelling_gegevens.totaal_incl_korting AS totaal
FROM 
bestelling_bezorgadres, 
bestelling_factuuradres, 
bestelling_gegevens


Dus hier ligt het dan volgens mij niet aan?
Je sluit hier ook niet 1 resultaat uit. Er hoeft dus maar in 1 tabel een record voor te komen en je krijgt al resultaat.
PHP:
1
2
3
4
WHERE
                            bestelling_bezorgadres.klant_id=" . $klant_id . " AND
                            bestelling_factuuradres.klant_id=" . $klant_id . " AND
                            bestelling_gegevens.klant_id=" . $klant_id . "");
kun je daar niet beter van maken

PHP:
1
2
3
4
WHERE
    bestelling_bezorgadres.klant_id=bestelling_factuuradres.klant_id AND
    bestelling_bezorgadres.klant_id=bestelling_gegevens.klant_id AND
    bestelling_bezorgadres.klant_id=bestelling_gegevens.klant_".$klant_id;


als je geen resultaten krijgt dan komt het inderdaad - zoals al eerder werd gesugereerd - omdat je id's niet kloppen. Doe het daarom dan eens met een LEFT JOIN ipv een INNER (met een WHERE dus)

  • marty
  • Registratie: Augustus 2002
  • Laatst online: 27-03-2023
Verwijderd schreef op 28 oktober 2003 @ 20:38:
Okee... ik heb nu dit:

Weet iemand misschien hoe ik dit netjes doe?
dus dat hij alleen de gegevens van bestelling_bezorgadres en bestelling_factuuradres op haalt als bestelling_gegevens geen overeenkomstig klant_id heeft?
Met een LEFT JOIN dus:
http://www.mysql.com/doc/en/JOIN.html

  • dArtagnan
  • Registratie: Mei 2002
  • Laatst online: 15-07 20:09

dArtagnan

Een voor allen, allen voor een

Verwijderd schreef op 28 October 2003 @ 20:38:
Okee... ik heb nu dit:

<knip>

Om ook tabellen op te vragen als er geen waarden is maar dat werkt niet, is btw ook niet echt netjes hoe ik het nu probeer.

Weet iemand misschien hoe ik dit netjes doe?
dus dat hij alleen de gegevens van bestelling_bezorgadres en bestelling_factuuradres op haalt als bestelling_gegevens geen overeenkomstig klant_id heeft?
Met een LEFT JOIN
http://www.w3schools.com/sql/sql_join.asp

edit:
Ik moet toch eens sneller gaan typen :)

[ Voor 67% gewijzigd door dArtagnan op 28-10-2003 20:42 ]


Verwijderd

Topicstarter
Koraalduivel schreef op 28 October 2003 @ 20:41:
[...]


Met een LEFT JOIN
http://www.w3schools.com/sql/sql_join.asp

edit:
Ik moet toch eens sneller gaan typen :)
Ik heb even wat informatie gelezen over left joins en toen kwam ik tot het volgende:

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
$query = mysql_query ("SELECT
                            bestelling_bezorgadres.voornaam             as ba_voornaam,
                            bestelling_bezorgadres.achternaam           as ba_achternaam,
                            bestelling_bezorgadres.straatnaam           as ba_straatnaam,
                            bestelling_bezorgadres.huisnummer           as ba_huisnummer,
                            bestelling_bezorgadres.postcode_postbus     as ba_postcode_postbus,
                            bestelling_bezorgadres.woonplaats           as ba_woonplaats,

                            bestelling_factuuradres.voornaam            as bf_voornaam,
                            bestelling_factuuradres.achternaam          as bf_achternaam,
                            bestelling_factuuradres.straatnaam          as bf_straatnaam,
                            bestelling_factuuradres.huisnummer          as bf_huisnummer,
                            bestelling_factuuradres.postcode_postbus    as bf_postcode_postbus,
                            bestelling_factuuradres.woonplaats          as bf_woonplaats,
                            bestelling_gegevens.totaal_incl_korting     as totaal
                       FROM
                            bestelling_factuuradres
                  LEFT JOIN
                            bestelling_bezorgadres,
                            bestelling_gegevens
                          ON
                            bestelling_factuuradres.klant_id = " . $klant_id . " AND
                            bestelling_bezorgadres.klant_id  = " . $klant_id . " AND
                            bestelling_gegevens.klant_id     = " . $klant_id . "");


Dit werkt dus niet en dat zal vast komen omdat mijn join niet echt 100% correct is.
Kan iemand mij misschien zeggen wat ik hier fout doe?

Verwijderd

Probeer dit eens:

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
$query = mysql_query ("SELECT
                            bestelling_bezorgadres.voornaam             as ba_voornaam,
                            bestelling_bezorgadres.achternaam           as ba_achternaam,
                            bestelling_bezorgadres.straatnaam           as ba_straatnaam,
                            bestelling_bezorgadres.huisnummer           as ba_huisnummer,
                            bestelling_bezorgadres.postcode_postbus     as ba_postcode_postbus,
                            bestelling_bezorgadres.woonplaats           as ba_woonplaats,

                            bestelling_factuuradres.voornaam            as bf_voornaam,
                            bestelling_factuuradres.achternaam          as bf_achternaam,
                            bestelling_factuuradres.straatnaam          as bf_straatnaam,
                            bestelling_factuuradres.huisnummer          as bf_huisnummer,
                            bestelling_factuuradres.postcode_postbus    as bf_postcode_postbus,
                            bestelling_factuuradres.woonplaats          as bf_woonplaats,
                            bestelling_gegevens.totaal_incl_korting     as totaal
                       FROM
                            bestelling_factuuradres
                  LEFT JOIN
                            bestelling_bezorgadres
                          ON
                            bestelling_bezorgadres.klant_id  = ". $klant_id." 
                  LEFT JOIN
                            bestelling_gegevens
                          ON
                            bestelling_gegevens.klant_id     = ". $klant_id . "
                  WHERE
                            bestelling_factuuradres.klant_id = ". $klant_id.");


Edit: Misschien beter:
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
$query = mysql_query ("SELECT
                            bestelling_bezorgadres.voornaam             as ba_voornaam,
                            bestelling_bezorgadres.achternaam           as ba_achternaam,
                            bestelling_bezorgadres.straatnaam           as ba_straatnaam,
                            bestelling_bezorgadres.huisnummer           as ba_huisnummer,
                            bestelling_bezorgadres.postcode_postbus     as ba_postcode_postbus,
                            bestelling_bezorgadres.woonplaats           as ba_woonplaats,

                            bestelling_factuuradres.voornaam            as bf_voornaam,
                            bestelling_factuuradres.achternaam          as bf_achternaam,
                            bestelling_factuuradres.straatnaam          as bf_straatnaam,
                            bestelling_factuuradres.huisnummer          as bf_huisnummer,
                            bestelling_factuuradres.postcode_postbus    as bf_postcode_postbus,
                            bestelling_factuuradres.woonplaats          as bf_woonplaats,
                            bestelling_gegevens.totaal_incl_korting     as totaal
                       FROM
                            bestelling_factuuradres
                  LEFT JOIN
                            bestelling_bezorgadres
                          ON
                        bestelling_bezorgadres.klant_id  =  bestelling_factuuradres.klant_id
                  LEFT JOIN
                            bestelling_gegevens
                          ON
                          bestelling_gegevens.klant_id  =  bestelling_factuuradres.klant_id
                  WHERE
                            bestelling_factuuradres.klant_id = ". $klant_id.");


edit:

Wat verkeerde spaties verwijderd.

[ Voor 39% gewijzigd door Verwijderd op 28-10-2003 22:49 ]


Verwijderd

Topicstarter
Verwijderd schreef op 28 oktober 2003 @ 22:29:
Probeer dit eens:

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
$query = mysql_query ("SELECT
                            bestelling_bezorgadres.voornaam             as ba_voornaam,
                            bestelling_bezorgadres.achternaam           as ba_achternaam,
                            bestelling_bezorgadres.straatnaam           as ba_straatnaam,
                            bestelling_bezorgadres.huisnummer           as ba_huisnummer,
                            bestelling_bezorgadres.postcode_postbus     as ba_postcode_postbus,
                            bestelling_bezorgadres.woonplaats           as ba_woonplaats,

                            bestelling_factuuradres.voornaam            as bf_voornaam,
                            bestelling_factuuradres.achternaam          as bf_achternaam,
                            bestelling_factuuradres.straatnaam          as bf_straatnaam,
                            bestelling_factuuradres.huisnummer          as bf_huisnummer,
                            bestelling_factuuradres.postcode_postbus    as bf_postcode_postbus,
                            bestelling_factuuradres.woonplaats          as bf_woonplaats,
                            bestelling_gegevens.totaal_incl_korting     as totaal
                       FROM
                            bestelling_factuuradres
                  LEFT JOIN
                            bestelling_bezorgadres
                          ON
                            bestelling_bezorgadres.klant_id  = " . $klant_id." 
                  LEFT JOIN
                            bestelling_gegevens
                          ON
                            bestelling_gegevens.klant_id     = " . $klant_id . "
                  WHERE
                            bestelling_factuuradres.klant_id = " . $klant_id.");


Edit: Misschien beter:
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
$query = mysql_query ("SELECT
                            bestelling_bezorgadres.voornaam             as ba_voornaam,
                            bestelling_bezorgadres.achternaam           as ba_achternaam,
                            bestelling_bezorgadres.straatnaam           as ba_straatnaam,
                            bestelling_bezorgadres.huisnummer           as ba_huisnummer,
                            bestelling_bezorgadres.postcode_postbus     as ba_postcode_postbus,
                            bestelling_bezorgadres.woonplaats           as ba_woonplaats,

                            bestelling_factuuradres.voornaam            as bf_voornaam,
                            bestelling_factuuradres.achternaam          as bf_achternaam,
                            bestelling_factuuradres.straatnaam          as bf_straatnaam,
                            bestelling_factuuradres.huisnummer          as bf_huisnummer,
                            bestelling_factuuradres.postcode_postbus    as bf_postcode_postbus,
                            bestelling_factuuradres.woonplaats          as bf_woonplaats,
                            bestelling_gegevens.totaal_incl_korting     as totaal
                       FROM
                            bestelling_factuuradres
                  LEFT JOIN
                            bestelling_bezorgadres
                          ON
                        bestelling_bezorgadres.klant_id  =  bestelling_factuuradres.klant_id
                  LEFT JOIN
                            bestelling_gegevens
                          ON
                          bestelling_gegevens.klant_id  =  bestelling_factuuradres.klant_id
                  WHERE
                            bestelling_factuuradres.klant_id = " . $klant_id.");
Ik krijg een parse error met deze code.

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
$query = mysql_query ("SELECT
                            bestelling_bezorgadres.voornaam             as ba_voornaam,
                            bestelling_bezorgadres.achternaam           as ba_achternaam,
                            bestelling_bezorgadres.straatnaam           as ba_straatnaam,
                            bestelling_bezorgadres.huisnummer           as ba_huisnummer,
                            bestelling_bezorgadres.postcode_postbus     as ba_postcode_postbus,
                            bestelling_bezorgadres.woonplaats           as ba_woonplaats,

                            bestelling_factuuradres.voornaam            as bf_voornaam,
                            bestelling_factuuradres.achternaam          as bf_achternaam,
                            bestelling_factuuradres.straatnaam          as bf_straatnaam,
                            bestelling_factuuradres.huisnummer          as bf_huisnummer,
                            bestelling_factuuradres.postcode_postbus    as bf_postcode_postbus,
                            bestelling_factuuradres.woonplaats          as bf_woonplaats,
                       FROM
                            bestelling_factuuradres
                  LEFT JOIN
                            bestelling_bezorgadres
                          ON
                            bestelling_bezorgadres.klant_id  = " . $klant_id."
                  LEFT JOIN
                            bestelling_gegevens
                          ON
                            bestelling_gegevens.klant_id     = " . $klant_id . "
                  WHERE
                            bestelling_factuuradres.klant_id = " . $klant_id."")

Verwijderd

Er staan bij de punten wat spaties teveel, die moet je even weghalen. Ik had wat snel getypt.

Verwijderd

Topicstarter
Verwijderd schreef op 28 October 2003 @ 22:47:
Er staan bij de punten wat spaties teveel, die moet je even weghalen. Ik had wat snel getypt.
Maakt niets uit hoor!
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
$query = mysql_query ("SELECT
                            bestelling_bezorgadres.voornaam             as ba_voornaam,
                            bestelling_bezorgadres.achternaam           as ba_achternaam,
                            bestelling_bezorgadres.straatnaam           as ba_straatnaam,
                            bestelling_bezorgadres.huisnummer           as ba_huisnummer,
                            bestelling_bezorgadres.postcode_postbus     as ba_postcode_postbus,
                            bestelling_bezorgadres.woonplaats           as ba_woonplaats,

                            bestelling_factuuradres.voornaam            as bf_voornaam,
                            bestelling_factuuradres.achternaam          as bf_achternaam,
                            bestelling_factuuradres.straatnaam          as bf_straatnaam,
                            bestelling_factuuradres.huisnummer          as bf_huisnummer,
                            bestelling_factuuradres.postcode_postbus    as bf_postcode_postbus,
                            bestelling_factuuradres.woonplaats          as bf_woonplaats,
                       FROM
                            bestelling_factuuradres
                  LEFT JOIN
                            bestelling_bezorgadres
                          ON
                        bestelling_bezorgadres.klant_id  =  bestelling_factuuradres.klant_id
                  LEFT JOIN
                            bestelling_gegevens
                          ON
                          bestelling_gegevens.klant_id  =  bestelling_factuuradres.klant_id
                  WHERE
                            bestelling_factuuradres.klant_id = ".$klant_id."");

Verwijderd

Wat is de precieze foutmelding?

Krijg je een php-parse error, of een MySql error?

Verwijderd

Topicstarter
Verwijderd schreef op 28 October 2003 @ 22:56:
Wat is de precieze foutmelding?

Krijg je een php-parse error, of een MySql error?
Warning: Supplied argument is not a valid MySQL result resource

  • marty
  • Registratie: Augustus 2002
  • Laatst online: 27-03-2023
dan klopt je query dus niet.
kun je debuggen door gebruik te maken van mysql_error()
http://nl2.php.net/manual/nl/function.mysql-error.php
Pagina: 1