Ondeindige while loop database

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Joni Fleischer

Joni Fleischer

30/11/2009 16:01:00
Quote Anchor link
Hallo allemaal,

Ik heb het volgende:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
if(!empty($_POST['soort']) && !empty($_POST['catagorie'])) {
                if(isset($_POST['catagorie']) && $_POST['catagorie'] == "alle") {
                    $search = " AND soort = '".$_POST['soort']."'";
                }
                else {
                    $search = " AND soort = '".$_POST['soort']."' AND cat = '".$_POST['catagorie']."'";
                }
            }
            $Sql = "SELECT titel,album,datum,prijs,SUBSTRING_INDEX(advertentietekst, '\\r\\n', 4) AS eerste4regels
            FROM advertentie WHERE titel LIKE '%".$_POST['term']."%' OR advertentietekst LIKE '%".$_POST['term']."%'".$search." ORDER BY datum DESC LIMIT 15";


Nu als ik dit in een while gooi met een mysql_fetch_array eraan,
dan looped hij hem ONEINDIG :S

Heeft iemand enig idee hoe dat kan??

Alvast bedankt
 
PHP hulp

PHP hulp

25/04/2024 07:41:51
 
Computer

Computer

30/11/2009 16:07:00
Quote Anchor link
Mag ik de code zien met de while loop, de mysql_fetch_array en met de mysql_query?
 
Joni Fleischer

Joni Fleischer

30/11/2009 16:09:00
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
    if(empty($_POST['actie'])) { $SearchForm = true;
        echo 'Vul hieronder uw zoekvoorwaarden in:<br /><br />';
    }

    else {
        if(empty($_POST['term'])) {
            echo '<font color="#FF0000"><b>U heeft geen zoekterm ingevuld.</b></font>';
            $SearchForm = true;
        }

        else {
            if(!empty($_POST['soort']) && !empty($_POST['catagorie'])) {
                if(isset($_POST['catagorie']) && $_POST['catagorie'] == "alle") {
                    $search = " AND soort = '".$_POST['soort']."'";
                }

                else {
                    $search = " AND soort = '".$_POST['soort']."' AND cat = '".$_POST['catagorie']."'";
                }
            }

            $Sql = "SELECT titel,album,datum,prijs,SUBSTRING_INDEX(advertentietekst, '\\r\\n', 4) AS eerste4regels
            FROM advertentie WHERE titel LIKE '%"
.$_POST['term']."%' OR advertentietekst LIKE '%".$_POST['term']."%'".$search." ORDER BY datum DESC LIMIT 15";
            if(mysql_num_rows(mysql_query($Sql))) {
                echo 'Aantal zoekresultaten: '.mysql_num_rows(mysql_query($Sql)).'<br><br>';
                while($sql = mysql_fetch_array(mysql_query($Sql))) {
                    $class = ($bool = ($bool ^ 2)) ? 'content_sub_blue_small' : 'content_sub_orange_small';
                    $map = "images/advertenties/".$sql['album']."/";
                      echo '<tr>
                       <td align="center" class="'
.$class.'" rowspan="2">';
                     if(file_exists($map.$sql['album']."_1.jpg")) {
                        echo '<img src="php/thumb.php?foto=../'.$map.$sql['album'].'_1.jpg&max=90" style="border:#000 1px solid;cursor:hand;">';
                    }
else { echo '<img src="images/geen_foto.jpg" width="90" height="68" style="border:#000 1px solid;cursor:hand;">'; }
                     echo '</td>
                        <td class="'
.$class.'" valign="top" height="15" style="border-right:#000 1px solid;border-left:#000 1px solid;">
                     '
.date("d-m-Y", $sql['datum']).'</td>
                        <td class="'
.$class.'" valign="top" height="15" style="border-right:#000 1px solid;">
                     <a href="#">'
.ucfirst(strtolower($sql['titel'])).'</a></td>
                       <td class="'
.$class.'" valign="top" height="15" style="border-right:#000 1px solid;">'.$sql['prijs'].'</td>
                      </tr>
                    <tr>
                    <td colspan="3" class="'
.$class.'" valign="top">'.$sql['eerste4regels'].'</td>
                    </tr>'
;
                }
            }

            else {
                echo 'Niks';
            }
        }
    }

?>
 
Joni Fleischer

Joni Fleischer

