D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] php mysql help

 

On Sat, 23 Apr 2011, Kevin Lucas wrote:

On Sat, 2011-04-23 at 21:09 +0100, Gordon Henderson wrote:
On Sat, 23 Apr 2011, Kevin Lucas wrote:

Hi all hope you are enjoying this Easter sunshine break?

No rest for the wicked...
(and we had thunder here earlier!)

//but I get a ,' left at the end so the query wont run

So is there an easier way of collecting the string together with commas
between and delimited by ' ' ?

If all else fails, use brute force:

   $x = "" ;
   foreach ($_POST ['box'] as $y)
     if ($x == "")
       $x = $y ;
     else
       $x .= ",'" . $y . "'" ;

   $x = "(" . $x . ")" ;

etc. (untested, use at your own risk, etc. and it's probably advisable to
make sure _POST ['box'] isn't empty or the foreach might whinge).

And I hope you're validating the POST data before sending to to mysql
though... (little bobby tables and all that)

Gordon


Getting close
thanks Gordon

this is the o/p from all the four methods with yours first
I need to put a ' before and after first item

(70765,'XM411','BP10891')

Ah, change:

   $x = $y ;

into

   $x = "'" . $y . "'" ;

get the checkboxes in a while list
you have chosen '70765','XM411','BP10891',

implode results(70765,XM411,BP10891)

loop round count of checkboxes and add comma
('70765','XM411','BP10891',')

Do you know why the query fails with alpha chars?

They need to be quoted.

In general, I always quote stuff - back quotes for table/column names, forward ticks for data..

Gordon

--
The Mailing List for the Devon & Cornwall LUG
http://mailman.dclug.org.uk/listinfo/list
FAQ: http://www.dcglug.org.uk/listfaq