Zoekfunctie ( Conditie van een product)
Het werkt helemaal behalve op 1 ding als de group op All staat pakt die alle resultaten
hier is de code ik heb echt ff hulp nodig:$
$article_query_1 = "SELECT * FROM articles";
if ($_SESSION['group'] != '%'){
if($_SESSION['group'] and $_SESSION['condition'] == "new" and $_SESSION['group'] !== "All"){
$article_query_1 = $article_query_1 ." WHERE AID LIKE '".$_SESSION['group']."%'";
}if($_SESSION['condition'] == "second_hand" and $_SESSION['group'] !== "All"){
$article_query_1 = $article_query_1 . " WHERE (AID LIKE'".$form['TWEE_CODE']."%')";
}if($_SESSION['condition'] == "both" and $_SESSION['group'] !== "All"){
$article_query_1 = $article_query_1 . " WHERE (AID LIKE'".$form['TWEE_CODE']."%' OR AID LIKE '".$_SESSION['group']."%')";
}
}
else {
if ($_SESSION['condition'] == "new" and $_SESSION['group'] = "All") {
$article_query_1 = $article_query_1 . 'WHERE (TWEE_CODE IS NOT LIKE "'.T.'%" OR AID IS NOT LIKE "'.T.'%" ) ';
}
if ($_SESSION['condition'] == "second_hand" and $_SESSION['group'] = "All") {
// controleren op T
$article_query_1 = "SELECT * FROM `articles` WHERE `AID` LIKE \'T%\' AND `TITEL` LIKE \'%starfighter%\'";
}
if ($_SESSION['condition'] == "both") {
$query .= ' AID LIKE "%'.$group.'%" ';
}
}
Toevoeging op 28/02/2013 11:29:52:
correctie : else if ($_SESSION['condition'] == "both") {
$article_query_1 = $article_query_1 .' AID LIKE "%'.$_SESSION['group'].'%" ';
}
Toevoeging op 28/02/2013 11:31:44:
Hij komt dus niet in de else terecht en hij begint ook te zeuren over mysql_num_rows() expects parameter 1 to be resource, boolean given in..
Code (php)
1
2
3
4
2
3
4
<?php
// controleren op T
$article_query_1 = "SELECT * FROM `articles` WHERE `AID` LIKE \'T%\' AND `TITEL` LIKE \'%starfighter%\'";
?>
// controleren op T
$article_query_1 = "SELECT * FROM `articles` WHERE `AID` LIKE \'T%\' AND `TITEL` LIKE \'%starfighter%\'";
?>
Hier escape je de ' voor SQL omdat je " gebruikt voor de string, gewoon de escape weghalen dus
Gewijzigd op 28/02/2013 11:54:58 door Ger van Steenderen
2) als je een foutmelding krijgt moet je die oplossen. Blijkbaar is je query gewoon fout, anders krijg je die foutmelding niet. Dus echo je query, los de fouten erin op.
3) waarom single quotes escapen als je dubbele quotes gebruikt?
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
27
28
29
30
31
32
33
34
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
<?php
$article_query_1 = "SELECT * FROM articles";
if($group != '%') {
if($_SESSION['group'] and $_SESSION['condition'] == "new" and $_SESSION['group'] !== "All")
{
$article_query_1 = $article_query_1 ." WHERE AID LIKE '".$_SESSION['group']."%'";
}
if($_SESSION['condition'] == "second_hand" and $_SESSION['group'] !== "All")
{
$article_query_1 = $article_query_1 . " WHERE (AID LIKE'".$form['TWEE_CODE']."%')";
}
if($_SESSION['condition'] == "both" and $_SESSION['group'] !== "All")
{
$article_query_1 = $article_query_1 . " WHERE (AID LIKE'".$form['TWEE_CODE']."%' OR AID LIKE '".$_SESSION['group']."%')";
}
}
else {
if ($_SESSION['condition'] == "new") {
// controleren op A, B, D, F, G, K, L, M, P NIET LIKE T! = SECONDHAND
$article_query_1 = $article_query_1 . 'WHERE (AID NOT LIKE "'.T.'%") ';
}
if ($_SESSION['condition'] == "second_hand") {
// controleren op T
$article_query_1 = "SELECT * FROM `articles` WHERE `AID` LIKE \'T%\' AND `TITEL` LIKE \'%starfighter%\' LIMIT 0, 30 ";
}
if ($_SESSION['condition'] == "both") {
$article_query_1 = $article_query_1 . ' AID LIKE "%'.$_SESSION['group'].'%" ';
}
}
?>
$article_query_1 = "SELECT * FROM articles";
if($group != '%') {
if($_SESSION['group'] and $_SESSION['condition'] == "new" and $_SESSION['group'] !== "All")
{
$article_query_1 = $article_query_1 ." WHERE AID LIKE '".$_SESSION['group']."%'";
}
if($_SESSION['condition'] == "second_hand" and $_SESSION['group'] !== "All")
{
$article_query_1 = $article_query_1 . " WHERE (AID LIKE'".$form['TWEE_CODE']."%')";
}
if($_SESSION['condition'] == "both" and $_SESSION['group'] !== "All")
{
$article_query_1 = $article_query_1 . " WHERE (AID LIKE'".$form['TWEE_CODE']."%' OR AID LIKE '".$_SESSION['group']."%')";
}
}
else {
if ($_SESSION['condition'] == "new") {
// controleren op A, B, D, F, G, K, L, M, P NIET LIKE T! = SECONDHAND
$article_query_1 = $article_query_1 . 'WHERE (AID NOT LIKE "'.T.'%") ';
}
if ($_SESSION['condition'] == "second_hand") {
// controleren op T
$article_query_1 = "SELECT * FROM `articles` WHERE `AID` LIKE \'T%\' AND `TITEL` LIKE \'%starfighter%\' LIMIT 0, 30 ";
}
if ($_SESSION['condition'] == "both") {
$article_query_1 = $article_query_1 . ' AID LIKE "%'.$_SESSION['group'].'%" ';
}
}
?>
Code (php)
1
2
3
4
5
2
3
4
5
<?php
$article_query_1 = "SELECT * FROM articles";
...
$article_query_1 = $article_query_1 . 'WHERE (AID NOT LIKE "'.T.'%") ';
?>
$article_query_1 = "SELECT * FROM articles";
...
$article_query_1 = $article_query_1 . 'WHERE (AID NOT LIKE "'.T.'%") ';
?>
Hier krijg je dus:
SELECT * FROM articlesWHERE (AID NOT LIKE "'.T.'%")
Dat werkt niet. Vandaar, echo je query en check voor dit soort fouten.