Jump to content

basic forum


wanttolearn

Recommended Posts

// please help why this code wont work correctly, everything is ok but it doesnt write te data from the data base into a table

// thaaannkxxx

 

 

 

<body>

<?php

$host="localhost"; // Host name

$username="root"; // Mysql username

$password=""; // Mysql password

$db_name="test"; // Database name

$tbl_name="forum_question"; // Table name

 

// Connect to server and select databse.

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

 

// Start looping table row

while($rows=mysql_fetch_array($result)){

?>

<tr>

<td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>

<td bgcolor="#FFFFFF"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?></a><BR></td>

<td align="center" bgcolor="#FFFFFF"><? echo $rows['view']; ?></td>

<td align="center" bgcolor="#FFFFFF"><? echo $rows['reply']; ?></td>

<td align="center" bgcolor="#FFFFFF"><? echo $rows['datetime']; ?></td>

</tr>

<?php

// Exit looping and close connection

}

mysql_close();

?>

<tr>

<td colspan="5" align="right" bgcolor="#E6E6E6"><a href="create_topic.php"><strong>Create New Topic</strong> </a></td>

</tr>

</table>

 

 

</body>

Link to comment
https://forums.phpfreaks.com/topic/273309-basic-forum/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.