PHP Database Array.
Maar nu heb ik een vraag...
Ik wil mijn adressen allemaal uit mijn database laten laden.
Maar ik weet alleen maar hoe ik er 1 laad op die manier.
Kan iemand mij dit uitleggen hoe ik dit kan laten loopen?
dit is mijn code
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
35
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
<?php
ob_start();
include('includes/LoadDB.php');
$result = mysql_query('SELECT * FROM users_details') or die("Nothing to load...");
?>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="6%" align="center" bgcolor="#E6E6E6"><strong>Voornaam</strong></td>
<td width="53%" align="center" bgcolor="#E6E6E6"><strong>AchterNaam</strong></td>
<td width="15%" align="center" bgcolor="#E6E6E6"><strong>Straat</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Stad</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Postcode</strong></td>
</tr>
<tr>
<?php
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
printf ("<td bgcolor='#FFFFFF'>%s</td>
<td bgcolor='#FFFFFF'>%s</td>
<td align='center' bgcolor='#FFFFFF'>%s</td>
<td align='center' bgcolor='#FFFFFF'>%s</td>
<td align='center' bgcolor='#FFFFFF'>%s</td>",
$row["FirstName"], //Loading FirstName Out of DB
$row["LastName"], //Loading The LastNaame
$row["Street"], //loading the Street
$row["City"], //loading the city.
$row["Number"]); //loading the number
}?>
</tr>
</table>
<?php
$content = ob_get_contents();
ob_end_clean();
include('layout.php');
?>
ob_start();
include('includes/LoadDB.php');
$result = mysql_query('SELECT * FROM users_details') or die("Nothing to load...");
?>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="6%" align="center" bgcolor="#E6E6E6"><strong>Voornaam</strong></td>
<td width="53%" align="center" bgcolor="#E6E6E6"><strong>AchterNaam</strong></td>
<td width="15%" align="center" bgcolor="#E6E6E6"><strong>Straat</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Stad</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Postcode</strong></td>
</tr>
<tr>
<?php
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
printf ("<td bgcolor='#FFFFFF'>%s</td>
<td bgcolor='#FFFFFF'>%s</td>
<td align='center' bgcolor='#FFFFFF'>%s</td>
<td align='center' bgcolor='#FFFFFF'>%s</td>
<td align='center' bgcolor='#FFFFFF'>%s</td>",
$row["FirstName"], //Loading FirstName Out of DB
$row["LastName"], //Loading The LastNaame
$row["Street"], //loading the Street
$row["City"], //loading the city.
$row["Number"]); //loading the number
}?>
</tr>
</table>
<?php
$content = ob_get_contents();
ob_end_clean();
include('layout.php');
?>
Dubbele post..
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
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
<?php
include('includes/LoadDB.php');
$sql = mysql_query("SELECT * FROM users_details");
if ($sql) {
echo '<table width="100%" style="background-color: #CCCCCC; border: 0">
<tr>
<td style="width: 6%; background-color: #E6E6E6; font-weight: bold">Voornaam</td>
<td style="width: 53%; background-color: #E6E6E6; font-weight: bold">Achternaam</td>
<td style="width: 16%; background-color: #E6E6E6; font-weight: bold">Straat</td>
<td style="width: 13%; background-color: #E6E6E6; font-weight: bold">Stad</td>
<td style="width: 13%; background-color: #E6E6E6; font-weight: bold">Postcode</td>
</tr>';
while ($result = mysql_fetch_assoc($sql)) {
echo '<tr>
<td style="width: 6%; background-color: #FFFFFF; font-weight: bold">'.$row['FirstName'].'</td>
<td style="width: 53%; background-color: #FFFFFF; font-weight: bold">'.$row['LastName'].'</td>
<td style="width: 16%; background-color: #FFFFFF; font-weight: bold">'.$row['Street'].'</td>
<td style="width: 13%; background-color: #FFFFFF; font-weight: bold">'.$row['City'].'</td>
<td style="width: 13%; background-color: #FFFFFF; font-weight: bold">'.$row['Number'].'</td>
</tr>';
}
echo '</table>';
} else {
echo 'Er ging iets mis tijdens het ophalen van gegevens.';
}
include('layout.php');
?>
include('includes/LoadDB.php');
$sql = mysql_query("SELECT * FROM users_details");
if ($sql) {
echo '<table width="100%" style="background-color: #CCCCCC; border: 0">
<tr>
<td style="width: 6%; background-color: #E6E6E6; font-weight: bold">Voornaam</td>
<td style="width: 53%; background-color: #E6E6E6; font-weight: bold">Achternaam</td>
<td style="width: 16%; background-color: #E6E6E6; font-weight: bold">Straat</td>
<td style="width: 13%; background-color: #E6E6E6; font-weight: bold">Stad</td>
<td style="width: 13%; background-color: #E6E6E6; font-weight: bold">Postcode</td>
</tr>';
while ($result = mysql_fetch_assoc($sql)) {
echo '<tr>
<td style="width: 6%; background-color: #FFFFFF; font-weight: bold">'.$row['FirstName'].'</td>
<td style="width: 53%; background-color: #FFFFFF; font-weight: bold">'.$row['LastName'].'</td>
<td style="width: 16%; background-color: #FFFFFF; font-weight: bold">'.$row['Street'].'</td>
<td style="width: 13%; background-color: #FFFFFF; font-weight: bold">'.$row['City'].'</td>
<td style="width: 13%; background-color: #FFFFFF; font-weight: bold">'.$row['Number'].'</td>
</tr>';
}
echo '</table>';
} else {
echo 'Er ging iets mis tijdens het ophalen van gegevens.';
}
include('layout.php');
?>
Roel van de Water op 06/08/2010 18:17:20:
Persoonlijk zou ik het zo doen: (zonder die OB-rotzooi)
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
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
<?php
include('includes/LoadDB.php');
$sql = mysql_query("SELECT * FROM users_details");
if ($sql) {
echo '<table width="100%" style="background-color: #CCCCCC; border: 0">
<tr>
<td style="width: 6%; background-color: #E6E6E6; font-weight: bold">Voornaam</td>
<td style="width: 53%; background-color: #E6E6E6; font-weight: bold">Achternaam</td>
<td style="width: 16%; background-color: #E6E6E6; font-weight: bold">Straat</td>
<td style="width: 13%; background-color: #E6E6E6; font-weight: bold">Stad</td>
<td style="width: 13%; background-color: #E6E6E6; font-weight: bold">Postcode</td>
</tr>';
while ($result = mysql_fetch_assoc($sql)) {
echo '<tr>
<td style="width: 6%; background-color: #FFFFFF; font-weight: bold">'.$row['FirstName'].'</td>
<td style="width: 53%; background-color: #FFFFFF; font-weight: bold">'.$row['LastName'].'</td>
<td style="width: 16%; background-color: #FFFFFF; font-weight: bold">'.$row['Street'].'</td>
<td style="width: 13%; background-color: #FFFFFF; font-weight: bold">'.$row['City'].'</td>
<td style="width: 13%; background-color: #FFFFFF; font-weight: bold">'.$row['Number'].'</td>
</tr>';
}
echo '</table>';
} else {
echo 'Er ging iets mis tijdens het ophalen van gegevens.';
}
include('layout.php');
?>
include('includes/LoadDB.php');
$sql = mysql_query("SELECT * FROM users_details");
if ($sql) {
echo '<table width="100%" style="background-color: #CCCCCC; border: 0">
<tr>
<td style="width: 6%; background-color: #E6E6E6; font-weight: bold">Voornaam</td>
<td style="width: 53%; background-color: #E6E6E6; font-weight: bold">Achternaam</td>
<td style="width: 16%; background-color: #E6E6E6; font-weight: bold">Straat</td>
<td style="width: 13%; background-color: #E6E6E6; font-weight: bold">Stad</td>
<td style="width: 13%; background-color: #E6E6E6; font-weight: bold">Postcode</td>
</tr>';
while ($result = mysql_fetch_assoc($sql)) {
echo '<tr>
<td style="width: 6%; background-color: #FFFFFF; font-weight: bold">'.$row['FirstName'].'</td>
<td style="width: 53%; background-color: #FFFFFF; font-weight: bold">'.$row['LastName'].'</td>
<td style="width: 16%; background-color: #FFFFFF; font-weight: bold">'.$row['Street'].'</td>
<td style="width: 13%; background-color: #FFFFFF; font-weight: bold">'.$row['City'].'</td>
<td style="width: 13%; background-color: #FFFFFF; font-weight: bold">'.$row['Number'].'</td>
</tr>';
}
echo '</table>';
} else {
echo 'Er ging iets mis tijdens het ophalen van gegevens.';
}
include('layout.php');
?>
die "OB Rotsooi" is voor mijn masterpage --"
Jij je zin, dan verberg je fouten lekker ipv ze op te lossen :)
Roel van de Water op 06/08/2010 18:32:48:
Jij je zin, dan verberg je fouten lekker ipv ze op te lossen :)
Ojah je code werkt niet als ik ze uitvoer die php code, krijg ik niets in me tabels --"
Selecteer wat je wilt hebben. Gebruik eventueel alleen tijdens de development debug dingen als mysql_error. Als je ob op deze manier nodig hebt, dan ben je niet handig bezig. Zet error reporting en display errors aan. Bouw checks in om te kijken hoe ver je script komt. Is je database wel gevuld?
Karl Karl op 06/08/2010 19:54:29:
Selecteer wat je wilt hebben. Gebruik eventueel alleen tijdens de development debug dingen als mysql_error. Als je ob op deze manier nodig hebt, dan ben je niet handig bezig. Zet error reporting en display errors aan. Bouw checks in om te kijken hoe ver je script komt. Is je database wel gevuld?
normaal gezien moet deze in de database zijn ge activeert.
Maar, zijn er nog andere manieren voor een PHP Masterpage?
Als je eerst gewoon je data ophaalt en er mee doet wat je wilt (logica) en dan pas de pagina maakt (presentatie) is er niks aan de hand en heb je geen ob_* nodig. Zie bijvoorbeeld ook mvc of three tier.
Maar, nu geeft hij de text niet ):
Kan iemand me helpe
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
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
<?php
include('includes/LoadDB.php');
$sql = "SELECT * FROM users_details ORDER BY Person_ID DESC";
$query = mysql_query($sql) or die(mysql_error());
?>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="6%" align="center" bgcolor="#E6E6E6"><strong>Firstname</strong></td>
<td width="53%" align="center" bgcolor="#E6E6E6"><strong>LastName</strong></td>
<td width="15%" align="center" bgcolor="#E6E6E6"><strong>Street</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>City</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Postcode</strong></td>
</tr>
<?php while($rows = mysql_fetch_array($query)){ ?>
<tr>
<td bgcolor="#FFFFFF"><? echo $rows['FirstName']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['LastName']; ?></a><BR></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['Street']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['City']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['Number']; ?></td>
</tr>
<?php } mysql_close(); ?>
<tr>
<td colspan="5" align="right" bgcolor="#E6E6E6"><a href="Add_adress.php"><strong>Create New Adress</strong> </a></td>
</tr>
</table>
include('includes/LoadDB.php');
$sql = "SELECT * FROM users_details ORDER BY Person_ID DESC";
$query = mysql_query($sql) or die(mysql_error());
?>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="6%" align="center" bgcolor="#E6E6E6"><strong>Firstname</strong></td>
<td width="53%" align="center" bgcolor="#E6E6E6"><strong>LastName</strong></td>
<td width="15%" align="center" bgcolor="#E6E6E6"><strong>Street</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>City</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Postcode</strong></td>
</tr>
<?php while($rows = mysql_fetch_array($query)){ ?>
<tr>
<td bgcolor="#FFFFFF"><? echo $rows['FirstName']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['LastName']; ?></a><BR></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['Street']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['City']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['Number']; ?></td>
</tr>
<?php } mysql_close(); ?>
<tr>
<td colspan="5" align="right" bgcolor="#E6E6E6"><a href="Add_adress.php"><strong>Create New Adress</strong> </a></td>
</tr>
</table>
s h o r t t a g s zijn uit den boze!
Selecteer wat je wilt hebben. Die is slecht.