jaybeeb Posted April 7, 2008 Share Posted April 7, 2008 I have a MYSQL table setup to display using PHP, I want to put this table data into a table I have already created in html, how do I go about getting the html table to retrieve the values from my PHP page? Thanks. Quote Link to comment Share on other sites More sharing options...
blackcell Posted April 7, 2008 Share Posted April 7, 2008 That is a big question. Are you anywhere on it or do you need help all the way from building the sql statement and executing? Quote Link to comment Share on other sites More sharing options...
jaybeeb Posted April 7, 2008 Author Share Posted April 7, 2008 My SQL/PHP code is created, it displays to a table, but I want to display the actual values into a new table in a HTML file Here is my SQL code <?php require_once 'library/db.php'; if (!($conn = mysql_connect('localhost', 'root', ''))) { showError(); } if (!(mysql_select_db('itsupport', $conn))) { showError(); } if (!($result = mysql_query('select * from itsupport', $conn))) { showError(); } while ($row =mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row[user_Name] . "</td><td>" . $row[user_ID] . "</td><td>" . $row[staff_ID] . "</td><td>" . $row[Problem] . "</td><td>" . $row[Problem_ID] . "</td><td>" . $row[user_email] . "</td><td>" . $row[staff_email] . "</td><td>" ; echo "<td><a href=\"update.php?id=$row[CId]\"><img border=\"0\" src=\"images/edit.gif\"></a>"; echo "</tr>"; } include 'library/closedb.php'; > Quote Link to comment Share on other sites More sharing options...
blackcell Posted April 8, 2008 Share Posted April 8, 2008 Try using variables for your table data first. It helps to organize. <?php $userName = $row[user_Name]; //ETC etc... ?> If your going to echo each table row, I would suggest making it look something like this: <?php echo "<tr>"; echo "<td>" . $userName . "</td>"; echo "<td>" . $userID . "</td>"; echo "<td>" . $StaffID. "</td>"; . . yada yada . . echo "</tr>"; ?> Are you receiving any errors or is the data not displaying? I don't know what your showError(); function does but I would suggest: mysql_select_db('itsupport', $conn) or die("Could not select database:<br>" . mysql_error()); Until you get the feel for things unless your showError() function is more detailed. Use the or die("blah blah" . mysql_error()) after everything. Quote Link to comment Share on other sites More sharing options...
jaybeeb Posted April 8, 2008 Author Share Posted April 8, 2008 Hi, Thanks for the tips, changed it around a bit. Not getting any errors the data displays correctly in my PHP table I juts want to be able to call this table in a HTML file, is this possible? Here is the code after I changed it arround, thanks <table border="1"> <?php require_once 'library/db.php'; if (!($conn = mysql_connect('localhost', 'root', ''))) { showError(); } if (!(mysql_select_db('itsupport', $conn))) { showError(); } $User_Name = $row['User_Name']; $User_ID = $row['User_ID']; $Staff_ID =$row['Staff_ID']; $Problem = $row['Problem']; $Problem_ID = $row['Problem_ID']; $User_email = $row['User_email']; $Staff_email = $row['Staff_email']; if (!($result = mysql_query('select * from itsupport', $conn))) { showError(); } while ($row =mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row[user_Name] . "</td>"; echo "<td>" . $row[user_ID] . "</td>"; echo "<td>" . $row[staff_ID] . "</td>"; echo "<td>" . $row[Problem] . "</td>"; echo "<td>" . $row[Problem_ID] . "</td>"; echo "<td>" . $row[user_email] . "</td>"; echo "<td>" . $row[staff_email] . "</td>"; echo "</tr>"; } include 'library/closedb.php'; ?> </table> Quote Link to comment Share on other sites More sharing options...
blackcell Posted April 8, 2008 Share Posted April 8, 2008 Oh, you want to rename your file from page.php to page.html ? I'm not for sure but I think in your apache configuration file you can tell the web server how to handle extensions. I will do some checking around also. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 8, 2008 Share Posted April 8, 2008 Indeed - if blackcell is correct in what you wanted to do and and if you're using apache, find this line in your http.conf: AddType application/x-httpd-php .php And add this line below: AddType application/x-httpd-php .html Quote Link to comment Share on other sites More sharing options...
discomatt Posted April 8, 2008 Share Posted April 8, 2008 Can also be done with an .htaccess file RemoveHandler .html .htm AddType application/x-httpd-php .php .htm .html Quote Link to comment Share on other sites More sharing options...
blackcell Posted April 8, 2008 Share Posted April 8, 2008 Out of curiosity, why do you want to do this? 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.