While lus over meerdere tabellen.

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Niels Cup

Niels Cup

08/01/2013 15:24:06
Quote Anchor link
Ik heb een pagina dat de voorpagina van een webshop moet worden met daarin 4 artikelen. De HTML is zo
bagger als wat dat weet ik maar daar gaat het nu even niet om. Vanuit een tblartikelen moet 4 tabellen gevuld worden. Elke tabel bevat de titel van 1 product, een afbeelding een prijs en een omschrijving.Ik heb while icm mysql_fetcharray in icm met SELECT * FROM artikelen LIMIT 1 dan wordt 1 tabel netjes gevuld
Wanneer ik Limit op 4 zet dan heb ik dat alles gevuld wordt echter dat werkt niet. Weet iemand welke techniek ik moet gebruiken om 4 tabellen te vullen met data uit een tblproducten dat elk een unieke ID_ARTIKELNUMMER heeft?



Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
<?php
session_start();
ini_set('error_display', '1');
error_reporting('E_ALL');
?>

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
<?php
include_once('includes/connect_to_mysql.php');
?>

<doctype html public>
<html dir=ltr lang=nl>
<head>
<title>Onlinewinkel-24u</title>
<meta content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<link rel="stylesheet" type="text/css" href="index_files/stylesheet.css">
<meta name=generator content="MSHTML 8.00.6001.18876">
</head>
<body bottommargin=0 leftmargin=0 rightmargin=0 topmargin=0 marginheight="0" marginwidth="0">
<!-- header //-->
<table border=0 cellspacing=0 cellpadding=0 width=766 align=center height=580>
<tbody>
<tr>
<td height=92 background=index_files/index_02.jpg width=766></td>
</tr>
<tr>
<td height=42 background=index_files/index_04.jpg width=766>
<table border=0 cellSpacing=0 cellPadding=0 width="100%">
<tbody>
<tr>
<td width=640><div style="padding-left: 15px"><a class=headerNavigation href="index.php">Home</a>
<img border=0 hspace=4 align=absMiddle src="index_files/nav_divider.gif" width=1 height=27>
<a class=headerNavigation href="shopping_cart.php">Winkelwagen</a> <img border=0 hspace=4 align=absMiddle
src="index_files/nav_divider.gif" width=1 height=27>
<a class=headerNavigation href="create_account.php">Klant worden</a><img border=0 hspace=4 align=absMiddle
src="index_files/nav_divider.gif" width=1 height=27> <a
class=headernavigation
href="login.php">Inloggen</A> <IMG border=0 hspace=4 align=absMiddle
src="index_files/nav_divider.gif" width=1 height=27> <a
class=headerNavigation
href="contact_us.php">Contact</a></div></td>
</tr>
</tbody>
</table></td>
</tr>
<tr>
<td height=580 valign=top background=index_files/index_06.gif width=766><!-- header_eof //-->
<!-- body //-->
<table border=0 cellspacing=3 cellpadding=3 width="100%">
<tbody>
<tr>
<Td valign=top width=box_width><table border=0 cellSpacing=0 cellPadding=2 width=box_width>
<!-- left_navigation //-->
<!-- categories //-->
<tbody>
<tr>
<td height=28 background=index_files/info_header.gif><table border=0 cellSpacing=0 cellPadding=0 width="100%">
<tbody>
<tr>
<td class=infoBoxHeading height=14 width="100%">Categoriëen</td>
<td class=infoBoxHeading height=14 noWrap><img border=0
alt="" src="index_files/pixel_trans.gif" width=11
height=14></td>
</tr>
</tbody>
</table></td>
</tr>
<tr>
<td class=box_categories><table>
<tbody>
<tr>
<td><div style="padding-left: 10px" align=left>
<table class=infoBox border=0 cellSpacing=0
cellPadding=1 width="100%">
<tbody>
<tr>
<td><table class=infoBoxContents border=0
cellSpacing=0 cellPadding=3 width="100%">
<tbody>
<tr>
<td><img border=0 alt=""
src="index_files/pixel_trans.gif" width="100%"
height=1></td>
</tr>
<tr>
<td class=boxText>
<tr>
<td class=category_meny><img hspace=0 vspace=2
align=absMiddle
src="index_files/cat_arrow_right.gif">&nbsp;<A
class=category_link
href="index.php?cPath=36">Accessoires</A>
<tr>
<td class=category_meny><img hspace=0 vspace=2
align=absMiddle
src="index_files/cat_arrow_right.gif">&nbsp;<A
class=category_link
href="index.php?cPath=39">Accu's</A>
<tr>
<td class=category_meny><img hspace=0 vspace=2
align=absMiddle
src="index_files/cat_arrow_right.gif">&nbsp;<A
class=category_link
href="index.php?cPath=41">Handsfree</A>
<tr>
<td class=category_meny><img hspace=0 vspace=2
align=absMiddle
src="index_files/cat_arrow_right.gif">&nbsp;<a
class=category_link
href="index.php?cPath=40">Headset</A>
<tr>
<td class=category_meny><img hspace=0 vspace=2
align=absMiddle
src="index_files/cat_arrow_right.gif">&nbsp;<a
class=category_link
href="index.php?cPath=38">Hoesjes</a>
<tr>
<td class=category_meny><img hspace=0 vspace=2
align=absMiddle
src="index_files/cat_arrow_right.gif">&nbsp;<a
class=category_link
href="index.php?cPath=37">Opladers</a>
<tr>
<td class=category_meny><img hspace=0 vspace=2
align=absMiddle
src="index_files/cat_arrow_right.gif">&nbsp;<a
class=category_link
href="index.php?cPath=35">Telefoons</a></td>
</tr>
<tr>
<td><img border=0 alt=""
src="index_files/pixel_trans.gif" width="100%"
height=1></td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table>
</div>
<div style="padding-left: 28px" align=left><A
class=adv_searchlink
href="advanced_search.php">Uitgebreid
zoeken</a></div></td>
</tr>
</tbody>
</table>
<br></td>
</tr>
<tr>
<td height=5></td>
</tr>
<!-- categories_eof //-->
<!-- shopping_cart //-->
<tr>
<td height=28 background=index_files/info_header.gif><table border=0 cellSpacing=0 cellPadding=0 width="100%">
<tbody>
<tr>
<td class=infoBoxHeading height=14
width="100%">Winkelwagen</TD>
</tr>
</tbody>
</table></td>
</tr>
<tr>
<td class=box_cart><div style="margin: 10px; width: 135px">
<table class=infoBox border=0 cellSpacing=0 cellPadding=1
width="100%">
<tbody>
<tr>
<td><table class=infoBoxContents border=0 cellSpacing=0
cellPadding=3 width="100%">
<tbody>
<tr>
<td><img border=0 alt=""
src="index_files/pixel_trans.gif" width="100%"
height=1></td>
</tr>
<tr>
<td class=boxText><center>
Geen artikelen
</center></TD>
</tr>
<tr>
<td><img border=0 alt=""
src="index_files/pixel_trans.gif" width="100%"
height=1></td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table>
</div>
<tr>
<td height=5></td>
</tr>
<!-- shopping_cart_eof //-->
<tr>
<td height=28 background=index_files/info_header.gif><table border=0 cellSpacing=0 cellPadding=0 width="100%">
<tbody>
<tr>
<td class=infoBoxHeading height=14
width="100%">Informatie</TD>
<td class=infoBoxHeading height=14 noWrap><img border=0
alt="" src="index_files/pixel_trans.gif" width=11
height=14></td>
</tr>
</tbody>
</table></td>
</tr>
<tr>
<td class=box_info><table class=infoBox border=0 cellSpacing=0 cellPadding=1
width="100%">
<tbody>
<tr>
<td><table class=infoBoxContents border=0 cellSpacing=0
cellPadding=3 width="100%">
<tbody>
<tr>
<td><img border=0 alt=""
src="index_files/pixel_trans.gif" width="100%"
height=1></td>
</tr>
<tr>
<td class=boxText><img
src="index_files/cat_arrow_right.gif">&nbsp;<a
href="information.php?info_id=11">Over
de iPhone</a><br>
<img src="index_files/cat_arrow_right.gif">&nbsp;
<a href="information.php?info_id=13">Meest gestelde vragen</a><br>
<img src="index_files/cat_arrow_right.gif">&nbsp;
<a href="information.php?info_id=15">Voorwaarden</a><br>
<img src="index_files/cat_arrow_right.gif">&nbsp;<a
href="information.php?info_id=16">Over ons bedrijf</a><br>
<img src="index_files/cat_arrow_right.gif">&nbsp;
<a href="information.php?info_id=17">test</a><br>
<img hspace=0 vspace=2 align=left
src="index_files/cat_arrow_right.gif">&nbsp;<A
href="contact_us.php">Contact</a></td>
</tr>
<tr>
<td><img border=0 alt=""
src="index_files/pixel_trans.gif" width="100%"
height=1></td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table>
<center>
<br>
<img
src="index_files/logos_algemeen.jpg"><br>
<br>
</center></td>
</tr>
<!-- information_eof //-->
<!-- left_navigation_eof //-->
</tbody>
</table></td>
<!-- body_text //-->
<td valign=top width="100%"><table border=0 cellSpacing=0 cellPadding=0 width="100%">
<tbody>
<tr>
<td><table class=infoBox_voor border=0 cellSpacing=1 cellPadding=4
width="98%" align=center>
<tbody>
<tr>
<td class=main>
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
<?php echo $dynamischeTekst; ?>
</td>
</tr>
</tbody>
</table>
<br>
<!-- new_products //-->
<table class=infoBox border=0 cellSpacing=0 cellPadding=1 width="100%">
<tbody>
<tr>
<td><table class=infoBoxContents border=0 cellSpacing=0 cellPadding=0 width="100%">
<tbody>
<tr>
<td class=smallText vAlign=top align=left><div
style="padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px">
<table class=box_outline border=0 cellSpacing=3
cellPadding=0 width=278 height=160>
<tbody>
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
<?php  
$rsProducten
= mysql_query("SELECT * FROM tblartikelen LIMIT 1 ", $intDb);
if(!rsProducten)
 die("De SQL opdracht klopt niet");

