Jump to content

I created display.php to show records from a mysql database on my site but?


xx_britt

Recommended Posts

I don't know what to do now?

 

I was told that if I wanted to display records from a mysql database on my site I would have to create a file named display.php and code it which I did... but now have no idea how to get it to display on my site?

 

What do I put in default.html?

Link to comment
Share on other sites

I of course change the variables to match my database name and user and password but this is the code:

 

<?

$username="username";

$password="password";

$database="database";

 

mysql_connect(localhost,$db_user,$password);

@mysql_select_db($db_name) or die( "Unable to select database");

$query="SELECT * FROM contacts";

$result=mysql_query($query);

 

$num=mysql_numrows($result);

 

mysql_close();

 

echo "<b><center>Database Output</center></b><br><br>";

 

$i=0;

while ($i < $num) {

 

$Name=mysql_result($result,$i,"name");

$Email=mysql_result($result,$i,"email");

$Comments=mysql_result($result,$i,"comments");

 

echo "<b>$name $email</b><br>Comments: $comments<br><hr><br>";

 

$i++;

}

 

?>

Link to comment
Share on other sites

I of course change the variables to match my database name and user and password but this is the code:

 

<?

$username="username";

$password="password";

$database="database";

 

mysql_connect(localhost,$db_user,$password);

@mysql_select_db($db_name) or die( "Unable to select database");

$query="SELECT * FROM contacts";

$result=mysql_query($query);

 

$num=mysql_numrows($result);

 

mysql_close();

 

echo "<b><center>Database Output</center></b><br><br>";

 

$i=0;

while ($i < $num) {

 

$Name=mysql_result($result,$i,"name");

$Email=mysql_result($result,$i,"email");

$Comments=mysql_result($result,$i,"comments");

 

echo "<b>$name $email</b><br>Comments: $comments<br><hr><br>";

 

$i++;

}

 

?>

 

try this:

 

while ($row = mysql_fetch_assoc($result)) {

$name=$row['name'];
$email = $row['email'];
$comments= $row['comments'];

echo "<b>$name $email</b><br>Comments: $comments<br><hr><br>";

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.