Het resultaat toont mij 1 record te weinig

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Pagina: 1 2 volgende »

Leon Low

Leon Low

29/09/2019 17:43:12
Quote Anchor link
Voor mijn voorraad wens ik de matenbalk horizontaal te halen uit de tabel.
Mijn tabel is als volgt :

ID Voorraad_ID Matenbalk Maat Aantal
1 1 1 S 1
2 1 1 M 2
3 1 1 L NULL
4 2 2 38 1
5 2 2 40 NULL
6 2 2 44 1

Mijn code is de volgende :
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
<?php
$qry
= mysql_query( "SELECT * FROM voorraad_maten ORDER By Matenbalk, ID asc" );
$qryMinMax = mysql_query( "SELECT MIN(Voorraad_ID) as 'Min', MAX(Voorraad_ID) as 'Max' From voorraad_maten" );
$rowMax = mysql_fetch_array( $qryMinMax );
$max = $rowMax[ 'Max' ];
$min = $rowMax[ 'Min' ];
?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Naamloos document</title>
</head>
<body>
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
<?php
echo "<table border='solid 1px' width=75%>";
for ( $i = $min; $i <= $max; $i++ ) {
  echo "<tr>";
  echo "<td align='center'> Balk-" . $i . "</td>";
  while ( ( ( $row = mysql_fetch_array( $qry ) )and( $row[ 'Voorraad_ID' ] ) == $i ) ) {
    if ( ( is_null( $row[ 'Aantal' ] ) ) ) {
      $quant = 0;
    }
else {
      $quant = $row[ 'Aantal' ];
    }

    echo "<th align='center'>" . $row[ 'Maat' ] . "</th>";
    echo "<td align='center'>" . $quant . "</td>";
  }
}

echo "</tr>";
echo "</table>";
?>

</table>
</body>
</html>

Het resultaat is niet in orde omdat ik graag het als volg had :
Balk 1 - S M L
1 2 0
Balk 2 - 38 40 44
1 0 1
Maar maat 38 valt weg en het aantal komt langs de maat ipv onder de maat.
Graag hulp aub...
 
PHP hulp

PHP hulp

28/03/2024 18:48:32
 
- Ariën  -
Beheerder

- Ariën -

29/09/2019 17:45:20
Quote Anchor link
Wordt het niet tijd om over te stappen op mysqli of PDO?
Want de oude mysql_xxxx() functies zou je eigenlijk al niet meer moeten gebruiken omdat deze PHP-versies verouderd zijn.
Gewijzigd op 29/09/2019 17:45:30 door - Ariën -
 
Frank Nietbelangrijk

Frank Nietbelangrijk

29/09/2019 19:18:50
Quote Anchor link
Dus eigenlijk wil je alle records onder elkaar hebben in een bepaalde volgorde en een scheiding maken wanneer er aan een nieuwe balk wordt begonnen?

En wat Ariën zegt.. mysql_ functies worden in de nieuwste php versies niet meer ondersteund.

$qry = mysql_query(..) ==> mysql_query geeft een resultaat terug en geen query! Toepasselijke namen voor je variabelen gebruiken is ook zo een ding tussen een opgeruimd huis en wanorde :-)
Gewijzigd op 29/09/2019 19:23:47 door Frank Nietbelangrijk
 
Leon Low

Leon Low

29/09/2019 19:26:42
Quote Anchor link
Het huidige resultaat zie op de link https://www.lowet.be/Webshop2/testHorizontaal.php.
Maar ik wens de S M L
1 2 0
38 40 44
1 0 1

Dank voor reactie

Toevoeging op 29/09/2019 19:31:20:

https://lowet.be/Webshop2/testHorizontaal.php
 
Frank Nietbelangrijk

Frank Nietbelangrijk

29/09/2019 21:22:11
Quote Anchor link
Ja dat is een leuke voor een dubbele do{ .. }while(); lus..
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
<?php
$query
= 'SELECT * FROM maten ORDER BY balk';
$result = mysqli_query($con, $query);

if(false === $result) {
    echo mysqli_error($con);
    die();
}


$row = mysqli_fetch_assoc($result); // haal de eerste rij op

?>

