# Param 1 : MySQL Host Name
# Param 2 : MySQL Username
# Param 3 : MySQL Password
# Param 4 : MySQL Database
# Param 5 : SQL Statement (SELECT)
show_table("localhost","...","...","...","SELECT * FROM articles");
function show_table($hostName,$userName,$passWord,$dataBase,$sqlQuery)
{
# Connect to MySQL
$conn=mysql_connect("...", "...", "...");
# 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 "<table border=1><tr>";
# Make the row for table column names
while (list($key, $value) = each($row))
{
$i++;
if(!($i%2))
echo "<td><b><a href='?order=$key'>$key</a></td>";
}
echo "</tr>";
$result=mysql_query($sqlQuery);
// Make rows for records
while($rec=mysql_fetch_array($result))
{
echo "<tr>";
for($i=0;$i<count($rec);$i++)
{
if($rec[$i])
echo '<td><A HREF="'.link("article.php", "ID=".$_GET['id']).'"><B>'.$rec[$i].'</B></A></td>';
Your program is trying to do a hard link in your system. Try to change that and will work or gove the right permisions on the system. If you are under *nix try to chmod with the owner of your webserver (under debian linux the owner is www-data on other system is apache or www)
Best Regards
A.
P.S. I dont know what is doing your code but try in this way if you are not want to using the "link" (I don't know why you are using link there ? do you declared a function named link ? php have it's own function link and you cannot declare a function with the same name):
and result is as following:
SELECT * FROM articles where ID = '1'
Warning: mysql_error(): supplied resource is not a valid MySQL-Link resource in .../read_news.php on line 57
SELECT * FROM articles where ID = '2006-03-16'
Line 57 is: echo(mysql_error($s));
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result .../read_news.php on line 48
There is no error shown. Problem is: 1.it gives me just first row 2.only first column has correct link like: http://mywebsite/article.php?id=1
It should have all columns above link
I have put echo count($rec)."<br>"; and number is 14
1. you looked at your generated html source ?
2. Is possible to have incorect links in database ?
3. Is possible to see this link somwhere in internet ? (send on private)
4. Is possible to have incorect html tags ?
Bookmarks