[PHP-DB] neeld voluntary help regarding project!
I was wondering if anyone wants to help me with this project. I already have a test database we can use, I just need help making the team pages. please take a look and reply if interested. thanks in advance I'm a noobie in regards of php but I am trying to learn. http://www.theufl.com/ufl_project.htm Karl James (TheSaint) [EMAIL PROTECTED] http://theufl.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Accessing Matisse DB
Robert Twitty wrote: Is there anyone here can tell me how to access Matisse DB? Thank you. Isn't there anyone can help me? Look at http://www.matisse.com/pdf/developers/php.pdf I found it by Googling for "Matisse PHP" I have. But it doesn't help much. Thanks anyway. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql to postgres migration blues...
On Thu, 23 Sep 2004 12:23:32 -0700, Andrew Kreps <[EMAIL PROTECTED]> wrote: > On Thu, 23 Sep 2004 20:51:52 +0200, Antoine <[EMAIL PROTECTED]> wrote: > > declaring it as global didn't seem to work - > > > > global $link; > > /* Connect to database */ > > $link = pg_connect("dbname=movies host=localhost user=anton > > password=password") > > The global keyword works a little bit differently in PHP. You need to > inform your function that your variable is global, as opposed to > declaring it as global outside the function. Like: > > $link = "database connection" > > function processData () { > global $link; > ... Like i said, I'll get there ;-). Cheers! I hope you folks don't mind answering some rather basic questions... I am going to be starting some serious development soon and promise to search the docs first :-). I have just followed up on the suggestion of pear and it looks like a winner. That may mean a change of mailing list but all good for the moment. Cheers Antoine -- G System, The Evolving GUniverse - http://www.g-system.at -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] MultSelect ListBox hell!
Well don't hate me for coming back here. I am shamed and embarassed enough. And while I appreciate all the great code and feedback received , I've run into a glitch. (oi) Because I'm using CodeCharge, it's not easy to just insert custom code anywhere. That is one of those code generators. I suppose if I had more hands on php coding the way could be found. So here is what I have: //Here is defines the field variable and uses //CodeCharge function to grab the variable $s_Industry = CCGetParam("s_Industry", ""); $s_LocationState = CCGetParam("s_LocationState", ""); $s_TaxTerm = CCGetParam("s_TaxTerm", ""); //Here is the parsing of the array. I'm not sure what the $proj variable is for. I gather it's a holder for the array values if (count($s_Industry) > 0 AND is_array($s_Industry)) { foreach ($s_Industry as $key => $value) { if ($Proj1 != "") $Proj1 = $Proj1.","; $Proj1 = $Proj1."'".$value."'"; } } //Parsing next array if (count($s_LocationState) > 0 AND is_array($s_LocationState)) { foreach ($s_LocationState as $key => $value) { if ($Proj2 != "") $Proj2 = $Proj2.","; $Proj2 = $Proj2."'".$value."'"; } } //Parsing file array if (count($s_TaxTerm) > 0 AND is_array($s_TaxTerm)) { foreach ($s_TaxTerm as $key => $value) { if ($Proj3 != "") $Proj3 = $Proj3.","; $Proj3 = $Proj3."'".$value."'"; } } Here is what will be the death of me :) First the where condition below is being appended to anoher file in my main sql statement (don't ask:)) CC keeps their code in various sections and files. Anyway , if you remember yesterday, it was determined that I needed the where condition to be dynamically created based on the user input. Obviously the code below does nothing of that sort. So as a start, I'm trying to figure out what I can do with this section here (since this is really what needs to be changed, I think) to make it all right. if ($Proj1) $VendorJobs->ds->SQL.= " AND (`VendorJobs`.Industry IN (".$Proj1."))"; if ($Proj2) $VendorJobs->ds->SQL.= " AND (`VendorJobs`.LocationState IN (".$Proj2."))"; if ($Proj3) $VendorJobs->ds->SQL.= " AND (VendorJobs.TaxTerm IN (".$Proj3."))"; echo "SQL:". $VendorJobs->ds->SQL.""; As a crash course on this issue, search form has 6 fields, user may enter 1 or up to all 6 values, but the results should be refined as more values are added. In other words AND is correct conditional , but has to allow for user to choose how many values they want to put in. Anyway , don't throw me off the list yet! I am reading on PHP, but I have gone pretty far on this project and prefer to finish it without diverting back/ Thank you, Stuart -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql to postgres migration blues...
On Thu, 23 Sep 2004 20:51:52 +0200, Antoine <[EMAIL PROTECTED]> wrote: > declaring it as global didn't seem to work - > > global $link; > /* Connect to database */ > $link = pg_connect("dbname=movies host=localhost user=anton > password=password") The global keyword works a little bit differently in PHP. You need to inform your function that your variable is global, as opposed to declaring it as global outside the function. Like: $link = "database connection" function processData () { global $link; ... } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql to postgres migration blues...
On Thu, 23 Sep 2004 22:27:38 +0400, M Saleh EG <[EMAIL PROTECTED]> wrote: > define the connection object as a global var in ur function > > function ( params) > { > global $ur_connection_obj; > ... > ... > Damn you guys are quick! I like this list... declaring it as global didn't seem to work - global $link; /* Connect to database */ $link = pg_connect("dbname=movies host=localhost user=anton password=password") or die("Could not connect : " . pg_result_error($link)); still didn't get it but passing it to the function did. I'll get there, but I pretty much copied and pasted all the php up until now so I have a little way to go... Cheers Antoine -- G System, The Evolving GUniverse - http://www.g-system.at -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql to postgres migration blues...
define the connection object as a global var in ur function function ( params) { global $ur_connection_obj; ... ... } On Thu, 23 Sep 2004 14:56:10 -0300, Eduardo Sampaio <[EMAIL PROTECTED]> wrote: > Its because the function cannot access your connection object... > Try passing it to the function.. > > function makelistboxentries($link, $title, $mytable, $mycolumn, $othertable, > $wherestring) > > > > > On Thu, 23 Sep 2004 19:44:51 +0200, Antoine <[EMAIL PROTECTED]> wrote: > > Hi, > > I am trying to get skilled up on postgres and decided to port a little > > movie database I wrote for mysql with php to access it. > > I used an auto converter for the bulk and then tried to tweak. The > > following code does not work but the error message it gives me is > > strange. It tells me that the connection string used on line 82 (where > > it calls pg_query in makelistboxentries) is invalid... but the same > > string/connection works just great in another script... any pointers > > appreciated. > > Cheers > > Antoine > > > > > > >/* Connect to database */ > >$link = pg_connect("dbname=movies host=localhost user=anton > > password=password") > >or die("Could not connect : " . pg_result_error($link)); > > > > print << > > > Search by: > > > > > > > > ID: > > > > > > > > > > > > > > > > > > Name: > > > > > > > > > > > > > > > > TII; > > makelistboxentries("Audio Language", "lang", "lang", " audio ", " > > t2.movie = t1.ID and t2.lang = "); > > makelistboxentries("Subtitle Language", "lang", "lang", " subtitles ", > > " t2.movie = t1.ID and t2.lang = "); > > makelistboxentries("Genre", "Genre", "Genre", " moviegenre ", " > > t2.movie = t1.ID and t2.genre = "); > > > > print << > > > > > > > Show All: > > > method="post"> > > > > > > > > > >Back to main page > >Add a movie > >Add a movie's audio languages > >Add a movie's subtitle languages > >Search the movies > > > > TINI; > >/* Close connection */ > >pg_close($link); > > > > function makelistboxentries($title, $mytable, $mycolumn, $othertable, > > $wherestring) > > { > > > > print ""; > > > > print "$title:"; > >/* Perform SQL query */ > >$query = "SELECT $mycolumn FROM $mytable"; > >$result = pg_query($link,$query) > >or die("Query failed : " . pg_result_error($link)); > >print ""; > >print ""; > >print "Select $title"; > >while ($line = pg_fetch_array($result,$result_countt++,PGSQL_ASSOC)) { > >foreach ($line as $col_value) { > >print (""); > >print $col_value; > >print (""); > >} > > > >} > > print ""; > > print ""; > > print ""; > > print ""; > > print ""; > > > >pg_free_result($result); > > } > > > > ?> > > > > -- > > G System, The Evolving GUniverse - http://www.g-system.at > > > > -- > > PHP Database Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- M.Saleh.E.G 97150-4779817 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql to postgres migration blues...
Its because the function cannot access your connection object... Try passing it to the function.. function makelistboxentries($link, $title, $mytable, $mycolumn, $othertable, $wherestring) On Thu, 23 Sep 2004 19:44:51 +0200, Antoine <[EMAIL PROTECTED]> wrote: > Hi, > I am trying to get skilled up on postgres and decided to port a little > movie database I wrote for mysql with php to access it. > I used an auto converter for the bulk and then tried to tweak. The > following code does not work but the error message it gives me is > strange. It tells me that the connection string used on line 82 (where > it calls pg_query in makelistboxentries) is invalid... but the same > string/connection works just great in another script... any pointers > appreciated. > Cheers > Antoine > > >/* Connect to database */ >$link = pg_connect("dbname=movies host=localhost user=anton > password=password") >or die("Could not connect : " . pg_result_error($link)); > > print << > Search by: > > > > ID: > > > > > > > > > Name: > > > > > > > > TII; > makelistboxentries("Audio Language", "lang", "lang", " audio ", " > t2.movie = t1.ID and t2.lang = "); > makelistboxentries("Subtitle Language", "lang", "lang", " subtitles ", > " t2.movie = t1.ID and t2.lang = "); > makelistboxentries("Genre", "Genre", "Genre", " moviegenre ", " > t2.movie = t1.ID and t2.genre = "); > > print << > > > Show All: > method="post"> > > > > >Back to main page >Add a movie >Add a movie's audio languages >Add a movie's subtitle languages >Search the movies > > TINI; >/* Close connection */ >pg_close($link); > > function makelistboxentries($title, $mytable, $mycolumn, $othertable, > $wherestring) > { > > print ""; > > print "$title:"; >/* Perform SQL query */ >$query = "SELECT $mycolumn FROM $mytable"; >$result = pg_query($link,$query) >or die("Query failed : " . pg_result_error($link)); >print ""; >print ""; >print "Select $title"; >while ($line = pg_fetch_array($result,$result_countt++,PGSQL_ASSOC)) { >foreach ($line as $col_value) { >print (""); >print $col_value; >print (""); >} > >} > print ""; > print ""; > print ""; > print ""; > print ""; > >pg_free_result($result); > } > > ?> > > -- > G System, The Evolving GUniverse - http://www.g-system.at > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] mysql to postgres migration blues...
Could be a scope problem. The connection is declared outside the function and the attempt to run a query is inside the function...Maybe add the global command to the connection. Or declare the connection inside the function... Bastien From: Antoine <[EMAIL PROTECTED]> Reply-To: Antoine <[EMAIL PROTECTED]> To: [EMAIL PROTECTED] Subject: [PHP-DB] mysql to postgres migration blues... Date: Thu, 23 Sep 2004 19:44:51 +0200 Hi, I am trying to get skilled up on postgres and decided to port a little movie database I wrote for mysql with php to access it. I used an auto converter for the bulk and then tried to tweak. The following code does not work but the error message it gives me is strange. It tells me that the connection string used on line 82 (where it calls pg_query in makelistboxentries) is invalid... but the same string/connection works just great in another script... any pointers appreciated. Cheers Antoine /* Connect to database */ $link = pg_connect("dbname=movies host=localhost user=anton password=password") or die("Could not connect : " . pg_result_error($link)); print << Search by: ID: Name: TII; makelistboxentries("Audio Language", "lang", "lang", " audio ", " t2.movie = t1.ID and t2.lang = "); makelistboxentries("Subtitle Language", "lang", "lang", " subtitles ", " t2.movie = t1.ID and t2.lang = "); makelistboxentries("Genre", "Genre", "Genre", " moviegenre ", " t2.movie = t1.ID and t2.genre = "); print << Show All: Back to main page Add a movie Add a movie's audio languages Add a movie's subtitle languages Search the movies TINI; /* Close connection */ pg_close($link); function makelistboxentries($title, $mytable, $mycolumn, $othertable, $wherestring) { print ""; print "$title:"; /* Perform SQL query */ $query = "SELECT $mycolumn FROM $mytable"; $result = pg_query($link,$query) or die("Query failed : " . pg_result_error($link)); print ""; print ""; print "Select $title"; while ($line = pg_fetch_array($result,$result_countt++,PGSQL_ASSOC)) { foreach ($line as $col_value) { print (""); print $col_value; print (""); } } print ""; print ""; print ""; print ""; print ""; pg_free_result($result); } ?> -- G System, The Evolving GUniverse - http://www.g-system.at -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ Take advantage of powerful junk e-mail filters built on patented Microsoft® SmartScreen Technology. http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines Start enjoying all the benefits of MSN® Premium right now and get the first two months FREE*. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] mysql to postgres migration blues...
Hi, I am trying to get skilled up on postgres and decided to port a little movie database I wrote for mysql with php to access it. I used an auto converter for the bulk and then tried to tweak. The following code does not work but the error message it gives me is strange. It tells me that the connection string used on line 82 (where it calls pg_query in makelistboxentries) is invalid... but the same string/connection works just great in another script... any pointers appreciated. Cheers Antoine Search by: ID: Name: TII; makelistboxentries("Audio Language", "lang", "lang", " audio ", " t2.movie = t1.ID and t2.lang = "); makelistboxentries("Subtitle Language", "lang", "lang", " subtitles ", " t2.movie = t1.ID and t2.lang = "); makelistboxentries("Genre", "Genre", "Genre", " moviegenre ", " t2.movie = t1.ID and t2.genre = "); print << Show All: Back to main page Add a movie Add a movie's audio languages Add a movie's subtitle languages Search the movies TINI; /* Close connection */ pg_close($link); function makelistboxentries($title, $mytable, $mycolumn, $othertable, $wherestring) { print ""; print "$title:"; /* Perform SQL query */ $query = "SELECT $mycolumn FROM $mytable"; $result = pg_query($link,$query) or die("Query failed : " . pg_result_error($link)); print ""; print ""; print "Select $title"; while ($line = pg_fetch_array($result,$result_countt++,PGSQL_ASSOC)) { foreach ($line as $col_value) { print (""); print $col_value; print (""); } } print ""; print ""; print ""; print ""; print ""; pg_free_result($result); } ?> -- G System, The Evolving GUniverse - http://www.g-system.at -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Using PHP to generate SQL statement
> -Original Message- > Seems to me we've just answered a very similar question to this (and I'd > be > surprised it there weren't several relevant threads in the list archives). > Nonetheless: I was so tired last night that I don't even remember if I checked the archives first - my bad. Thanks for helping Mike. And thanks to Manuel and Eduardo. I'll explore these options and go from there. -Ed -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] File Mime Type Function
cool, that's what I was looking at doing, I was just wondering if there was anything native to php 4.3.8. On Thu, 23 Sep 2004 11:59:41 -0500, Matt M. <[EMAIL PROTECTED]> wrote: > > I've looked around for a while, does anyone know of a PHP function > > already built in to the install that gets the Mime type of a file on > > the server? > > you might try this > > http://pear.php.net/package/MIME_Type/ > -- << Jasper Howard - Database Administration ApexEleven.com 530 559 0107 --->> -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Form input/output manager class
I know it's not the right place to post... but donno where else I could post! Any idea about a good class that parses form input/outputs written in PEAR level and standards? -- M.Saleh.E.G 97150-4779817 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] File Mime Type Function
> I've looked around for a while, does anyone know of a PHP function > already built in to the install that gets the Mime type of a file on > the server? you might try this http://pear.php.net/package/MIME_Type/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] File Mime Type Function
I've looked around for a while, does anyone know of a PHP function already built in to the install that gets the Mime type of a file on the server? thanks, -- << Jasper Howard - Database Administration ApexEleven.com 530 559 0107 --->> -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Using PHP to generate SQL statement
Hello, On 09/23/2004 03:46 AM, Ed Lazor wrote: I keep looking at the following code and thinking there's gotta be a better way. I've been in front of the computer all day tho and I'm drawing a blank. Any ideas? You may want to consider a Data Access Objects (DAO) class generator. DAO classes encapsulate the storage and retrieval of data in database table rows as objects of associated classes. Each retrieved row is mapped to an object of a DAO class. The row columns are mapped to class variables. Since usually DAO classes are tedious to implement by hand, you may want to try this PHP DAO generator tool that lets you define your DAO classes in a simple XML format including variables, validation rules, relationships and functions that you need to manipulate your data objects and it generates all the code for you: http://freshmeat.net/projects/metastorage/ -- Regards, Manuel Lemos PHP Classes - Free ready to use OOP components written in PHP http://www.phpclasses.org/ PHP Reviews - Reviews of PHP books and other products http://www.phpclasses.org/reviews/ Metastorage - Data object relational mapping layer generator http://www.meta-language.net/metastorage.html -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Using PHP to generate SQL statement
Or you could use a more flexible way, allowing you to easily add other filters to the query. $sql = "select ID from products"; if ($webpage->parameter_isset("CategoryID")) $sql = addFilter($sql,"CategoryID",$webpage->CategoryID); if ($webpage->parameter_isset("CompanyID")) $sql = addFilter($sql,"CompanyID",$webpage->CompanyID); if ($webpage->parameter_isset("SettingID")) $sql = addFilter($sql,"SettingID",$webpage->SettingID); if ($webpage->parameter_isset("SystemID")) $sql = addFilter($sql,"SystemID",$webpage->SystemID); $sql .= " limit 10"; return $sql; function addFilter($qry,$fld,$val,$cnd='=') { if ($qry && $fld) { if (preg_match("/where/i",$qry)) { $qry.= ' and'; } else { $qry.= ' where'; } $qry.= " $fld $cnd '$val'"; } return $qry; } On Thu, 23 Sep 2004 13:25:18 +0100, Ford, Mike <[EMAIL PROTECTED]> wrote: > On 23 September 2004 07:47, Ed Lazor wrote: > > > I keep looking at the following code and thinking there's > > gotta be a better > > way. I've been in front of the computer all day tho and I'm drawing > > a blank. Any ideas? > > Seems to me we've just answered a very similar question to this (and I'd be > surprised it there weren't several relevant threads in the list archives). > Nonetheless: > > > $sql = "select ID from products where "; > > > > if ($webpage->parameter_isset("CategoryID")) { > > Two possible approaches that spring to mind are: > > $sql = "select ID from products where 1=1"; > > if ($webpage->parameter_isset("CategoryID")) { > $sql .= " AND CategoryID = '{$webpage->CategoryID}'"; > } > > if ($webpage->parameter_isset("CompanyID")) { > $sql .= " AND CompanyID = '{$webpage->CompanyID}'"; > } > > if ($webpage->parameter_isset("SettingID")) { > $sql .= " AND SettingID = '{$webpage->SettingID}'"; > } > > if ($webpage->parameter_isset("SystemID")) { > $sql .= "AND SystemID = '{$webpage->SystemID}'"; > } > > Or: > > $where = '' > foreach (array('CategoryID', 'CompanyID', 'SettingID', 'SystemID') > as $field): > if ($webpage->parameter_isset($field)): >$where .= ($where?' AND':'')." $field = '{$webpage->$field}'"; > endif; > endforeach; > > if ($where): > $sql = "select ID from products where$where"; > ... > else: > // no where information -- major error > endif; > > Cheers! > > Mike > > - > Mike Ford, Electronic Information Services Adviser, > Learning Support Services, Learning & Information Services, > JG125, James Graham Building, Leeds Metropolitan University, > Headingley Campus, LEEDS, LS6 3QS, United Kingdom > Email: [EMAIL PROTECTED] > Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
SV: [PHP-DB] MultSelect ListBox hell!
On 22 September 2004 18:45, Stuart Felenstein wrote: Given the conditions you want your WHERE phrase to test, you're going to need more parentheses to force the ORs to be evaluated before the ANDs; this is where the IN syntax, IMO, is more readable. So you want either: $sql .= "(state='".implode("' OR state='",$_POST['state'])."')"; or: $sql .= "state IN ('".implode("','",$_POST['state'])."')"; I agree, the IN syntax is more readable. But if the field is indexed, the OR syntax is faster, though not noticeably so in small tables. Regards Henrik Hornemann -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Using PHP to generate SQL statement
On 23 September 2004 07:47, Ed Lazor wrote: > I keep looking at the following code and thinking there's > gotta be a better > way. I've been in front of the computer all day tho and I'm drawing > a blank. Any ideas? Seems to me we've just answered a very similar question to this (and I'd be surprised it there weren't several relevant threads in the list archives). Nonetheless: > $sql = "select ID from products where "; > > if ($webpage->parameter_isset("CategoryID")) { Two possible approaches that spring to mind are: $sql = "select ID from products where 1=1"; if ($webpage->parameter_isset("CategoryID")) { $sql .= " AND CategoryID = '{$webpage->CategoryID}'"; } if ($webpage->parameter_isset("CompanyID")) { $sql .= " AND CompanyID = '{$webpage->CompanyID}'"; } if ($webpage->parameter_isset("SettingID")) { $sql .= " AND SettingID = '{$webpage->SettingID}'"; } if ($webpage->parameter_isset("SystemID")) { $sql .= "AND SystemID = '{$webpage->SystemID}'"; } Or: $where = '' foreach (array('CategoryID', 'CompanyID', 'SettingID', 'SystemID') as $field): if ($webpage->parameter_isset($field)): $where .= ($where?' AND':'')." $field = '{$webpage->$field}'"; endif; endforeach; if ($where): $sql = "select ID from products where$where"; ... else: // no where information -- major error endif; Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] MultSelect ListBox hell!
On 22 September 2004 18:45, Stuart Felenstein wrote: > Just to confirm, > This is what I'm going to start with: Yeah, I'd say you've pretty much got it, except... > //base sql statement > $sql = "select * from jobs where record_deleted = 'NO' "; > > if (isset($_POST['states'])){ Your SQL is going to need some sort of conjunction here, as your WHERE phrase already has an initial condition in it. I'm guessing you'll want an AND, so: $sql .= 'AND '; > //check to see if the states is an array > // multiple items or just one > if (is_array($_POST['state'])) You've switched from $_POST['states'] to $_POST['state'] -- fix whichever is wrong ;) > $sql .= "state='".implode("' OR state='", > $_POST['state'])."'"; Given the conditions you want your WHERE phrase to test, you're going to need more parentheses to force the ORs to be evaluated before the ANDs; this is where the IN syntax, IMO, is more readable. So you want either: $sql .= "(state='".implode("' OR state='",$_POST['state'])."')"; or: $sql .= "state IN ('".implode("','",$_POST['state'])."')"; > > }else{ > //$_POST['state'] is not an array > $sql .= "state = '".$_POST['state']."' "; > }//end if > > if (isset($_POST['job'])){ >if (isset($_POST['state'])){ $sql .= " AND "; } And throughout this second block you've used a cut'n'paste of the first block without altering ['state'] to ['job'] -- just the sort of oversight that can give you the raving heebie-jeebies somewhere down the line if you fail to fix it! ;) > > //add in the AND if the state is set > //check to see if the states is an array > //multiple items or just one > > if (is_array($_POST['state'])) >$sql .= "state='".implode("' OR state='", > $_POST['state'])."'"; > $sql .= ")"; > }else{ > $_POST['job'] is not an array > $sql .= "job = '".$_POST['job']."' "; > } > //end if Given the moderate complexity of this code, I'd strongly recommend echo-ing out $sql immediately before it's used whilst you're in testing mode. When your query fails, you'll already be one step ahead in working out what the problem is. Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php