PHP

Moderators: None (Apply to moderate this forum)
Number of threads: 1845
Number of posts: 5013

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
search database from multiple dropdownlist using php Posted by violetbaby on 19 May 2005 at 8:27 PM
somebody pls help me...
i'm very new in php...i have a problem when search database using multiple dropdownlist...
i call so many function like below to search
....either user select one dropdown list..
either two dropdownlist and all selected...
how can i combine all together in one function?call one function only whatever selection that user made..

some part in html:

<select name="Location" id="Location">
......
</select>

<select name="Subject" id="Subject">
.......
</select>

<select name="Semester" id="Semester">
...........
</select>


some part in php...

if (isset($_POST['submit'])) {

if ($_POST['Location'] && $_POST['Subject'] && $_POST['Semester'] ){

.....
$staff=$staff->getLecturers_Loc_Sub_Sem($_POST['Location'],$_POST['Subject'],$_POST['Semester']);}

else if ($_POST['Location'] && $_POST['Subject']){

.......
$staff=$staff->getLecturers_Loc_Sub($_POST['Location'],$_POST['Subject']); }

else if ($_POST['Location'] && $_POST['Semester']){

...........
$staff=$staff->getLecturers_Loc_Sem($_POST['Location'],$_POST['Semester']); }

else if ($_POST['Subject'] && $_POST['Semester']){

.......
$staff=$staff->getLecturers_Sub_Sem($_POST['Subject'],$_POST['Semester']); }

else if ($_POST['Location']){

.............
$staff=$staff->getLecturers_Loc($_POST['Location']); }

else if ($_POST['Subject']){

..............
$staff=$staff->getLecturers_Sub($_POST['Subject']); }

else if ($_POST['Semester']){

...........
$staff=$staff->getLecturers_Sem($_POST['Semester']); }

some sql statement when search location and subject in this function...

getLecturers_Loc_Sub($id1,$id2); {
....
$sql= "select * from intake i,intake_subject ij, staff_subject ss
where i.location=$id and ss.subject=$id2
and i.id=ij.intake and ij.subject=ss.subject group by ss.staff";
.....
}
Report
Re: search database from multiple dropdownlist using php Posted by Johnny13 on 21 May 2005 at 11:49 PM
Can't you give them default values?
function getLecturers($id1=0,$id2=0,$id3=0)
{...
} 

if(isset($_POST['submit']))
{/*$staff=*/$staff->getLecturers($_POST['Location'],$_POST['Subject'],$_POST['Semester']);
}
and I dunno why you must return something to the Class.
Report
Re: search database from multiple dropdownlist using php Posted by PrzemekG_ on 24 May 2005 at 9:57 AM
: Can't you give them default values?
function getLecturers($id1=0,$id2=0,$id3=0)
: {...
: } 
: 
: if(isset($_POST['submit']))
: {/*$staff=*/$staff->getLecturers($_POST['Location'],$_POST['Subject'],$_POST['Semester']);
: }
and I dunno why you must return something to the Class.
:

I solve those problems like this:
function getLecture($loc, $subject, $sem)
{
// I don't know your table structure so I call my fileds Location, Subject and Semester
   $sql = 'SELECT * FROM my_list WHERE 1';
   if ($loc) $sql .= ' AND Location="'.$loc.'"';
   if ($subject) $sql .= ' AND Subject="'.$subject.'"';
   if ($sem) $sql .= ' AND Semester="'.$sem.'"';

   // you should always produce nice SQL
   $sql .= ';';

   $resul = mysql_query($sql); // or whatever API you use
}




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.