Re: Automatic Colspan from database data

From: Date: Sat, 09 Nov 2002 20:10:39 +0000
Subject: Re: Automatic Colspan from database data
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-123619@lists.php.net to get a copy of this message
Ouch... well, assuming you have two columns: day_id and value, here's a possible solution: $rs = mysql_query ('select day_id, value from my_table order by day_id'); $a = mysql_fetch_assoc ($rs); do { $i = 1; $control = $a['value']; while (($a = mysql_fetch_assoc ($rs)) && $a['value'] == $control) $i++; echo '<td colspan=' . $i . '>' . $control . '</td>'; } while ($a); This is a bit rough and can probably be optimized quite a bit, plus I can't test it, so I'm not sure that it will work the first time. Hopefully, it gives you an idea of how it could be done. If I could make a suggestion without knowing how your system works, I think you should revisit your database design a little. Hope this helps, Marco -- ------------ php|architect - The magazine for PHP Professionals The first monthly worldwide magazine dedicated to PHP programmers Check us out on the web at http://www.phparch.com On Sat, 2002-11-09 at 14:32, Dhaval Desai wrote: > Hi! > > Well I have 12 table for 2 years which makes it 24 tables named as: > jan_2002, feb_2002 ...etc dec_2002 > jan_2003, feb_2003 ...etc dec_2003 > > Each table has fields according to the number of days in the month plus 1 > field as a unique key. > > Each registration will create 1 entry in 24 tables each and it can only be > modified as 1 entry per registrant per table. > the fields in each table will take values ranging rom 1-20. > > Well that's all about how my tables are in the database. > > > Thank You for your time > > Dhaval Desai > > > > > > > > > > >From: Marco Tabini <marcot@tabini.ca> > >To: Dhaval Desai <da_linuxguru@hotmail.com> > >CC: php-general@lists.php.net > >Subject: Re: [PHP] Automatic Colspan from database data > >Date: 09 Nov 2002 13:34:20 -0500 > > > >How is your database organized? you might be able to pull this > >information from the query by using an appropriate group-by clause. > > > > > >Marco > >-- > >------------ > >php|architect - The magazine for PHP Professionals > >The first monthly worldwide magazine dedicated to PHP programmers > >Check us out on the web at http://www.phparch.com > > > >On Sat, 2002-11-09 at 11:57, Dhaval Desai wrote: > > > > > > > > > > > > > > > Hi everybody! > > > > > > > > > Well this is how it goes... > > > > > > For the month of January there are 31 days... > > > so there are 2 rows in this table on the top row there are 31 columns > > > showing 31 days...and in the row below this one we will have to > > > generate....colspan based on the below information pulled from the > > > database... > > > > > > 2222211111111111111999999992222 > > > > > > > > > in the above case we will have to get a colspan as follows: > > > <tr> > > > <td colspan="5"> 2 </td> > > > <td colspan="15"> 1 </td> > > > <td colspan="8"> 9 </td> > > > <td>colspan="4"> 2 </td> > > > </tr> > > > > > > > > > This is all I want to do....I know it is difficult...but still waiting > >for > > > some genius! > > > > > > > > > Thank You! > > > Dhaval > > > > > > > > > _________________________________________________________________ > > > Add photos to your messages with MSN 8. Get 2 months FREE*. > > > http://join.msn.com/?page=features/featuredemail > > > > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > _________________________________________________________________ > STOP MORE SPAM with the new MSN 8 and get 2 months FREE* > http://join.msn.com/?page=features/junkmail > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.general (#123619) next »