while($rProducten = mysql_fetch_array($rsProducten))
   {

?>

<tr>
<td bgColor=#ebebeb height=30 vAlign=center
colSpan=2><a class=box_name
href="product_info.php?products_id=39">
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
<?php echo($rProducten['Artikelnaam']); ?>
</a></td>
</tr>
<tr>
<td vAlign=center width=115 align=middle><a
href="product_info.php?products_id=39"><img
title="" border=0
alt=""
src="index_files/
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
<?php echo($rProducten['Afbeelding']); ?>
.jpg" width=100
height=80></A></td>
<td background=index_files/box_back.gif><table border=0 width="100%" height=121>
<tbody>
<tr>
<td class=box_desc vAlign=top colSpan=2
align=left><div
style="padding-right: 10px; padding-top: 7px">
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
<?php echo($rProducten['Omschrijving']); ?>
</div></td>
</tr>
<tr>
<td class=box_price height=40 vAlign=center
width=60 align=middle>
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
<?php echo($rProducten['Prijs']); ?>
</TD>
<td vAlign=center><A
href="product_info.php?products_id=39"><img
border=0 alt=""
src="index_files/button_buy_now.gif" width=57
height=16></a></td>
</tr>
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
<?php
                                                       }
                                                       mysql_free_result($rsProducten);
                                                       mysql_close($intDb);
                                                       //einde while
                                                      ?>

</tbody>
</table></td>
</tr>
</tbody>
</table>
</div></td>
<td class=smallText vAlign=top align=left><div
style="padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px">

<table class=box_outline border=0 cellSpacing=3
cellPadding=0 width=278 height=160>
<tbody>
<tr>
<td bgColor=#ebebeb height=30 vAlign=center
colSpan=2><a class=box_name
href="product_info.php?products_id=35"></a></td>
</tr>
<tr>
<td valign=center width=115 align=middle><a
href="product_info.php?products_id=35"><img
title="" border="0"
alt=""
src="index_files/.jpg" width=100
height=80></a></td>
<td background=index_files/box_back.gif><table border=0 width="100%" height=121>
<tbody>
<tr>
<td class=box_desc vAlign=top colSpan=2
align=left><div
style="padding-right: 10px; padding-top: 7px"></div></td>
</tr>
<tr>
<td class=box_price height=40 vAlign=center
width=60 align=middle></td>
<td vAlign=center><a
href="product_info.php?products_id=35"><img
border=0 alt=""
src="index_files/button_buy_now.gif" width=57
height=16></a></td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table>
</div></td>
</tr>
<tr>
<td class=smallText vAlign=top align=left><div
style="padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px">
<table class=box_outline border=0 cellSpacing=3
cellPadding=0 width=278 height=160>
<tbody>
<tr>
<td bgColor=#ebebeb height=30 vAlign=center
colSpan=2><a class=box_name
href="product_info.php?products_id=37"></a></td>
</tr>
<tr>
<td valign=center width=115 align=middle>
<a href="product_info.php?products_id=37">
<img title="" border=0 alt="" src="index_files/.jpg" width=100 height=80></a></td>
<td background=index_files/box_back.gif><table border=0 width="100%" height=121>
<tbody>
<tr>
<td class=box_desc vAlign=top colSpan=2 align=left>
<div style="padding-right: 10px; padding-top: 7px"></div></td>
</tr>
<tr>
<td class=box_price height=40 vAlign=center
width=60 align=middle></td>
<td vAlign=center><a
href="product_info.php?products_id=37"><img
border=0 alt=""
src="index_files/button_buy_now.gif" width=57
height=16></a></td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table>
</div></td>
<td class=smallText vAlign=top align=left><div
style="padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px">
<table class=box_outline border=0 cellSpacing=3
cellPadding=0 width=278 height=160>
<tbody>
<tr>
<td bgColor=#ebebeb height=30 valign=center
colSpan=2><a class=box_name
href="product_info.php?products_id=36"></a></td>
</tr>
<tr>
<td valign=center width=115 align=middle>
<a href="product_info.php?products_id=36"><img
title="" border=0 alt="" src="index_files/.jpg" width=100
height=80></a></td>
<td background=index_files/box_back.gif><table border=0 width="100%" height=121>
<tbody>
<tr>
<td class=box_desc valign=top colSpan=2
align=left><div
style="padding-right: 10px; padding-top: 7px"></div></td>
</tr>
<tr>
<td class=box_price height=40 vAlign=center
width=60 align=middle></td>
<td vAlign=center><a
href="product_info.php?products_id=36"><img
border=0 alt=""
src="index_files/button_buy_now.gif" width=57
height=16></a></td>
</tr>

</tbody>
</table></td>
</tr>
</tbody>
</table>
</div></td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table>
<!-- new_products_eof //-->
<br></td>
</tr>
</tbody>
</table></td>
<!-- body_text_eof //-->
</tr>
</tbody>
</table>
<!-- body_eof //-->
<!-- footer //--></td>
</tr>
<tr>
<td height=55 background=index_files/index_08.jpg width=954 colSpan=2><div style="padding-bottom: 0px; padding-right: 20px" class=footerText
align=right>Online-24u | <a
href="conditions.php">Algemene
voorwaarden</A> - <A
href="privacy.php">Privacybeleid</a> </div></td>
</tr>
</tbody>
</table>
<br>
<!-- footer_eof //-->
<br>
</body>
</html>
 
PHP hulp

PHP hulp

02/05/2024 07:40:41
 
No One

No One

08/01/2013 15:25:42
Quote Anchor link
kun je de html ook even tussen code tags zetten??
 
Obelix Idefix

Obelix Idefix

08/01/2013 15:51:00
Quote Anchor link
En misschien is het verstandig om alleen _relevante_ code te plaatsen ?!
Is dit overigens dezelfde vraag als in http://www.phphulp.nl/php/forum/topic/while-loop-en-tabellen/88451/ ? Alleen dat 'wat' meer code/tekst?
Gewijzigd op 08/01/2013 15:52:05 door Obelix Idefix
 
Niels Cup

Niels Cup

08/01/2013 16:09:34
Quote Anchor link
Dit is de while lus die ik gebruik:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
<?php  
$rsProducten
= mysql_query("SELECT * FROM tblartikelen LIMIT 1 ", $intDb);
if(!rsProducten)
 die("De SQL opdracht klopt niet");

