arrays - PHP table output partial output from MSSQL database -
this school project , cannot figure out why, returns 2 columns. picture of database querying is:
.
since screenshot have changed null fields 1, thinking wouldn't print null.
the webpage of project on my project.
before step of building table, did test see array returns, , expected. there blanks null values previous database. thinking have been numbers stopping returning rest of arrays, commands using, iirc(if recall), return strings arrays. might not correct, understanding.
rememeber: nulls in database image linked 1's(int type).
i have not used framework, doing inline coding (for experience). first time using php. have looked @ many other examples, can't seem adapt solutions own problem. appreciated!
edit: forgot print array output testing. (almost same url above, remove main.php , add test.php), forgot mention null fields varchar data typed replaced na instead of 1's have edited image reflect this.
<?php require_once(file there...) // removed example security reasons. // test message echo '<p>connect please...</p>'; try { // connection php mssql via pdo // database host $dbh = new pdo($dsn, $user, $password); //sent/send host , preparing query send. $sth = $dbh->prepare("select * backbar"); //send query! $result = $sth->execute(); // fetch of remaining rows in result set $row = $sth->fetchall(); // used move through array. $subarraypos = 0; // start table format extravaganza! print('<table border="1px">'); print('<tr><th>productcompany</th> <th>productname</th> <th>barcode#</th> <th>color</th> <th>perms</th> <th>cost</th> <th>volume</th> <th>size</th> <th>shelf location</th> <th>shelf cap</th> <th>quantity on hand</th> <th>storage location</th> <th>quantity in storage</th> <th>vendor</th> <th>vendor region</th> <th>vendor mileage</th>'); foreach($row $value) { if($subarraypos === 0) { print('<tr><td>'.$value[$subarraypos].'</td>'); $subarraypos++; } // 16 reset number of columns // database each entry correctly shown. // else of first if(...) (elif) if($subarraypos <=15) { print('<td>'.$value[$subarraypos].'</td>'); $subarraypos++; } // else of second if(...) (else) $subarraypos = 0; print('</tr>'); } print('</table>'); print('<p>'.$row.'</p>'); print('<p>'.$value.'</p>'); } catch (pdoexception $e) { echo 'connection failed: ' . $e->getmessage(); } echo "<p>you should see table, unless broke it.</p>"; unset($dbh); ?>
looks forgot loop on subarray. call subarraypos = 0 , subarraypos = 1, move next row of table.
foreach ($row $value) { print('<tr>') ($subarraypos = 0; $subarraypos < 16; $subarraypos++) { print('<td>' . $value[$subarraypos] . '</td>') } print('</tr>') }
Comments
Post a Comment