PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 5th, 2013, 03:07 AM
bayken37 bayken37 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Location: Paris, France
Posts: 15 bayken37 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 38 m 36 sec
Reputation Power: 0
PHP-General - Explode to array

Using GROUP_CONCAT in my SQL I have a comma-separated list of values for each year.

What do I need to now do in PHP to allow those values to be separated by <td>'s

So my query returns something like this:
2013: a,b,c,d,...
2012: b,c,e,f,...
...

I want all of those including the year to be placed into <tr>'s and then separated by <td> with no commas

I've ready about exploding into arrays, but my knowledge of this in PHP isn't quite there yet.

Any ideas?

Reply With Quote
  #2  
Old February 5th, 2013, 03:39 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,869 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 22 h 59 m 40 sec
Reputation Power: 813
Hi,

don't misuse GOUP_CONCAT for fetching groups of values. Fetch normal rows (ordered by the date), and whenever the date changes, add a </tr><tr>. If you don't have too many dates, you could also fetch the values separately for each date.

Reply With Quote
  #3  
Old February 5th, 2013, 06:43 AM
bayken37 bayken37 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Location: Paris, France
Posts: 15 bayken37 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 38 m 36 sec
Reputation Power: 0
Yeah I didn't think that GROUP_CONCAT was what I really needed, but the reason I went to that was because I wasn't sure how to do precisely what you suggested.

How do I make it so that a new row is formed once the year changes?

Reply With Quote
  #4  
Old February 5th, 2013, 06:58 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,869 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 22 h 59 m 40 sec
Reputation Power: 813
Make a variable which holds the last date. And then check it on each iteration:
PHP Code:
 $last_date '';
foreach (
$values as $value) {
    if (
$value['date'] != $last_date) {
        
$last_date $value['date'];
        echo 
'</tr><tr>';
    }
    ...


Reply With Quote
  #5  
Old February 5th, 2013, 11:10 AM
bayken37 bayken37 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Location: Paris, France
Posts: 15 bayken37 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 38 m 36 sec
Reputation Power: 0
Thanks, one more question though: how do I get the year to show up in the first <td> of each <tr>

Here's what I have:
PHP Code:
 $last_date ''
while(
$row mysql_fetch_assoc$result ))  
{
    if (
== ($i++ & 1))
    {
        
$sClass 'odd';
    }
    else
    {
        
$sClass 'even';
    }
    if (
$row['Year_GG'] != $last_date) { 
        
$last_date $row['Year_GG']; 
        echo 
'</tr><tr class="'.$sClass.'">'
    }
        
printf('
        <td>%s</td>' 
PHP_EOL$row['LName']); 


Reply With Quote
  #6  
Old February 5th, 2013, 02:08 PM
bayken37 bayken37 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Location: Paris, France
Posts: 15 bayken37 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 38 m 36 sec
Reputation Power: 0
scratch that, found it.. was easier than I had thought..

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP-General - Explode to array

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap