[mysql]mysql or statement werkt niet goed

Pagina: 1
Acties:

  • InfoTracer
  • Registratie: November 2001
  • Laatst online: 26-04 13:17
heb al wat gezocht maar het wil nog steeds niet werken.
Ben nu al zo'n 2 uur bezig met 1 querie maar hij wil niet echt

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
<?
$xbegin = 61;
$xeinde = 120;
$ybegin = 0;
$yeinde = 61;

$food = '';
$iron = 20;
$oct = '';
$end = '';

$insert_food = '';
$insert_iron = '';
$insert_oct = '';
$insert_end = '';

if($food != '')
{
    $insert_food = "AND planets.planet_food >= $food";
}

if($iron != '')
{
    if($food != '')
    {
        $insert_iron = "AND planets.planet_iron >= $iron";
    }
    else
    {
        $insert_iron = "OR planets.planet_iron >= $iron";
    }
}

if($oct != '')
{
    if($food != '' && $iron != '')
    {
        $insert_oct = "AND planets.planet_octarine >= $oct";
    }
    else
    {
        $insert_oct = "OR planets.planet_octarine >= $oct";
    }
}

if($end != '')
{   
    if($food != '' && $iron != '' && $oct != '')
    {
        $insert_end = "AND planets.planet_endurium >= $end";
    }
    else
    {
        $insert_end = "OR planets.planet_endurium >= $end";
    }
}


$q = mysql_query("SELECT planets.system_id, planets.planet_nr, planets.planet_food, planets.planet_iron, planets.planet_octarine, planets.planet_endurium FROM systems, planets WHERE systems.system_id = planets.system_id AND systems.x >= '$xbegin' AND systems.x <= '$xeinde' AND systems.y >= '$ybegin' AND systems.y <= '$yeinde' ".$insert_food." ".$insert_iron." ".$insert_oct." ".$insert_end." GROUP BY planets.system_id")or die (mysql_error());
?>


hij zou nu alleen planet moeten laten zien die hoger dan 20 iron hebben maar hij laat ook nog planets zien die bv 16 oct hebben of helemaal niets aan bonus.

hier een stukje uit de output
code:
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<HTML>
<HEAD>
<TITLE>Overview planets</TITLE>
</HEAD>
</BODY>
<TABLE BORDER = '1'>
<TR>
    <TD>Planet_nr.</TD>
    <TD>food</TD>
    <TD>iron</TD>
    <TD>octarine</TD>
    <TD>endurium</TD>
</TR>
<TR>
    <TD>1,22:7</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center">22</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
</TR>
<TR>
    <TD>1,24:6</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center">21</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
</TR>
<TR>
    <TD>1,40:3</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center">24</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
</TR>
<TR>
    <TD>1,93:13</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center">22</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
</TR>
<TR>
    <TD>1,98:4</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center">25</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
</TR>
<TR>
    <TD>10,115:14</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center">20</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
</TR>
<TR>
    <TD>10,35:19</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center">22</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
</TR>
<TR>
    <TD>10,63:13</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center">23</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
</TR>
<TR>
    <TD>10,65:11</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center">20</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
</TR>
<TR>
    <TD>10,70:8</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center">21</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
</TR>
<TR>
    <TD>10,74:18</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center">22</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
</TR>
<TR>
    <TD>10,80:18</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center">20</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
</TR>
<TR>
    <TD>100,115:3</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center">23</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
</TR>
<TR>
    <TD>100,117:12</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center">21</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
</TR>
<TR>
    <TD>100,14:1</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
</TR>
<TR>
    <TD>100,16:1</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
</TR>
<TR>
    <TD>100,25:1</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center">22</TD>
</TR>
<TR>
    <TD>100,28:1</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
</TR>
<TR>
    <TD>100,36:1</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
</TR>
<TR>
    <TD>100,39:1</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center">20</TD>
</TR>
<TR>
    <TD>100,4:1</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center">12</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
</TR>
<TR>
    <TD>100,43:1</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
