Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #7647

Re: Query a Array Field in MySQL

From Jerry Stuckle <jstucklex@attglobal.net>
Newsgroups comp.lang.php
Subject Re: Query a Array Field in MySQL
Date 2012-11-26 15:10 -0500
Organization A noiseless patient Spider
Message-ID <k90iat$56d$1@dont-email.me> (permalink)
References <54d3cfad-b3c7-4ae2-b375-8897168810df@googlegroups.com>

Show all headers | View raw


On 11/26/2012 12:04 PM, 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
>

MySQL does not have arrays.  If this is what you got back from a column 
in MySQL, then the database is not properly normalized (one column 
contains multiple values - fails 1st normal condition).

The data is output from the php serialize() function.  You will need to 
unserialize() it, which will create an array for you.  Then you can 
access the rincidente member of the array.

And for pete's sake - get a good database design before going any 
further.  The current one will cause you no end of problems!  (For 
further information on database design, try comp.databases.mysql).

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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