Zoekfunctie ( Conditie van een product)

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Willem R

Willem R

28/02/2013 11:28:33
Quote Anchor link
Hee, ik heb een vraagje ik ben bezig met een conditie veldje voor artikelen (new second_hand and both)
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..
 
PHP hulp

PHP hulp

29/03/2024 15:37:00
 
Ger van Steenderen
Tutorial mod

Ger van Steenderen

28/02/2013 11:53:52
Quote Anchor link
Zet je php code aub tussen [code] [/code]tags en <?php ?> tags, kunnen we wat makkelijker lezen.
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
<?php
// 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
 
Erwin H

Erwin H

28/02/2013 11:56:23
Quote Anchor link
1) je code is zo onleesbaar, dus echt inhoudelijk ga ik er niet op in.
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)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
<?php
$article_query_1
= "SELECT * FROM `articles` WHERE `AID` LIKE \'T%\' AND `TITEL` LIKE \'%starfighter%\'";
?>
 
Willem R

Willem R

28/02/2013 12:04:55
Quote Anchor link
Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
<?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'].'%" ';
        }

}



?>
 
Erwin H

Erwin H

28/02/2013 12:09:02
Quote Anchor link
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
<?php
$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.
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.