<html>
    <head>
        <meta charset="UTF-8">
        <title>test</title>
    </head>
    <body>
        <?php if($row): ?> <!-- als er een rij beschikbaar was -->
        <table>
            <tbody>
                <?php do { ?> <!-- start een do-while lus voor iedere balk -->
                <tr>
                    <th><?php echo 'Balk-' . $row['balk']; ?></th>
                    <?php
                        $currentBalk
= $row['balk']; // onthoud in welke balk we bezig zijn
                        do { // start een do-while lus voor iedere kledingmaat
                            echo '<td>' . $row['maat'].'</td>';
                            echo '<td>[' . $row['aantal'].']</td>';
                            $row = mysqli_fetch_assoc($result); // haal de volgende rij op!
                        }while($row && $currentBalk == $row['balk']); // zolang we nog een nieuwe rij konden ophalen EN de nieuwe rij bij de huidige balk hoort.
                    ?>

                </tr>
                <?php }while($row); ?> <!-- zolang we nog een nieuwe rij konden ophalen -->
            </tbody>
        </table>
        <?php else: ?>
            geen resultaten gevonden.
        <?php endif; ?>
    </body>
</html>


De kolomnamen moet je wel even aanpassen, en ik heb geen mysql_ functies beschikbaar..
Gewijzigd op 29/09/2019 21:41:08 door Frank Nietbelangrijk
 
Leon Low

Leon Low

30/09/2019 15:49:52
Quote Anchor link
Bedankt voor hulp.
 
Frank Nietbelangrijk

Frank Nietbelangrijk

30/09/2019 17:38:47
Quote Anchor link
Is het gelukt?
 
Leon Low

Leon Low

30/09/2019 17:41:10
Quote Anchor link
Het is gelukt... Maar ik moet dit nu integreren in een grotere tabel. En dat lukt mij niet zo meteen.
Mag ik de totale code doorgeven ?? Wellicht kun je me hiermee op weg helpen.
Gewijzigd op 02/10/2019 09:55:16 door Leon Low
 
- Ariën  -
Beheerder

- Ariën -

30/09/2019 17:46:18
Quote Anchor link
Laat je relevante code (geen tientallen regels) maar zien tussen code-tags.
Gewijzigd op 30/09/2019 17:46:46 door - Ariën -
 
Leon Low

Leon Low

30/09/2019 17:48:31
Quote Anchor link
bedankt
Gewijzigd op 02/10/2019 09:56:10 door Leon Low
 
- Ariën  -
Beheerder

- Ariën -

30/09/2019 17:54:10
Quote Anchor link
Kan je het tussen code-tags zetten? (Zie opmaakcodes in Veelgestelde Vragen). Dan is het wat beter leesbaarder.
 
Leon Low

Leon Low

30/09/2019 18:14:19
Quote Anchor link
Ik vermoed dat je dit bedoelt ??
Gewijzigd op 02/10/2019 09:53:20 door Leon Low
 
Adoptive Solution

Adoptive Solution

30/09/2019 18:17:34
Quote Anchor link
In plaats van <td> met vet en gecentreerd, kan je ook <th> gebruiken:

https://www.w3schools.com/tags/tag_thead.asp

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
<table>
    <thead>
        <tr>
            <th>ID</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td align='center'><?php echo $row[ 'ID' ]; ?></td>
        </tr>
    </tbody>
</tble>
 
Frank Nietbelangrijk

Frank Nietbelangrijk

30/09/2019 19:24:42
Quote Anchor link
>> Ik vermoed dat je dit bedoelt ??

Nee. zet om je derde post even [code] en [/code]. Je HTML onder in wordt dan ook mee gepakt in plaats van enkel je php blokken.
 
Leon Low

Leon Low

