<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MySQL Archives - Shawn DeWolfe Consulting</title>
	<atom:link href="https://shawndewolfe.com/category/code-example/mysql/feed" rel="self" type="application/rss+xml" />
	<link>https://shawndewolfe.com/category/code-example/mysql</link>
	<description>Web Design &#124; WordPress Development &#124; WordPress Support</description>
	<lastBuildDate>Tue, 26 Nov 2019 17:48:08 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.4</generator>

<image>
	<url>https://shawndewolfe.com/wp-content/uploads/2019/05/cropped-favicon-32x32.png</url>
	<title>MySQL Archives - Shawn DeWolfe Consulting</title>
	<link>https://shawndewolfe.com/category/code-example/mysql</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Turning A List Of MySQL Rows Into A Serialized PHP string</title>
		<link>https://shawndewolfe.com/turning-a-list-of-mysql-rows-into-a-serialized-php-string</link>
					<comments>https://shawndewolfe.com/turning-a-list-of-mysql-rows-into-a-serialized-php-string#respond</comments>
		
		<dc:creator><![CDATA[Shawn DeWolfe]]></dc:creator>
		<pubDate>Tue, 26 Nov 2019 17:48:08 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<guid isPermaLink="false">https://shawndewolfe.com/?p=2945</guid>

					<description><![CDATA[<p>Turn a list of rows of from MySQL into a serialized PHP result</p>
<p>The post <a href="https://shawndewolfe.com/turning-a-list-of-mysql-rows-into-a-serialized-php-string">Turning A List Of MySQL Rows Into A Serialized PHP string</a> appeared first on <a href="https://shawndewolfe.com">Shawn DeWolfe Consulting</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><code>SELECT DISTINCT<br />
p.ID as post_id, 'prefix_list', CONCAT('a:', COUNT(*), ':{', GROUP_CONCAT(CONCAT('i:', f.`delta`, ';s:',LENGTH(f.`field_prefix_list_value`),':"', UPPER(f.`field_prefix_list_value`), '"') SEPARATOR ';'), ';}') AS `prefixes`<br />
FROM  `Giwth4_posts` p<br />
INNER JOIN node_field_data n ON (p.post_title = n.title COLLATE utf8mb4_unicode_ci)<br />
INNER JOIN `node__field_prefix_list` f ON f.revision_id = n.vid<br />
WHERE n.status = 1 AND f.deleted = 0 GROUP BY f.`entity_id` ORDER BY f.`delta`</code></p>
<ul>
<li>It starts with a count of how many elements are in a group</li>
<li>It takes the records, grouped by the common element (in this case, entity_id)</li>
<li>It concatenates the delta that is avaialble as the array index</li>
<li>It looks at the length of the value needed</li>
<li>In my case, I needed upper case strings, so I put in an UPPER() function call</li>
<li>It separates each one with a semi-colon</li>
<li>It group concatenates that</li>
<li>It does the rest of the necessary formatting.</li>
<li>It orders the elements by their delta inside of the groups to go from lowest to highest index</li>
</ul>
<p>The post <a href="https://shawndewolfe.com/turning-a-list-of-mysql-rows-into-a-serialized-php-string">Turning A List Of MySQL Rows Into A Serialized PHP string</a> appeared first on <a href="https://shawndewolfe.com">Shawn DeWolfe Consulting</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://shawndewolfe.com/turning-a-list-of-mysql-rows-into-a-serialized-php-string/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
