Hi Ken, Thanks very much for that.
I pasted your code straight in and it works. Have a great weekend! Mat On Nov 6, 4:54 pm, "Ken Golovin" <[email protected]> wrote: > $row[3] is a simple string, as it is how it is stored in the DB. Mysql does > not have an array field type, so unless you are using Doctrine or other ORM > that implements array field type, you have to manually convert String => > Array, like this for example: > > $sizeArray = explode(',', $row[3]); > > > > ----- Original Message ----- > From: "MatF" <[email protected]> > To: "NZ PHP Users Group" <[email protected]> > Sent: Friday, November 06, 2009 4:36 PM > Subject: [phpug] Array within an array, or unusable Good Test Code vs > > unusable Crappy Test Code > > > Hi All, > > > I'm trying to put a set of numbers (i.e. stored like: 0,2,4,6,8,10...) > > from a database field, into an array, so that I can loop through and > > display them. > > > Below is my 'Good Test Code' that uses manually populated arrays, > > followed by the 'Good Results' I get. > > > Below this, under 'Crappy Test Code' is the same code (with the kind > > of thing I am trying to do, although successfully ;) with the line: > > $sizeArray = array(0,2,4,6,8,10,12,14,16,18,20,22,24,26,28); > > changed to: > > $sizeArray = array($row[3]); > > follow by the 'Crappy Results' results that I get. > > > For some reason (that I don't know of), the $sizeArray seems to treat > > the $row[3] as a literal string or something??? > > > I hope this makes sense and sorry the post is a bit long. > > > Mat > > > Good Test Code > > ============ > > <?php > > > require_once('model/global.php'); > > > $field = '*'; > > $table = 'sizes'; > > $condition = "WHERE brandID = 'mega-whoppers'"; > > include('model/qrySelect.php'); > > > $row = $result->fetch_array(MYSQLI_NUM); > > printf ("%s (%s)\n", $row[3], $row[4]); > > > $sizeArray = array(0,2,4,6,8,10,12,14,16,18,20,22,24,26,28); > > $bustArray = array > > (31,32,33,34,35,36.5,38,39.5,41,43,45,47.5,50,53,56); > > $waistArray = array > > (31,32,33,34,35,36.5,38,39.5,41,43,45,47.5,50,53,56); > > $hipsArray = array > > (31,32,33,34,35,36.5,38,39.5,41,43,45,47.5,50,53,56); > > $notesArray = array("Standard gown length is 59 inches / 150 cm's from > > hollow to hem.","Standard bodice length is 14.5 inches / 37 cm's from > > hollow to waist.","Standard sleeve length is 18 inches / 46 cm's from > > underarm to wrist.","No extra charges for plus sizes.","Factory > > tolerance on measurement is 1/2 an inch / 1.3 cm's."); > > > $sizeArrayCount = count($sizeArray); > > > $i = 0; > > ?> > > > <table> > > <tr> > > <th>Size</th> > > <th>Bust (in)</th> > > <th>Waist (in)</th> > > <th>Hips (in)</th> > > </tr> > > <?php > > while($sizeArrayCount > $i) > > { > > echo "<tr>"; > > echo "<td>" . $sizeArray[$i] . "</td>"; > > echo "<td>" . $bustArray[$i] . "</td>"; > > echo "<td>" . $waistArray[$i] . "</td>"; > > echo "<td>" . $hipsArray[$i] . "</td>"; > > echo "</tr>"; > > $i++; > > } > > > echo "</table>"; > > > ?> > > > Good Results > > ========== > > 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28 > > (31,32,33,34,35,36.5,38,39.5,41,43,45,47.5,50,53,56) > > Size Bust (in) Waist (in) Hips (in) > > 0 31 31 31 > > 2 32 32 32 > > 4 33 33 33 > > 6 34 34 34 > > 8 35 35 35 > > 10 36.5 36.5 36.5 > > 12 38 38 38 > > 14 39.5 39.5 39.5 > > 16 41 41 41 > > 18 43 43 43 > > 20 45 45 45 > > 22 47.5 47.5 47.5 > > 24 50 50 50 > > 26 53 53 53 > > 28 56 56 56 > > > Crappy Test Code > > ============= > > <?php > > > require_once('model/global.php'); > > > $field = '*'; > > $table = 'sizes'; > > $condition = "WHERE brandID = 'mega-whoppers'"; > > include('model/qrySelect.php'); > > > $row = $result->fetch_array(MYSQLI_NUM); > > printf ("%s (%s)\n", $row[3], $row[4]); > > > //THIS IS WHAT THE KIND OF THING I AM TRYING TO DO AND NEED HELP > > WITH!! > > $sizeArray = array($row[3]); > > //$sizeArray = array(0,2,4,6,8,10,12,14,16,18,20,22,24,26,28); > > $bustArray = array > > (31,32,33,34,35,36.5,38,39.5,41,43,45,47.5,50,53,56); > > $waistArray = array > > (31,32,33,34,35,36.5,38,39.5,41,43,45,47.5,50,53,56); > > $hipsArray = array > > (31,32,33,34,35,36.5,38,39.5,41,43,45,47.5,50,53,56); > > $notesArray = array("Standard gown length is 59 inches / 150 cm's from > > hollow to hem.","Standard bodice length is 14.5 inches / 37 cm's from > > hollow to waist.","Standard sleeve length is 18 inches / 46 cm's from > > underarm to wrist.","No extra charges for plus sizes.","Factory > > tolerance on measurement is 1/2 an inch / 1.3 cm's."); > > > $sizeArrayCount = count($sizeArray); > > > $i = 0; > > ?> > > > <table> > > <tr> > > <th>Size</th> > > <th>Bust (in)</th> > > <th>Waist (in)</th> > > <th>Hips (in)</th> > > </tr> > > <?php > > while($sizeArrayCount > $i) > > { > > echo "<tr>"; > > echo "<td>" . $sizeArray[$i] . "</td>"; > > echo "<td>" . $bustArray[$i] . "</td>"; > > echo "<td>" . $waistArray[$i] . "</td>"; > > echo "<td>" . $hipsArray[$i] . "</td>"; > > echo "</tr>"; > > $i++; > > } > > > echo "</table>"; > > > ?> > > > Crappy Results > > =========== > > 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28 > > (31,32,33,34,35,36.5,38,39.5,41,43,45,47.5,50,53,56) > > Size Bust (in) Waist (in) Hips (in) > > 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28 31 31 31 --~--~---------~--~----~------------~-------~--~----~ NZ PHP Users Group: http://groups.google.com/group/nzphpug To post, send email to [email protected] To unsubscribe, send email to [email protected] -~----------~----~----~----~------~----~------~--~---
