xx_britt Posted July 23, 2009 Share Posted July 23, 2009 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? Quote Link to comment Share on other sites More sharing options...
trq Posted July 23, 2009 Share Posted July 23, 2009 Your question is pretty vague. Can we see display.php ? Quote Link to comment Share on other sites More sharing options...
xx_britt Posted July 23, 2009 Author Share Posted July 23, 2009 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++; } ?> Quote Link to comment Share on other sites More sharing options...
Prismatic Posted July 23, 2009 Share Posted July 23, 2009 Just upload display.php into the same folder as default.html on your website and visit it. Quote Link to comment Share on other sites More sharing options...
xx_britt Posted July 23, 2009 Author Share Posted July 23, 2009 prismatic, what do you mean? link it? i want it to show on the page. not be a link to another page. Quote Link to comment Share on other sites More sharing options...
trq Posted July 23, 2009 Share Posted July 23, 2009 Then put that code in the page you need it in. Quote Link to comment Share on other sites More sharing options...
acadia Posted July 23, 2009 Share Posted July 23, 2009 Upload display.php to the same folder as default.html and add this line into your default.html: <?php include('display.php');?> acadia Quote Link to comment Share on other sites More sharing options...
xx_britt Posted July 24, 2009 Author Share Posted July 24, 2009 acadia, your code did nothing. i put it under a blog post before the html form... any other suggestions? Quote Link to comment Share on other sites More sharing options...
abazoskib Posted July 24, 2009 Share Posted July 24, 2009 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>"; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.