Hi,
this is my first post, I really wish I didn't have too but frustration is overrated.
Problem: I have a database set up with keywords in it, I would like to be able to extract and display results by $variable.
For instance...a visitor wants to see all of the keywords that have the word "search" in it. If they had access to my database they would type in
select * from popularkeywords where keywords="search";
but how can I do this using PHP/html, where data is displayed in tables? Here is my idea of how it would work, yet, it doesn't. I have two pages, one is keywordsearch.shtml and search.php here's what's inside both.
keywordsearch.shtml:
<head>
<title>keyword</title>
</head>
<body>
<table width="200" border="1" bordercolor="#6666cc">
<tr>
<td>
<form action="search.php" method="post">
keyword search tool: <input type="text" name="keywords"><br>
<input type="Submit">
</form>
</tr>
</td>
</table>
</body>
search.php:
<?
$username="username";
$password="password";
$database="database";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM popularkeywords where keywords="$keywords";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
echo "<b><center>Database Output</center></b><br><br>";
$i=0;
while ($i < $num) {
$keywords=mysql_result($result,$i,"keywords");
echo "<b>Keywords: $keywords</b>";
++$i;
}
?>
I realize this doesn't work, I just can't figure out where. If anyone can help that would be great, meanwhile I'll continue to RTFM.
Thanks,