Try this <?php $submit = $_POST["submit"]; $keywords = $_POST["keywords"]; if(isset($submit) || isset($keywords)) { doSearch($keywords); } else { getKeywords(); } function getKeywords() { ?> <html> <head> <title> Enter Search Keywords </title> </head> <body bgcolor="#FFFFFF"> <form name="frmKW" action="searchdocs.php" method="post"> <h1>Keyword Search</h1> Enter keywords to search on: <input type="text" name="keywords" maxlength="100"> <br><br><input type="submit" name="submit" value="Search"> </form> </body> </html> <?php } function doSearch($search_keywords) { $arrWords = explode(" ", $search_keywords); if(sizeof($arrWords) == 0 || $search_keywords == "") { echo "You didn't enter any keywords<br>"; echo "<a href='searchdocs.php'>Go Back</a>"; } else { for($i = 0; $i < sizeof($arrWords); $i++) { $query = "select articleids from searchwords where word = '{$arrWords[$i]}'"; $result = mysql_query($query); if(mysql_num_rows($result) > 0) { // Get the id's of the articles $row = mysql_fetch_array($result); $arrIds = $row[0]; $aQuery = "select articleid, title, left(description, 100) as remedy from articles where articleid in ( $arrIds ) group by articleid, title, description"; $aResult = mysql_query($aQuery); $count=mysql_num_rows($aResult) ; if($count > 0) { echo "<h1>" .$count; echo ($count == 1 ? " article" : " articles"); echo " found:</h1>"; while($aRow = mysql_fetch_array($aResult)) { echo '<a href="article.php?articleId='.$aRow["articleid"].'"><b><u>'.$aRow["title"].'</u></b></a>'; echo '<br> '.$aRow["remedy"].'....<br><a href="article.php?articleId='.$aRow["articleid"].'">'; echo 'http://www.mysite.com/article.php?articleId='.$aRow["articleid"].'</a><br><br>'; } } else { echo "No results found for '$search_keywords'<br>"; echo "<a href='searchdocs.php'>Go Back</a>"; } } mysql_close(); } } } ?> Code (markup):
OMG it's working, thanx a lot Well, i have another request for help. like from the screen shot i gave previously, it gave result of 'fever' & once the user click on it, it will direct the user to a page that contains the information of 'fever'. The information is already provided in the database. How to display those information? Do you know how to do that? Sorry for troubling you.
well, the article.php is only a dummy page, because i don't know how to link and display the information from the database after the result is displayed
i show with screen shots & some explanation ok so firstly the user type in the any keywords like for the example "cold", then these results come out http://img532.imageshack.us/i/86046657.jpg/ then for example the user click on "Fever", an information page will be showed http://img205.imageshack.us/i/14100289.jpg/ or if the user click on like say "Cough" http://img338.imageshack.us/i/72793219.jpg/ The "title", "description" & "remedy" are all from the database called "ailment" inside a table called "articles". Please let me know if you need more information.
This is how your article.php looks like <? $aQuery = "select articleid, title, description, left(description, 100) as remedy from articles where articleid =". $_GET['articleId']; $aResult = mysql_query($aQuery); while($aRow = mysql_fetch_array($aResult)) { echo '<b><u>'.$aRow["title"].'</u></b>'; echo '<br><b><u>Description :</u></b>'.$aRow["description"]; echo '<br><b><u>Remedy :</u></b>'.$aRow["remedy"]; } mysql_close(); ?> Code (markup):
I want to start HTML and PHP, can anyone guide me from where to start ? any locations for institutes or internet educations! Thanks
i still have the problem to display the information & regarding this search function i wonder if it can search using multiple keywords for a specific result? can anyone help me with this please. Thanx in advance
Try using this: <? $title=$_GET['title']; $result = mysql_query("SELECT * FROM articles WHERE title='$title'") or die(mysql_error()); while($rows=mysql_fetch_array($result)) { ?> <strong><? echo $rows['title']; ?></strong> <br /><br /> <strong>Description: <? echo $rows['description']; ?> <br /><br /> <strong>Remedy: <? echo $rows['remedy']; ?> PHP: This will work for all of the entries in the table "articles".
Hi, thanx for helping but the result only displays something like this: it didn't display the title, the description & the remedy
Make sure you have the relevant database selected try adding this line at the top of the previous PHP code mysql_select_db("ailment") or die(mysql_error()); PHP: let me know if it works
i have already connect to the database & it displays what i have mention on the above post, the codes for your reference $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ailment", $con); $title=$_GET['title']; $result = mysql_query("SELECT * FROM articles WHERE title='$title'") or die(mysql_error()); while($rows=mysql_fetch_array($result)) { ?> <strong><? echo $rows['title']; ?></strong> <br /><br /> <strong>Description: <? echo $rows['description']; ?> <br /><br /> <strong>Remedy: <? echo $rows['remedy']; PHP: i don't know where's the wrong part