30/09/2019 19:31:42
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
include "storescripts/connect_to_mysql.php";
$qryRaadpleeg = mysql_query( "SELECT * FROM merken INNER JOIN (artikelen INNER JOIN voorraad ON artikelen.ArtikelCode = voorraad.Artikelcode) ON merken.MERKCODE = voorraad.Merknr" );
$Aantal = mysql_num_rows( $qryRaadpleeg );
$qryMaten = mysql_query( "SELECT * From voorraad_maten ORDER BY Matenbalk" );
if ( $Aantal > 0 ) {
  echo "<table border='solid 1px' width=90% align='center'>";
  $tabel .= "<tr >";
  $tabel .= "<td align='center'><b>ID</b></td>";
  $tabel .= "<td align='center'><b>MERK</b></td>";
  $tabel .= "<td align='center'><b>ARTIKELNAAM</b></td>";
  $tabel .= "<td  align='center'><b>KLEUR</b></td>";
  $tabel .= "<td  align='center'><b>AP</b></td>";
  $tabel .= "<td  align='center'><b>PRIJS 1</b></td>";
  $tabel .= "<td  align='center'><b>PRIJS 2</b></td>";
  $tabel .= "<td  align='center'><b>ARTIKEL</b></td>";
  $tabel .= "<td  align='center'><b>AFDELING</b></td>";
  $tabel .= "<td  align='center'><b>DATUM BIJVOEGING</b></td>";
  $tabel .= "<td  align='center'><b>OMSCHRIJVING</b></td>";
  $tabel .= "</tr>";
  while ( $row = mysql_fetch_array( $qryRaadpleeg ) ) {
    if ( $row[ 'Afdeling' ] == 1 ) {
      $afdeling = "Dames";
    }
elseif ( $row[ 'Afdeling' ] == 2 ) {
      $afdeling = "Trend";
    }
elseif ( $row[ 'Afdeling' ] == 3 ) {
      $afdeling = "Heren";
    }
elseif ( $row[ 'Afdeling' ] == 4 ) {
      $afdeling = "Schoenen";
    }
else {
      $afdeling = "Ander";
    }

    
      
      $rowMaten=mysql_fetch_array($qryMaten);    
    $tabel .= "<tr>";
    $tabel .= "<td align='center'>" . $row[ 'ID' ] . "</td>";
    $tabel .= "<td align='center'>" . $row[ 'Merkomschrijving' ] . "</td>";
    $tabel .= "<td align='center'>" . $row[ 'Artikelnaam' ] . "</td>";
    $tabel .= "<td align='center'>" . $row[ 'Kleur' ] . "</td>";
    $tabel .= "<td align='right' style='padding-right:5px'>" . $row[ 'AP' ] . "</td>";
    $tabel .= "<td align='right' style='padding-right:5px'>" . $row[ 'VP' ] . "</td>";
    $tabel .= "<td align='right' style='padding-right:5px'>" . $row[ 'VP2' ] . "</td>";
    $tabel .= "<td align='center'>" . $row[ 'Omschrijving' ] . "</td>";
    $tabel .= "<td align='center'>" . $afdeling . "</td>";
    $tabel .= "<td align='center'>" . date( "d-m-Y", strtotime( $row[ 'datum_invoeging' ] ) ) . "</td>";
    $tabel .= "<td align='center'>" . $row[ 'omschrijving' ] . "</td>";
    do { // start een do-while lus voor iedere balk -->
                 $currentBalk = $rowMaten['Matenbalk']; // onthoud in welke balk we bezig zijn
                        do { // start een do-while lus voor iedere kledingmaat
                            $tabel .= '<td>' . $rowMaten['Maat'].'</td>';
                            $tabel .= '<td>[' . $rowMaten['Aantal'].']</td>';
                            $rowMaten = mysqli_fetch_array($qryMaten); // haal de volgende rij op!
                            
                        }while($rowMaten && $currentBalk == $rowMaten['Matenbalk']); // zolang we nog een nieuwe rij konden ophalen EN de nieuwe rij bij de huidige balk hoort.
                            }while($rowMaten);  //zolang we nog een nieuwe rij konden ophalen
      
  }
   $tabel .= "</table>";
  }

mysql_close( $locadatabase );
?>

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Webshop BackOffice Voorraad</title>
<style>
td {
color: black;
}
</style>
</head>

<body>

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
<?php include_once("../Hoofding.html") ?>

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
<div align="center">
<p align="right" style="padding-right: 5%;">

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
<?php echo date('d-m-Y H:m'); ?>

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
</p>
<br />
<div align="center">

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
<?php
        echo $tabel;
?>

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
</div>
</body>
</html>
Gewijzigd op 30/09/2019 19:59:30 door Leon Low
 
- Ariën  -
Beheerder

- Ariën -

30/09/2019 19:45:15
Quote Anchor link
je staat nu code met regelsnummer te copypasten, en dat weer tussen code-tags te plaatsen :P
Check je HTML maar eens ;-)
 
Leon Low

Leon Low

30/09/2019 20:01:43
Quote Anchor link
Voorgaande gewijzigd. Bedoel je het zo??
 
Frank Nietbelangrijk

Frank Nietbelangrijk

30/09/2019 20:06:07
Quote Anchor link
Oef.. Je doet te veel werk en het kan veel makkelijker :-) [code]<de originele code hier plakken>[/code]
en met originele bedoel ik zo vanuit je editor zonder enige aanpassingen.
Gewijzigd op 30/09/2019 20:06:29 door Frank Nietbelangrijk
 
Leon Low

Leon Low

30/09/2019 20:08:32
Quote Anchor link
Oké. Maar is het resultaat nu zoals gewenst?
 
Frank Nietbelangrijk

Frank Nietbelangrijk

30/09/2019 20:38:39
Quote Anchor link
Nee want wij kunnen je code niet in één keer kopiëren om het vervolgens in onze editor te plakken.
 
Leon Low

Leon Low