30/11/2009 16:10:00
Quote Anchor link
Heb je hier wat aan?
 
Computer

Computer

30/11/2009 16:11:00
Quote Anchor link
De mysql_query staat in de while loop en wordt dus steeds opnieuw uitgevoerd. Ik post zo wel een alternatieve code.

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
    if(empty($_POST['actie'])) { $SearchForm = true;
        echo 'Vul hieronder uw zoekvoorwaarden in:<br /><br />';
    }

    else {
        if(empty($_POST['term'])) {
            echo '<font color="#FF0000"><b>U heeft geen zoekterm ingevuld.</b></font>';
            $SearchForm = true;
        }

        else {
            if(!empty($_POST['soort']) && !empty($_POST['catagorie'])) {
                if(isset($_POST['catagorie']) && $_POST['catagorie'] == "alle") {
                    $search = " AND soort = '".$_POST['soort']."'";
                }

                else {
                    $search = " AND soort = '".$_POST['soort']."' AND cat = '".$_POST['catagorie']."'";
                }
            }

            $Sql = "SELECT titel,album,datum,prijs,SUBSTRING_INDEX(advertentietekst, '\\r\\n', 4) AS eerste4regels
            FROM advertentie WHERE titel LIKE '%"
.$_POST['term']."%' OR advertentietekst LIKE '%".$_POST['term']."%'".$search." ORDER BY datum DESC LIMIT 15";
$Sql_resultaat = mysql_query($Sql);
            if(mysql_num_rows($Sql_resultaat)) {
                echo 'Aantal zoekresultaten: '.mysql_num_rows($Sql_resultaat).'<br><br>';
$Sql_resultaat = mysql_query($Sql);
                while($sql = mysql_fetch_array($Sql_resultaat)) {
                    $class = ($bool = ($bool ^ 2)) ? 'content_sub_blue_small' : 'content_sub_orange_small';
                    $map = "images/advertenties/".$sql['album']."/";
                      echo '<tr>
                       <td align="center" class="'
.$class.'" rowspan="2">';
                     if(file_exists($map.$sql['album']."_1.jpg")) {
                        echo '<img src="php/thumb.php?foto=../'.$map.$sql['album'].'_1.jpg&max=90" style="border:#000 1px solid;cursor:hand;">';
                    }
else { echo '<img src="images/geen_foto.jpg" width="90" height="68" style="border:#000 1px solid;cursor:hand;">'; }
                     echo '</td>
                        <td class="'
.$class.'" valign="top" height="15" style="border-right:#000 1px solid;border-left:#000 1px solid;">
                     '
.date("d-m-Y", $sql['datum']).'</td>
                        <td class="'
.$class.'" valign="top" height="15" style="border-right:#000 1px solid;">
                     <a href="#">'
.ucfirst(strtolower($sql['titel'])).'</a></td>
                       <td class="'
.$class.'" valign="top" height="15" style="border-right:#000 1px solid;">'.$sql['prijs'].'</td>
                      </tr>
                    <tr>
                    <td colspan="3" class="'
.$class.'" valign="top">'.$sql['eerste4regels'].'</td>
                    </tr>'
;
                }
            }

            else {
                echo 'Niks';
            }
        }
    }

?>

Daar heb je het. Omdat de mysql_query in de while stond werd die steeds opnieuw uitgevoerd.
Gewijzigd op 01/01/1970 01:00:00 door Computer
 
Joni Fleischer

Joni Fleischer

30/11/2009 16:18:00
Quote Anchor link
HAha, ja nou zie ik het,
normaal doe ik dat nooit, heb er nu gewoon:

$Sql = mysql_query("SELECT titel,album,datum,prijs,SUBSTRING_INDEX(advertentietekst, '\\r\\n', 4) AS eerste4regels
FROM advertentie WHERE titel LIKE '%".$_POST['term']."%' OR advertentietekst LIKE '%".$_POST['term']."%'".$search." ORDER BY datum DESC LIMIT 15");

Van gemaakt, werkt ook ;)

thnx

Domme fout :S
 
Computer

Computer

30/11/2009 16:18:00
Quote Anchor link
Heb je daar wat aan?
(ik denk het wel)

Edit:
Ja dus, mijn browser doet raar dus ik kan niet zo snel reageren :S
Gewijzigd op 01/01/1970 01:00:00 door Computer
 



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.