Hi all,
If anyone can help its appreciated as I really can't find a solution.
I've got a search engine that queries a "proble/solution" MYSQL database.
This returns the following for each result and displays it on the screen:
Title
Problem text
last accessed
hits
This works fine.
What I'd like to do is allow the user to click on the title to display:
Title
Problem
Solution
http: link
The reason for this is that the solution can be huge (i.e. how I pop my email).
Below is the code I've got so far.
<head>
<title>search engine</title>
</head>
<form action="search.php" method="post">
Enter Your Query:
<input type="text" name="search">
<input type="submit" name="submit" value="Submit!">
</form>
<table border="1" width="90%" cellpadding="2">
<?PHP
include "./common_db.inc";
$link_id = db_connect();
if(!$link_id) die(sql_error());
$db=mysql_connect($dbhost, $dbusername, $dbuserpassword);
if(!mysql_select_db("solution_db", $db)) die(sql_error());
if (!IsSet($search)){
$search="";
}
if ($search == "") { die("Error: Empty query string!"); }
$search=trim($search);
$search=stripslashes($search);
$searchtext = htmlentities($search);
if($search!=""){
$params = split(" ", $search);
$InQuotedString = 0;
$tokNum = 0;
$tokens = array();
//Build Tokens
$tokens[$tokNum] = "";
for($i=0; $i<count($params); $i++){
if(!IsSet($tokens[$tokNum])){
$tokens[$tokNum] = "";
}
$param = $params[$i];
if(ereg("^\"", $param) || ereg("^[+-]\"", $param)){
$InQuotedString = 1;
}
if($InQuotedString == 1){
$tokens[$tokNum] .= ereg_replace("\"", "", $param) . " ";
}
else{
$tokens[$tokNum++] = $param;
}
if(ereg("\"$", $param)){
$InQuotedString = 0;
$tokens[$tokNum] = chop($tokens[$tokNum]);
$tokNum++;
}
}
echo "<p>";
$fields[] = "problem";
$fields[] = "solution";
$sql = "select id, date_format(create_date, '%d, %b, %Y') as formatted_create_date , date_format(last_access, '%D, %M,
%Y, %r') as formatted_last_accessed, title, problem, solution, author, link, hit from solution where (";
for($i=0; $i<count($tokens); $i++){
for($x=0; $x<count($fields); $x++){
$token = ereg_replace(" $", "", $tokens[$i]);
if(ereg("^\\+", $token)){
$token = ereg_replace("^\\+", "", $token);
$sql .= "$fields[$x] like '%$token%'";
if($x<count($fields)-1){
$sql .= " OR ";
}
}
elseif(ereg("^\\-", $token)){
$token = ereg_replace("^\\-", "", $token);
$sql .= "$fields[$x] NOT like '%$token%'";
if($x<count($fields)-1){
$sql .= " AND ";
}
}
else{
$sql .= "$fields[$x] like '%$token%'";
if($x<count($fields)-1){
$sql .= " OR ";
}
}
}
if($i<count($tokens)-1){
$sql .= ") AND (";
}
else{
$sql .= ")";
}
}
$limit=" limit 20";
$sql .= " order by create_date" . $limit;
// echo "$sql";
$result=mysql_query($sql) or die("Problem with query: ".mysql_error());
}
$i = 1;
//id, create_date, problem, solution, link
while ($row = mysql_fetch_array($result)) {
$id = $row["id"];
$formatted_create_date = $row["formatted_create_date"];
$formatted_last_accessed = $row["formatted_last_accessed"];
$title = $row["title"];
$problem = $row["problem"];
$solution = $row["solution"];
$author = $row["author"];
$link = $row["link"];
$hit = $row["hit"];
// Title link
echo "<STRONG> <A
HREF=\"$PHP_SELF?action=search&id=$id&formatted_create_date=$formatted_create_date&formatted_last_accessed=$formatted
_last_accessed&title=$title&problem=$problem&solution=$solution&author=$author&link=$link&hit=$hit\">".($i).".$title</A></
STRONG>\n";
echo "<BLOCKQUOTE>\n";
echo $problem;
echo "<BR>\n";
echo "<EM>Last Accessed: $formatted_last_accessed</EM><BR>\n";
echo "<EM>Hit(s): " . number_format($hit) . "</EM><BR>\n";
echo "</BLOCKQUOTE>\n";
$i++;
}
?>
</table></body>