Re: Database abstraction?

From: Date: Thu, 17 Apr 2008 18:18:22 +0000
Subject: Re: Database abstraction?
References: 1 2 3 4 5 6 7 8 9  Groups: php.general 
Request: Send a blank email to php-general+get-273207@lists.php.net to get a copy of this message
On Apr 17, 2008, at 2:12 PM, Jim Lucas wrote:
Jason Pruim wrote:
On Apr 17, 2008, at 11:14 AM, Jim Lucas wrote:
Stut wrote:
[/snip]
Both ideas worked great... Thank you! Now I do still have one question, I decided that what Jim put up worked a little bit better for me so I'm going off of his code, what I want to do now though, is take this code:
       foreach ( $dataSet AS $row ) {
echo <<<ROW
           <tr>
           <td>{$row['FName']}</td>
           <td>{$row['LName']}</td>
           <td>{$row['Add1']}</td>
           <td>{$row['Add2']}</td>
           <td>{$row['City']}</td>
           <td>{$row['State']}</td>
           <td>{$row['Zip']}</td>
           <td>{$row['XCode']}</td>
           <td>{$row['Record']}</td>
           </tr>
ROW;
       }
And turn it into some kind of a loop that would pull the info dynamically so I can have something more like this:
<?PHP while($dataSet <= $num_rows) { //print dynamic fields based off of field names echo <<<ROW <tr> <td>$dataSet['$field']</td> </tr> ROW; } ?> And what would print on the page would be something along the lines of: <?PHP echo <<<TEST <tr> <td>Jason</td> <td>Pruim</td> <td>My Address</td> <td>My Other Address</td> </tr> TEST; ?> Etc. Etc. Etc. I'm trying to avoid hardcoding things like field names so that I can use this software for multiple customers without having to completely customize it for everyone since so many parts will be the same. Maybe though I'm trying to abstract the wrong part of the program... I could do it to a few other parts and just customize this one... Need to think about that. Any ideas are greatly appreciated :) --Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424-9337 www.raoset.com japruim@raoset.com
This would do it. foreach ( $dataSet AS $row ) { echo '<tr><td>.join('</td><td>', $row).'</td></tr>'; }
Okay so that worked perfectly... NOW... Care to tell me why? :) Or point me to the right area? -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424-9337 www.raoset.com japruim@raoset.com

« previous php.general (#273207) next »