while($rProducten = mysql_fetch_array($rsProducten))
   {

?>
 
Erwin H

Erwin H

08/01/2013 18:14:42
Quote Anchor link
Waarom zou je daar een while loop gebruiken? Je hebt er een LIMIT 1 in staan, dus hoe dan ook krijg je altijd maar maximaal 1 record terug.
 
Niels Cup

Niels Cup

08/01/2013 18:20:35
Quote Anchor link
Die LIMIT moet weg. Het probleem waar ik nu mee zitten is dat elke tabel met dezelfde record wordt gevuld.
 
Obelix Idefix

Obelix Idefix

08/01/2013 18:23:32
Quote Anchor link
Niels Cup op 08/01/2013 18:20:35:
Het probleem waar ik nu mee zitten is dat elke tabel met dezelfde record wordt gevuld.

Dat gaat dus toch over een INSERT (of UPDATE)-query en niet over de SELECT die je laat zien?
Niels Cup op 08/01/2013 16:09:34:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
<?php  
$rsProducten
= mysql_query("SELECT * FROM tblartikelen LIMIT 1 ", $intDb);
?>
 
Erwin H

Erwin H

08/01/2013 18:26:38
Quote Anchor link
Post dan svp de daadwerkelijke code, en alleen relevante code. Zolang je foute code post kunnen wij natuurlijk nooit het probleem achterhalen (en die berg overbodige html helpt ook niet).
 
Niels Cup

Niels Cup

08/01/2013 18:48:06
Quote Anchor link
Dat heb ik gedaan Erwin. Zie mijn PHP blok hierboven.
 
Erwin H

Erwin H

08/01/2013 18:57:07
Quote Anchor link
Ik zie nog steeds een berg nutteloze html en een LIMIT 1. Dus probeer het nog eens zou ik zeggen.
 
Niels Cup

Niels Cup

08/01/2013 19:03:58
Quote Anchor link
Voor de eerste Table row plaats ik deze code:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
<?php
                                $intDb
= mysql_connect("localhost", "root", "");
                                 if (!$intDb)
                                  die("Kan niet verbinden naar de db server");
                                   mysql_selectdb("webshop", $intDb);
                                      $strArtikelen = mysql_query("select * from tblartikelen", $intDb);
                                       if (!tblartikelen)
                                        die("De SQL opdracht klopt niet.");
                                       while ($strArtikelen = mysql_fetch_array($strArtikelen))
                                {

?>

Na de laatste table row plaats ik deze code
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
<?php
                                                       }
                                                       mysql_free_result($rsProducten);
                                                       mysql_close($intDb);
                                                       //einde while

                                                      ?>


Daar tussenin staat dus dieberg HTML code
 
Erwin H

Erwin H

08/01/2013 19:07:52
Quote Anchor link
Hoeveel rijen krijg je terug en wat wil je precies met die rijen doen? Je wil het in een tabel zetten (of meerdere tabellen), maar wat is het probleem daarmee?
 
Niels Cup

Niels Cup

08/01/2013 19:21:50
Quote Anchor link
Je gebruikt dus een tabel om een product met afbeelding, prijs en omschrijving te tonen. In totaal
zijn hiervoor 4 <table> tags in de pagina. Kun je dan met 1 while lus al die tabellen vullen?
 
Erwin H

Erwin H

08/01/2013 19:24:54
Quote Anchor link
Antwoord is ja, vraag is alleen nog even hoe.

Heb je per product een tabel, of heb je per kenmerk een tabel?
 
Niels Cup

Niels Cup

08/01/2013 19:26:32
Quote Anchor link
Per product een tabel.
 
Erwin H

Erwin H

08/01/2013 19:43:00
Quote Anchor link
Als het per product is dan is het kinderlijk eenvoudig:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
<?php
while ($row = mysql_fetch_array($strArtikelen)){
  echo '<table>';
  echo '<tr>';
  echo '<td>'.$row['afbeelding'].'</td>';
  echo '<td>'.$row['prijs'].'</td>';
  echo '<td>'.$row['omschrijving'].'</td>';
  echo '</tr>';
  echo '</table>';
}

?>

Let alleen op dat ik je while conditie iets heb aangepast naar while ($row = mysql_fetch_array($strArtikelen)){
($row ipv $strArtikelen). Je query uitkomst had nu dezelfde variabele als de rij met gegevens, dat leek me niet echt handig...
 
Ger van Steenderen
Tutorial mod

Ger van Steenderen

08/01/2013 20:59:11
Quote Anchor link
En Niels kan je even je start topic aanpassen, haal de al de html eruit.
 



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.