Created
November 16, 2012 00:51
-
-
Save someara/4082888 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Welcome to MyFace! | |
<html><head><title>MyFace Users</title></head><body> | |
<?php | |
$db_host = 'localhost'; | |
$db_user = 'root'; | |
$db_pwd = '<%= node['mysql']['server_root_password'] %>'; | |
$database = 'myface'; | |
$table = 'users'; | |
if (!mysql_connect($db_host, $db_user, $db_pwd)) | |
die("Can't connect to database"); | |
if (!mysql_select_db($database)) | |
die("Can't select database"); | |
// sending query | |
$result = mysql_query("SELECT * FROM {$table}"); | |
if (!$result) { | |
die("Query to show fields from table failed"); | |
} | |
$fields_num = mysql_num_fields($result); | |
echo "<table border='1'><tr>"; | |
// printing table headers | |
for($i=0; $i<$fields_num; $i++) | |
{ | |
$field = mysql_fetch_field($result); | |
echo "<td>{$field->name}</td>"; | |
} | |
echo "</tr>\n"; | |
// printing table rows | |
while($row = mysql_fetch_row($result)) | |
{ | |
echo "<tr>"; | |
// $row is array... foreach( .. ) puts every element | |
// of $row to $cell variable | |
foreach($row as $cell) | |
echo "<td>$cell</td>"; | |
echo "</tr>\n"; | |
} | |
mysql_free_result($result); | |
?> | |
</body></html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment