| | |
searching and comparing from several tables
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Try the following code:
php Syntax (Toggle Plain Text)
<? mysql_connect('localhost','root',''); mysql_select_db('mydatabase'); if (isset($_POST) && !empty($_POST)) { function generate($sql) { $dat=''; $var=mysql_query($sql); while ($data=mysql_fetch_assoc($var)) { $dat.='<tr><td>'.$data['lessonID'].'</td><td>'.$data['subject'].'</td><td>'.$data['learningArea'].'</td><td>'.$data['ability'].'</td><td>'.$data['form'].'</td><td>'.$data['skills'].'</td><td>'.$data['time'].'</td></tr>'; } return $dat; } $table=0; $string=''; if ($_POST['weight']['subject']>0 && !empty($_POST['subject'])) { $sql='SELECT * FROM `lessonplan` WHERE `subject` LIKE "%'.mysql_real_escape_string($_POST['subject']).'%"'; $string.='`subject` NOT LIKE "%'.mysql_real_escape_string($_POST['subject']).'%" AND '; $sqlarray[$_POST['weight']['subject']][]=$sql; } if ($_POST['weight']['learningarea']>0 && !empty($_POST['learningarea'])) { $sql='SELECT * FROM `lessonplan` WHERE '.$string.'`learningarea` LIKE "%'.mysql_real_escape_string($_POST['learningarea']).'%"'; $string.='`learningarea` LIKE "%'.mysql_real_escape_string($_POST['learningarea']).'%" AND '; $sqlarray[$_POST['weight']['learningarea']][]=$sql; } if ($_POST['weight']['ability']>0 && !empty($_POST['ability'])) { $sql='SELECT * FROM `lessonplan` WHERE '.$string.'`ability`="'.mysql_real_escape_string($_POST['ability']).'"'; $string.='`ability`!="'.mysql_real_escape_string($_POST['ability']).'" AND '; $sqlarray[$_POST['weight']['ability']][]=$sql; } if ($_POST['weight']['skills']>0 && !empty($_POST['skills'])) { $sql='SELECT * FROM `lessonplan` WHERE '.$string.'`skills` LIKE "%'.mysql_real_escape_string($_POST['skills']).'%"'; $string.='`skills` NOT LIKE "%'.mysql_real_escape_string($_POST['skills']).'%" AND '; $sqlarray[$_POST['weight']['skills']][]=$sql; } if ($_POST['weight']['time']>0 && !empty($_POST['time'])) { $sql='SELECT * FROM `lessonplan` WHERE '.$string.'`time` LIKE "%'.mysql_real_escape_string($_POST['time']).'%"'; $sqlarray[$_POST['weight']['time']][]=$sql; } if ($table==1) { echo '</table>'; } if (!empty($sqlarray) && isset($sqlarray)) { echo '<table border=1 cellpadding=4 cellspacing=0><tr bgcolor="#CCCCCC"><td>ID</td><td>Subject</td><td>Learning Area</td><td>Ability</td><td>Form</td><td>Skills</td><td>Time</td></tr>'; krsort($sqlarray); foreach ($sqlarray AS $array) { foreach ($array AS $sql) { echo generate($sql); } } echo '</table><p>'; } } ?> <style type="text/css"> .class { border:0px; } </style> <form method="post"> <table border=1 cellpadding=0 cellspacing=0> <tr> <td colspan=4 bgcolor="#CCCCCC">Enter Keywords here:</td> </tr><tr> <td>Subject:</td> <td><input class="class" type="text" name="subject" value="<? echo htmlentities($_POST['subject'], ENT_QUOTES); ?>"></td> <td><select name="weight[subject]" style="width:100%"> <option value="9">9 <option value="8">8 <option value="7">7 <option value="6">6 <option value="5">5 <option value="4">4 <option value="3">3 <option value="2">2 <option value="1">1 <option value="0">0 </select></td> </tr><tr> <td>Learning Area:</td> <td><input class="class" type="text" name="learningarea" value="<? echo htmlentities($_POST['learningarea'], ENT_QUOTES); ?>"></td> <td><select name="weight[learningarea]" style="width:100%"> <option value="9">9 <option value="8">8 <option value="7">7 <option value="6">6 <option value="5">5 <option value="4">4 <option value="3">3 <option value="2">2 <option value="1">1 <option value="0">0 </select></td> </tr><tr> <td>Ability:</td> <td><select name="ability" style="width:100%"> <option value="excellent">Excellent <option value="good">Good <option value="poor">Poor </select></td> <td><select name="weight[ability]" style="width:100%"> <option value="9">9 <option value="8">8 <option value="7">7 <option value="6">6 <option value="5">5 <option value="4">4 <option value="3">3 <option value="2">2 <option value="1">1 <option value="0">0 </select></td> </tr><tr> <td>Skills:</td> <td><input class="class" type="text" name="skills" value="<? echo htmlentities($_POST['skills'], ENT_QUOTES); ?>"></td> <td><select name="weight[skills]" style="width:100%"> <option value="9">9 <option value="8">8 <option value="7">7 <option value="6">6 <option value="5">5 <option value="4">4 <option value="3">3 <option value="2">2 <option value="1">1 <option value="0">0 </select></td> </tr><tr> <td>Time (minutes):</td> <td><input class="class" type="text" name="time" value="<? echo htmlentities($_POST['time'], ENT_QUOTES); ?>"></td> <td><select name="weight[time]" style="width:100%"> <option value="9">9 <option value="8">8 <option value="7">7 <option value="6">6 <option value="5">5 <option value="4">4 <option value="3">3 <option value="2">2 <option value="1">1 <option value="0">0 </select></td> </tr><tr bgcolor="#CCFFCC"> <td colspan=2>Search Now:</td> <td bgcolor="#FFFFFF"><input type="submit" value="Search"></td> </tr></table></form>
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
My favourite PC. - Oopy Doopy Do 2U2!
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*` My favourite PC. - Oopy Doopy Do 2U2!
Could you please explain in more detail what each column does. What I so far get is that there is one table per keyword box and the simularity field is times by the keyword strength and the id field is the linker between the lookup table and the lessonplan table. What I dont get is what are the fields 'query' and 'case' used for?
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
My favourite PC. - Oopy Doopy Do 2U2!
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*` My favourite PC. - Oopy Doopy Do 2U2!
I just check the picture you sent and it has 12 searchable fields where as the mysql database has only 10 fields. How is that suppose to work? Also what might make this a lot easier since how you have a picture is if you write ontop of each box in the picture what mysql column the input box is meant to refer to because this is becomming a mind warp.
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
My favourite PC. - Oopy Doopy Do 2U2!
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*` My favourite PC. - Oopy Doopy Do 2U2!
•
•
Join Date: May 2009
Posts: 81
Reputation:
Solved Threads: 0
•
•
•
•
it has 12 searchable fields where as the mysql database has only 10 fields. How is that suppose to work
The main problem is I do not know how to refer to several lookup tables. How can I do this ?
many thanks.
•
•
Join Date: May 2009
Posts: 81
Reputation:
Solved Threads: 0
Result of the search will be displayed in rank.
The most similar record to the query will be at the top of the result list..followed by the 2nd most similar and so on.
this similarity is calculated by referring to the weight and similar match of the keyword (query) and records in database.
Your code is good, but I need a suggestion on how to integrate the code to the lookup tables (which contain similarity)
thanks
The most similar record to the query will be at the top of the result list..followed by the 2nd most similar and so on.
this similarity is calculated by referring to the weight and similar match of the keyword (query) and records in database.
Your code is good, but I need a suggestion on how to integrate the code to the lookup tables (which contain similarity)
thanks
•
•
•
•
Your code is good, but I need a suggestion on how to integrate the code to the lookup tables (which contain similarity)
thanks
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
My favourite PC. - Oopy Doopy Do 2U2!
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*` My favourite PC. - Oopy Doopy Do 2U2!
![]() |
Similar Threads
- Using REGEXP in searching (ASP)
- Searching Multiple tables... Please help me!!!!! (PHP)
- Searching multiple MS SQL Tables (VB.NET)
- Searching a record in 3 tables (Visual Basic 4 / 5 / 6)
- Searching and Comparing strings from an XML Document (Python)
Other Threads in the PHP Forum
- Previous Thread: Fix the options in Cakephp Form Field of type radio button
- Next Thread: How to Update database when the Browser is closed
Views: 768 | Replies: 21
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email encode error file files folder form forms function functions google howtowriteathesis href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail menu methods mlm mod_rewrite multiple multipletables mysql oop parse paypal pdf php problem provider query radio random recursion regex remote script search select server sessions sms soap source space speed sql structure syntax system table template tutorial update updates upload url validation validator variable video web xml youtube






