php output to table ???
Posted: Mon Sep 02, 2002 9:12 am
I am having difficulty trying to get a search result to display to a table. At the moment it lists the output all vertically ie.,
1. title1
1. genre1
1. format1
2. title2
2. genre2
2. format2
I really want it to display like:
title1 | genre1 | format1
title2 | genre2 | format2
Here's the script (edited for security reasons):
<html>
<head>
<title>Movies Search Results</title>
</head>
<body>
<h1>Movies Search Results</h1>
<?
trim($searchterm);
if (!$searchtype || !$searchterm)
{
echo "You have not entered search details. Please go back and try again.";
exit;
}
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
@ $db = mysql_pconnect("*****","*****","*****");
if (!$db)
{
echo "Error: Could not connect to database. Please try again later.";
exit;
}
mysql_select_db("*****");
$query = "select * from movies where ".$searchtype." like
'%".$searchterm."%'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo "<p>Number of entries found: ".$num_results."</p>";
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo "<p><strong>".($i+1).". Title: ";
echo htmlspecialchars( stripslashes($row["title"]));
echo "<p><strong>".($i+1).". Genre: ";
echo htmlspecialchars( stripslashes($row["genre"]));
echo "<p><strong>".($i+1).". Format: ";
echo htmlspecialchars( stripslashes($row["format"]));
echo "<p><strong>".($i+1).". No of CD's: ";
echo htmlspecialchars( stripslashes($row["cds"]));
echo "</p>";
}
?>
</body>
</html>
Any help would be appreciated !!! I am still trying to work it out myself, but if anybody can spot the problem please let me know.
Cheers,
Pha3dr0n
1. title1
1. genre1
1. format1
2. title2
2. genre2
2. format2
I really want it to display like:
title1 | genre1 | format1
title2 | genre2 | format2
Here's the script (edited for security reasons):
<html>
<head>
<title>Movies Search Results</title>
</head>
<body>
<h1>Movies Search Results</h1>
<?
trim($searchterm);
if (!$searchtype || !$searchterm)
{
echo "You have not entered search details. Please go back and try again.";
exit;
}
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
@ $db = mysql_pconnect("*****","*****","*****");
if (!$db)
{
echo "Error: Could not connect to database. Please try again later.";
exit;
}
mysql_select_db("*****");
$query = "select * from movies where ".$searchtype." like
'%".$searchterm."%'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo "<p>Number of entries found: ".$num_results."</p>";
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo "<p><strong>".($i+1).". Title: ";
echo htmlspecialchars( stripslashes($row["title"]));
echo "<p><strong>".($i+1).". Genre: ";
echo htmlspecialchars( stripslashes($row["genre"]));
echo "<p><strong>".($i+1).". Format: ";
echo htmlspecialchars( stripslashes($row["format"]));
echo "<p><strong>".($i+1).". No of CD's: ";
echo htmlspecialchars( stripslashes($row["cds"]));
echo "</p>";
}
?>
</body>
</html>
Any help would be appreciated !!! I am still trying to work it out myself, but if anybody can spot the problem please let me know.
Cheers,
Pha3dr0n