</TR>
<TR>
    <TD>100,47:1</TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center"></TD>
    <TD ALIGN="center">16</TD>
    <TD ALIGN="center"></TD>
</TR>
</TABLE>
</BODY>
</HTML>


wat gaat er fout bij de querie?

[ Voor 36% gewijzigd door InfoTracer op 30-10-2005 15:49 ]


  • BasieP
  • Registratie: Oktober 2000
  • Laatst online: 19-10-2025
offtopic:
oei Imperial Conflict :P

ik heb daar ooit eens een ban gekregen omdat ik netjes alle planeten af liep en deze in een DB stopte, en idd mjin eigen query's er op ging uitvoeren.
Pas je ff op dat dat bij jouw niet gebeurd?


ontopic: die onderste lap html code is vrij nutteloos, kort hem in, want dit komt de leesbaarheid niet echt ten goede

verder is dit vrij makkelijk zelf te debuggen.
zorg dat je eerst de complete query ziet. (kan je hier ook in dit topic plaatsen)
dan kan je sowieso zien wat het resultaat is van je if statments.

daarna kan je adhv je query zien welk if statment er fout gaat

[ Voor 63% gewijzigd door BasieP op 30-10-2005 16:03 ]

This message was sent on 100% recyclable electrons.


  • InfoTracer
  • Registratie: November 2001
  • Laatst online: 26-04 13:17
yep je had gelijk me querie kwam er niet goed uit na die if's het is me gelukt :D
probleem was dat de if else in de if omgedraait moest worden dus die ene moest ANDworden en die andere moest OR worden

ps idd imperial conflict
en hoop ook niet dat ik gebanned word maar ik hou het nog allemaal vrij netjes heb er geen bot van gemaakt enzo
en ben de scripts eigenlijk ook meer aan het maken om me php en mysql te verbeteren.

  • ripexx
  • Registratie: Juli 2002
  • Laatst online: 25-04 12:02

ripexx

bibs

Vervang
PHP:
1
2
3
4
<?

$q = mysql_query("SELECT planets.system_id, planets.planet_nr, planets.planet_food, planets.planet_iron, planets.planet_octarine, planets.planet_endurium FROM systems, planets WHERE systems.system_id = planets.system_id AND systems.x >= '$xbegin' AND systems.x <= '$xeinde' AND systems.y >= '$ybegin' AND systems.y <= '$yeinde' ".$insert_food." ".$insert_iron." ".$insert_oct." ".$insert_end." GROUP BY planets.system_id")or die (mysql_error());
?>

Door dir
PHP:
1
2
3
4
5
6
<?

$q = "SELECT planets.system_id, planets.planet_nr, planets.planet_food, planets.planet_iron, planets.planet_octarine, planets.planet_endurium FROM systems, planets WHERE systems.system_id = planets.system_id AND systems.x >= '$xbegin' AND systems.x <= '$xeinde' AND systems.y >= '$ybegin' AND systems.y <= '$yeinde' ".$insert_food." ".$insert_iron." ".$insert_oct." ".$insert_end." GROUP BY planets.system_id";
echo "<pre>".$q."</pre>";
$qr = mysql_query($q)or die (mysql_error());
?>

buit is binnen sukkel


  • InfoTracer
  • Registratie: November 2001
  • Laatst online: 26-04 13:17
toch bedankt ripexx zo heb ik idd me probleem opgelost
alleen dan zonder <PRE> maar das dan alleen voor de leesbaarheid ;)

  • ripexx
  • Registratie: Juli 2002
  • Laatst online: 25-04 12:02

ripexx

bibs

InfoTracer schreef op zondag 30 oktober 2005 @ 16:22:
toch bedankt ripexx zo heb ik idd me probleem opgelost
alleen dan zonder <PRE> maar das dan alleen voor de leesbaarheid ;)
Standaard "PHP debuggen" oftewel, wat voer ik aan MySQL en klopt dit dan?

buit is binnen sukkel

Pagina: 1