Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #7646
| From | Scott Johnson <noonehome@chalupasworld.com> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Query a Array Field in MySQL |
| Date | 2012-11-26 12:00 -0800 |
| Organization | A noiseless patient Spider |
| Message-ID | <k90hpr$1h2$1@dont-email.me> (permalink) |
| References | <54d3cfad-b3c7-4ae2-b375-8897168810df@googlegroups.com> |
On 11/26/2012 9:04 AM, heitorfaria@gmail.com wrote:
> Hello folks,
>
> I have the following function:
> #====================================================================
> #=======================================
> # @ Build Search Drop
> # Builds a search field drop-down list.
> #=======================================
>
> function build_search_drop($select='')
> {
>
>
> $fields = array( 'id' => 'Ticket ID', 'subject' => 'Subject', 'message' => 'Message', 'mname' => 'Submitted By', 'email' => 'Email' );
>
>
> $ift_html = "<select name='field' id='field'>";
>
> foreach( $fields as $id => $name )
> {
> if ( $select == $id )
> {
> $ift_html .= "<option value='{$id}' selected='yes'>{$name}</option>";
> }
> else
> {
> $ift_html .= "<option value='{$id}'>{$name}</option>";
> }
> }
>
> $ift_html .= "</select>";
>
> return $ift_html;
> }
>
> }
>
> ?>
> #====================================================================
>
> What in need: in $fields=array(...), I want to be able to query another (more complex) database field witch contains a MySql Array (I guess). It has this kind of information:
> #====================================================================
> a:4:{s:10:"rincidente";s:2:"ri";s:13:"codigoservico";s:5:"00000";s:3:"url";b:0;s:8:"localcpd";s:3:"bsa";}
> #====================================================================
>
> So I want to add a query that can return the value of "rincidente" or "codigoservico", for exemple. Is that possible? How I do that?
>
> Regards,
>
> Heitor Faria
>
If the
'a:4:{s:10:"rincidente";s:2:"ri";s:13:"codigoservico";s:5:"00000";s:3:"url";b:0;s:8:"localcpd";s:3:"bsa";}'
is what you are querying from the DB, that is a 'serialized' value.
Once you have pulled that value out of the DB just unserialize it:
$data_ary = unserialize($serialized_data);
This will create an Associative array of that data.
You can then plug the $data_ary in place of the $fields var.
This will not account for error checking or html code in the data that
could muck up your page.
if you are in control of the data in, then the data out can be controlled.
If you are getting this data from a third party, make sure you have some
good data checking methods in place.
You can verify the array structure returned by using print_r(); or
var_export();
The data you gave for example is:
Array
(
[rincidente] => ri
[codigoservico] => 00000
[url] =>
[localcpd] => bsa
)
If you are unsure of how to query the DB then you may want to hope over
to c.d.mysql group.
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Query a Array Field in MySQL heitorfaria@gmail.com - 2012-11-26 09:04 -0800
Re: Query a Array Field in MySQL Scott Johnson <noonehome@chalupasworld.com> - 2012-11-26 12:00 -0800
Re: Query a Array Field in MySQL heitorfaria@gmail.com - 2012-11-27 06:40 -0800
Re: Query a Array Field in MySQL heitorfaria@gmail.com - 2012-11-27 06:56 -0800
Re: Query a Array Field in MySQL Scott Johnson <noonehome@chalupasworld.com> - 2012-11-27 21:10 -0800
Re: Query a Array Field in MySQL Jerry Stuckle <jstucklex@attglobal.net> - 2012-11-26 15:10 -0500
Re: Query a Array Field in MySQL Denis McMahon <denismfmcmahon@gmail.com> - 2012-11-27 00:28 +0000
Re: Query a Array Field in MySQL Denis McMahon <denismfmcmahon@gmail.com> - 2012-11-27 00:28 +0000
csiph-web