php - Need a small help in Viewing database content in a webpage -
i'm trying view contents of database webpage. i'm using code:
<?php error_reporting(0); $host="localhost"; $username="root"; $password=""; $database="pncollege"; mysql_connect($host,$username,$password); @mysql_select_db($database) or die( "unable select database"); $query="select * data"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo ""; $i=0; while ($i < $num) { $email=mysql_result($result,$i,"email"); $name=mysql_result($result,$i,"name"); echo ""; $i++; } ?> <!doctype html> <html> <head> <title>free guidance website template | programs :: w3layouts</title> <link href="css/style.css" rel="stylesheet" type="text/css" media="all" /> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link href='http://fonts.googleapis.com/css?family=montserrat+alternates' rel='stylesheet' type='text/css'> <!------ light box ------> <script src="js/jquery.min.js"></script> <link rel="stylesheet" href="css/swipebox.css"> <script src="js/ios-orientationchange-fix.js"></script> <script src="js/jquery.swipebox.min.js"></script> <script type="text/javascript"> jquery(function($) { $(".swipebox").swipebox(); }); </script> <style> /* max width before particular table gets nasty query take effect screen smaller 760px , ipads specifically. */ @media screen , (max-width: 760px), (min-device-width: 768px) , (max-device-width: 1024px) { /* force table not tables anymore */ table, thead, tbody, th, td, tr { display: block; } /* hide table headers (but not display: none;, accessibility) */ thead tr { position: absolute; top: -9999px; left: -9999px; } tr { border: 1px solid #ccc; } td { /* behave "row" */ border: none; border-bottom: 1px solid #eee; position: relative; padding-left: 50%; } td:before { /* table header */ position: absolute; /* top/left values mimic padding */ top: 6px; left: 6px; width: 45%; padding-right: 10px; white-space: nowrap; } /* label data */ td:nth-of-type(1):before { content: "first name"; } td:nth-of-type(2):before { content: "last name"; } td:nth-of-type(3):before { content: "job title"; } td:nth-of-type(4):before { content: "favorite color"; } td:nth-of-type(5):before { content: "wars of trek?"; } td:nth-of-type(6):before { content: "porn name"; } td:nth-of-type(7):before { content: "date of birth"; } td:nth-of-type(8):before { content: "dream vacation city"; } td:nth-of-type(9):before { content: "gpa"; } td:nth-of-type(10):before { content: "arbitrary data"; } } /* smartphones (portrait , landscape) ----------- */ @media screen , (min-device-width : 320px) , (max-device-width : 480px) { body { padding: 0; margin: 0; width: 320px; } } /* ipads (portrait , landscape) ----------- */ @media screen , (min-device-width: 768px) , (max-device-width: 1024px) { body { width: 495px; } } * { margin: 0; padding: 0; } body { font: 14px/1.4 georgia, serif; } #page-wrap { margin: 50px; } p { margin: 20px 0; } /* generic styling, desktops/laptops */ table { width: 100%; border-collapse: collapse; } /* zebra striping */ tr:nth-of-type(odd) { background: #eee; } th { background: #333; color: white; font-weight: bold; } td, th { padding: 6px; border: 1px solid #ccc; text-align: left; } </style> <!------ eng light box ------> </head> <body> <div class="header-bg"> <div class="wrap"> <div class="total-box"> <div class="total"> <div class="header_top"> <div class="menu"> <ul> <li><a href="index.html">home</a></li> <li><a href="about.html">about</a></li> <li><a href="faculty.html">faculties</a></li> <li><a href="picture.html">picture gallery</a></li> <li class="active"><a href="principal.html">principal's desk</a></li> <li><a href="contact.html">contact</a></li> <div class="clear"></div> </ul> </div> <ul class="follow_icon"> <li><a href="#" style="opacity: 1;"><img src="images/fb.png" alt=""></a></li> <li><a href="#" style="opacity: 1;"><img src="images/tw.png" alt=""></a></li> <li><a href="#" style="opacity: 1;"><img src="images/rss.png" alt=""></a></li> </ul> <div class="clear"></div> </div> <div class="header-bottom"> <div class="logo"> <img src="images/logo.png"> </div> <div class="logo"> <h1><a href="index.html">p.n. college, parsa</a></h1> <h2><a href="index.html"> ( constituent unit of jaiprakash university )</a></h2> </div> <div class="search"> <form> <input type="text" value=""> <input type="submit" value=""> </form> </div> <div class="clear"></div> </div> </div> </div> </div> </div> <div class="banner-box"> <div class="wrap"> <div class="main-top"> <div class="main"> <div class="heading3"> <h3 style="text-align:center">admin panel</h3> <hr><br> </div> <div class="section group"> <center> <table> <thead> <tr> <th>name</th> <th>email</th> <th>message</th> </tr> </thead> <tbody> <tr> <td><?php echo "$username"; ?></td> <td><?php echo "$useremail"; ?></td> <td><?php echo "$usermsg"; ?></td> </tr> </tbody> </table> </center> <div class="clear"></div> </div> </div> </div> </div> </div> <div class="copy-right"> <p style="letter-spacing:4px;border-radius:15px 0 15px 0;background-color:#000;padding-top:15px;padding-bottom:15px;width:100%">© <a href="index.html">p.n. college </a>| designed <a href="http://facebook.com/incredible100rav"> incredible saurav</a></p> </div> </body> </html> can me , guide me i've made mistake? know code little messy , i'm sorry that. can't figure out i've made mistake.
change loop fetch array each row -
while ($row = mysql_fetch_array($result)) { $email = $row['email']; // assign array part variable $name = $row['name']; echo $name ." " .$email . "<br />"; // echo variables } // can close connection, after have used results mysql_close(); please, stop using mysql_* functions. no longer maintained , officially deprecated. learn prepared statements instead, , consider using pdo, it's not hard think.
Comments
Post a Comment