Mini Forum en PHP. Les messages ne s'afichent pas.

gnome
Invité n'ayant pas de compte PHPfrance

13 août 2011, 06:08

Bonjour à tous, j'ai fais un petit script de forum tout simple mais j'ai un problème. Les messages ne s'affichent pas. (Le ID,TOPIC,VIEW,REPLY et DATE)
Je n'ai aucun message d'erreur. j'ai juste 2 barre blanche vide.

Image

Image
<?php
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="forum"; // Database name 
$tbl_name="forum_question"; // Table name 

 mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
 mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name ORDER BY id DESC";
// OREDER BY id DESC is order result by descending 
 $result=mysql_query($sql);
 ?>
 <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
 <tr>
 <td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td>
 <td width="53%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td>
 <td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td>
 <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td>
 <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td>
 </tr>

<?php
 while($rows=mysql_fetch_assoc($result,MYSQL_ASSOC)){ // Start looping table row 
 ?>
<tr>
 <td bgcolor="#FFFFFF"><? echo mysql_real_escape_string($rows['id']); ?></td>
<td bgcolor="#FFFFFF"><a href="view_topic.php?id=<? echo mysql_real_escape_string($rows['id']); ?>"><? echo mysql_real_escape_string($rows['topic']); ?></a><BR></td>
 <td align="center" bgcolor="#FFFFFF"><? echo mysql_real_escape_string($rows['view']); ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo mysql_real_escape_string($rows['reply']); ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo mysql_real_escape_string($rows['datetime']); ?></td>
 </tr>

<?php
// Exit looping and close connection 
 }
 ?>
Un problème avec le $rows=mysql_fetch_assoc($result,MYSQL_ASSOC) ?
J'ai déjà essayé :
$rows=mysql_fetch_assoc($result)
$rows=mysql_fetch_assoc($result,MYSQL_BOTH)


:(

gnome
Invité n'ayant pas de compte PHPfrance

13 août 2011, 23:05

J'ai trouvé l'erreur enfaite. Il fallait que je mette le tout dans 1 <?php ?> et que je fasse un echo' ';