That php code is long, There are other way's to do the same thing. o_o Without showing everything.
These is a php that is smaller then your and more well displayed, I'm not saying you did a bad job, You did great work.. =) But if you want to display something try something like this
<?php $db = mysql_connect("localhost","username","password"); mysql_select_db("newdb", $db); $query = mysql_query("SELECT * FROM links"); echo ' '; while ($r = mysql_fetch_assoc($query)) { echo '| ', implode(' | ',$r), ' | '; } echo ' '; ?>
Your should be about this long.
<?PHP
- Param 1 : MySQL Host Name
- Param 2 : MySQL Username
- Param 3 : MySQL Password
- Param 4 : MySQL Database
- Param 5 : SQL Statement (SELECT)
show_table("66.176.96.57","root","","newdb","SELECT * FROM armor");
function show_table($hostName,$userName,$passWord,$dataBase,$sqlQuery) {
- Connect to MySQL
$conn=mysql_connect($hostName,$userName,$passWord);
- Select Database
mysql_select_db($dataBase,$conn);
- Validate SQL Statement
$array=explode(" ORDER",$sqlQuery); $sqlQuery=$array[0]; if(!strstr($sqlQuery,"SELECT")) die("Invalid Query : SQL statement should be a SELECT statement.");
- ORDER records by requested column
if($_GET['order']) $sqlQuery=$sqlQuery." ORDER BY ".$_GET['order'];
- Execute SQL query
$result=mysql_query($sqlQuery) or die("Invalid Query : ".mysql_error()); $row=mysql_fetch_array($result);
- Check whether NULL records found
if(!mysql_num_rows($result)) die("No records found."); echo "";
- Make the row for table column names
while (list($key, $value) = each($row)) { $i++; if(!($i%2)) echo "<a href='?order=$key'>$key</a></td>"; } echo "</tr>"; $result=mysql_query($sqlQuery); // Make rows for records while($rec=mysql_fetch_array($result)) { echo " | "; for($i=0;$i<count($rec);$i++) { if($rec[$i]) echo "$rec[$i]</td>"; } echo "</tr>"; } echo "</table>"; } ?>
|
|