mark103 Posted April 9, 2013 Share Posted April 9, 2013 Hi guys,I have stored the data in mysql database where I can ouput them in php using with this following code: <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbusername'); define('DB_PASSWORD', 'mydbpassword'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $qrytable1="SELECT id, channels FROM tvguide"; $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); while ($row = mysql_fetch_array($result1)) { echo "</br>"; echo "<td>".$row['channels']."</td>"; echo "</br>"; } } ?> I want to know how I can output the data from php to html, do you know how?if so please can you help me.thanks in advance. Link to comment https://forums.phpfreaks.com/topic/276725-need-help-with-output-the-data/ Share on other sites More sharing options...
devWhiz Posted April 10, 2013 Share Posted April 10, 2013 I'm not sure I get what you mean? Is your script not displaying anything? Any errors being displayed? The only thing I see that would cause an error is your $qry variable being undefined. Link to comment https://forums.phpfreaks.com/topic/276725-need-help-with-output-the-data/#findComment-1423851 Share on other sites More sharing options...
computermax2328 Posted April 10, 2013 Share Posted April 10, 2013 I agree with CLUELESS plus if you are going to be using HTML elements in your PHP use the right ones. For your table you have the start a <table> outside of your while loop. Then if you want to have one piece of data per row you need to add <tr> tags in your loop. Replace the <br> tags with them. echo "<table>"; //query while ($SomethingWorks) { echo "<tr>"; echo "$row['whatever']"; echo "<tr>"; } echo "</table>"; Link to comment https://forums.phpfreaks.com/topic/276725-need-help-with-output-the-data/#findComment-1423920 Share on other sites More sharing options...
Barand Posted April 10, 2013 Share Posted April 10, 2013 Don't forget the '<td>...</td>' tags Link to comment https://forums.phpfreaks.com/topic/276725-need-help-with-output-the-data/#findComment-1423955 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.