30/09/2019 20:42: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
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
<?php
include "storescripts/connect_to_mysql.php";
$qryRaadpleeg = mysql_query( "SELECT * FROM merken INNER JOIN (artikelen INNER JOIN voorraad ON artikelen.ArtikelCode = voorraad.Artikelcode) ON merken.MERKCODE = voorraad.Merknr" );
$Aantal = mysql_num_rows( $qryRaadpleeg );
$qryMaten = mysql_query( "SELECT * From voorraad_maten ORDER BY Matenbalk" );
if ( $Aantal > 0 ) {
  echo "<table border='solid 1px' width=90% align='center'>";
  $tabel .= "<thead>";
  $tabel .= "<tr>";
  $tabel .= "<th>ID</th>";
  $tabel .= "<th>MERK</th>";
  $tabel .= "<th>ARTIKELNAAM</th>";
  $tabel .= "<th>KLEUR</th>";
  $tabel .= "<th>AP</th>";
  $tabel .= "<th>PRIJS 1</th>";
  $tabel .= "<th>PRIJS 2</th>";
  $tabel .= "<th>ARTIKEL</th>";
  $tabel .= "<th>AFDELING</th>";
  $tabel .= "<th>DATUM BIJVOEGING</th>";
  $tabel .= "<th>OMSCHRIJVING</th>";
  $tabel .= "</tr>";
  $tabel .= "</thead>";
  while ( $row = mysql_fetch_array( $qryRaadpleeg ) ) {
    if ( $row[ 'Afdeling' ] == 1 ) {
      $afdeling = "Dames";
    }
elseif ( $row[ 'Afdeling' ] == 2 ) {
      $afdeling = "Trend";
    }
elseif ( $row[ 'Afdeling' ] == 3 ) {
      $afdeling = "Heren";
    }
elseif ( $row[ 'Afdeling' ] == 4 ) {
      $afdeling = "Schoenen";
    }
else {
      $afdeling = "Ander";
    }

    $rowMaten = mysql_fetch_array( $qryMaten );
    $tabel .= "<tr>";
    $tabel .= "<td align='center'>" . $row[ 'ID' ] . "</td>";
    $tabel .= "<td align='center'>" . $row[ 'Merkomschrijving' ] . "</td>";
    $tabel .= "<td align='center'>" . $row[ 'Artikelnaam' ] . "</td>";
    $tabel .= "<td align='center'>" . $row[ 'Kleur' ] . "</td>";
    $tabel .= "<td align='right' style='padding-right:5px'>" . $row[ 'AP' ] . "</td>";
    $tabel .= "<td align='right' style='padding-right:5px'>" . $row[ 'VP' ] . "</td>";
    $tabel .= "<td align='right' style='padding-right:5px'>" . $row[ 'VP2' ] . "</td>";
    $tabel .= "<td align='center'>" . $row[ 'Omschrijving' ] . "</td>";
    $tabel .= "<td align='center'>" . $afdeling . "</td>";
    $tabel .= "<td align='center'>" . date( "d-m-Y", strtotime( $row[ 'datum_invoeging' ] ) ) . "</td>";
    $tabel .= "<td align='center'>" . $row[ 'omschrijving' ] . "</td>";
    do { // start een do-while lus voor iedere balk -->
      $currentBalk = $rowMaten[ 'Matenbalk' ]; // onthoud in welke balk we bezig zijn
      do { // start een do-while lus voor iedere kledingmaat
        $tabel .= '<td>' . $rowMaten[ 'Maat' ] . '</td>';
        $tabel .= '<td>[' . $rowMaten[ 'Aantal' ] . ']</td>';
        $rowMaten = mysql_fetch_array( $qryMaten ); // haal de volgende rij op!

      } while ( $rowMaten && $currentBalk == $rowMaten[ 'Matenbalk' ] ); // zolang we nog een nieuwe rij konden ophalen EN de nieuwe rij bij de huidige balk hoort.
    } while ( $rowMaten ); //zolang we nog een nieuwe rij konden ophalen

  }
  $tabel .= "</table>";
}

mysql_close( $locadatabase );
?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Webshop BackOffice Voorraad</title>
<style>
td {
    color: black;
}
thead {
    color: black;
}
</style>
</head>

<body>
<?php include_once("../Hoofding.html") ?>
<div align="center">
<p align="right" style="padding-right: 5%;"><?php echo date('d-m-Y H:m'); ?></p>
<br />
<div align="center">
  <?php
  echo $tabel;
  ?>

</div>
</body>
</html>
Gewijzigd op 30/09/2019 20:55:19 door Leon Low
 

Pagina: 1 2 volgende »



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.