While

Gestart doorWouterp42 reacties105 weergaven

43 berichten · pagina 1 van 3

Wouterp

Lid · Topicstarter

Berichten
1.631
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hallo,

Mijn vorige topic was compleet van het echte onderwerp af dus even een nieuwe.

Ik heb problemen met de while functie wie zou hem mij kunnen uitleggen? Kom niet aan met google etc. want ik krijg het niet onder de knie.

Ik wil dat hij alle berichten echoëd

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/require"]require[/URL] [COLOR= #DD0000]connect.php[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$sql[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT *
FROM  `berichtenbalk` ORDER BY id DESC"[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$row[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_array"]mysql_fetch_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700]);[/COLOR]

  
?>
<table border="1" width=500>
<tr>
  <td><marquee direction="left"  hspace=40><b>Berichten: </b>[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]berichten[/COLOR][COLOR= #007700]][/COLOR] ?></marquee></td>
</tr>
</table>

<form name="input" action="berichtenbalk_post.php">
<input type=text name="bericht" />
<input type="submit" value="Plaats een bericht" />
</form>
</html>
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Goededag schreef:
Hallo,
Mijn vorige topic was compleet van het echte onderwerp af dus even een nieuwe.

Ik heb problemen met de while functie wie zou hem mij kunnen uitleggen? Kom niet aan met google etc. want ik krijg het niet onder de knie.

Ik wil dat hij alle berichten echoëd

[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/require"]require[/URL] [COLOR= #DD0000]connect.php[/COLOR][COLOR= #007700];[/COLOR] ?>
<table border="1" width=500>
<tr>
  <td><marquee direction="left"  hspace=40><b>Berichten: </b>[COLOR= #0000BB]<?php
$sql[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT *
FROM  `berichtenbalk` ORDER BY id DESC"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$row[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_array"]mysql_fetch_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700])) {[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]berichten[/COLOR][COLOR= #007700]];
}[/COLOR]
?></marquee></td>
</tr>
</table>

<form name="input" action="berichtenbalk_post.php">
<input type=text name="bericht" />
<input type="submit" value="Plaats een bericht" />
</form>
</html>
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Je vergeet de foutafhandeling.

[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]// mysql_query geeft altijd een result.[/COLOR]
[COLOR= #0000BB]$result[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM  berichtenbalk ORDER BY id DESC"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$result[/COLOR][COLOR= #007700]) {[/COLOR]
  [URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$row[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700])) {[/COLOR] [COLOR= #FF8000]// assoc is sneller.[/COLOR]
      [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]berichten[/COLOR][COLOR= #007700]];
   }
}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Er is een fout opgetreden: "[/COLOR][COLOR= #007700].[/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]();
}[/COLOR]
?>
0
Wouterp

Lid · Topicstarter

Berichten
1.631
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Nu moet er nog even voor elk resultaat : $row[[poster] : bericht | Poster : bericht

Dus:

Piet | Heeey Klaas : Doei |
0
Berichten
4.912
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
en de beveiliging want je wilt geen xss injecties.
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
True..

echo htmlentities($row[berichten]);
0
Wouterp

Lid · Topicstarter

Berichten
1.631
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Goededag schreef:
Nu moet er nog even voor elk resultaat : $row[[poster] : bericht | Poster : bericht
Dus:

Piet | Heeey Klaas : Doei |
0
Berichten
6.144
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]// mysql_query geeft altijd een result.[/COLOR]
[COLOR= #0000BB]$result[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM  berichtenbalk ORDER BY id DESC"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$result[/COLOR][COLOR= #007700]) {[/COLOR]
  [URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$row[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700])) {[/COLOR] [COLOR= #FF8000]// assoc is sneller.[/COLOR]
      [URL="http://www.php.net/echo"]echo[/URL] htmlentities[COLOR= #007700]([/COLOR][URL="http://www.php.net/ucfirst"]ucfirst[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]poster[/COLOR][COLOR= #007700]])).[/COLOR][COLOR= #DD0000]: [/COLOR][COLOR= #007700].[/COLOR]htmlentities[COLOR= #007700]([/COLOR][COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]berichten[/COLOR][COLOR= #007700]]).[/COLOR][COLOR= #DD0000] | [/COLOR][COLOR= #007700];
   }
}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Er is een fout opgetreden: "[/COLOR][COLOR= #007700].[/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]();
}[/COLOR]
?>
0
Wouterp

Lid · Topicstarter

Berichten
1.631
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Geen resultaat maar de database bestaat wel kijk:
Afbeelding
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hoe ziet je leden tabel er dan uit? En de link van een profiel, dan ik ook wat maken dat ze op naam kunnen klikken wink
0
Wouterp

Lid · Topicstarter

Berichten
1.631
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Dit is een compleet eigen script niks met een ledensysteem of dergelijk.
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Bij poster staat een getal. Ik neem aan dat het id van het lid van de poster is. Ik moet dus de tabel zien waar de leden in staan.
0
Wouterp

Lid · Topicstarter

Berichten
1.631
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Die resultaten heb ik net snel iets even in getypt zoals:

KDJKSDJKSDjeidjskdasjiewjdsad

Het betekent helemaal niks dus er is geen tabel leden zoals ik al zei.
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Jponsen schreef:
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]// mysql_query geeft altijd een result.[/COLOR]
[COLOR= #0000BB]$result[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM  berichtenbalk ORDER BY id DESC"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$result[/COLOR][COLOR= #007700]) {[/COLOR]
  [URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$row[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700])) {[/COLOR] [COLOR= #FF8000]// assoc is sneller.[/COLOR]
      [URL="http://www.php.net/echo"]echo[/URL] htmlentities[COLOR= #007700]([/COLOR][URL="http://www.php.net/ucfirst"]ucfirst[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]poster[/COLOR][COLOR= #007700]])).[/COLOR][COLOR= #DD0000]: [/COLOR][COLOR= #007700].[/COLOR]htmlentities[COLOR= #007700]([/COLOR][COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]berichten[/COLOR][COLOR= #007700]]).[/COLOR][COLOR= #DD0000] | [/COLOR][COLOR= #007700];
   }
}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Er is een fout opgetreden: "[/COLOR][COLOR= #007700].[/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]();
}[/COLOR]
?>
Dat zou dan toch moeten werken?
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren