php - Cant Output MySQL Table via Web Form -



php - Cant Output MySQL Table via Web Form -

i totally new php , trying write simple web form keeps track of inventory , borrowed it. have lamp setup on ubuntu 13.10 w/php 5.5. had no problem writing script takes client info , writes mysql db stuck on getting script outputs it. looking @ examples , reading have far:

<?php ini_set("display_errors","on"); $dsn='mysql:host=localhost;dbname=inventory_form'; $username="****"; $password="*****"; $database="inventory_form"; seek { $link=new pdo($dsn, $username,$password); echo 'connection established'; } grab (pdoexception $e) { $error_message=$e->getmessage(); echo "<h1>an error occurred: $error_message</h1>"; } $query="select * inventory"; $result=$link->query($query); /*/ $num=mysql_num_rows($result); echo "<b><center>database output</center></b>"; ?> <table border="2" cellspacing="2" cellpadding="2"> <tr> <th><font face="arial, helvetica, sans-serif">name</font></th> <th><font face="arial, helvetica, sans-serif">equipment borrowed</font></th> <th><font face="arial, helvetica, sans-serif">service tag</font></th> <th><font face="arial, helvetica, sans-serif">date borrowed</font></th> </tr> <?php $i=0; while ($i < $num) { $first=mysql_result($result,$i,"fname"); $last=mysql_result($result,$i,"lname"); $eq_brwd=mysql_result($result,$i,"eqpmnt_brwd"); $svc_tag=mysql_result($result,$i,"service_tag"); $date_bwd=mysql_result($result,$i,"date_taken"); ?> <tr> <td><font face="arial, helvetica, sans-serif"><?php echo "$first $last"; ?></font></td> <td><font face="arial, helvetica, sans-serif"><?php echo "$eq_brwd"; ?></font></td> <td><font face="arial, helvetica, sans-serif"><?php echo "$svc_tag"; ?></font></td> <td><font face="arial, helvetica, sans-serif"><?php echo "$date_bwd"; ?></font></td> </tr> <?php ++$i; } echo "</table>"; ?>

all connection established message. 1 problem know $num variable not getting value returned my_sql_num_rows.i know there must simpler way output table info. suggestions or improve way welcome.

reply: keeping simple. have this:

<?php ini_set("display_errors","on"); $dsn='mysql:host=localhost;dbname=inventory_form'; $username="alank"; $password="alank"; $database="inventory_form"; seek { $link=new pdo($dsn, $username,$password); echo 'connection established'; } grab (pdoexception $e) { $error_message=$e->getmessage(); echo "<h1>an error occurred: $error_message</h1>"; } $query="select * inventory"; $result=$link->query($query); echo "<b><center>database output</center></b>"; ?> <table border="2" cellspacing="2" cellpadding="2"> <tr> <th><font face="arial, helvetica, sans-serif">name</font></th> <th><font face="arial, helvetica, sans-serif">equipment borrowed</font></th> <th><font face="arial, helvetica, sans-serif">service tag</font></th> <th><font face="arial, helvetica, sans-serif">date borrowed</font></th> </tr> <?php while ($row = $result->fetch()) { echo '$row'; } ?>

but still no good. output is: connection established database output $row$row$row$row$row$row$row name equipment borrowed service tag date borrowed

any advise. sorry many questions. that's how learn. appreciate patience.

$query="select * inventory"; $result=$link->query($query); while ($row = $result->fetch()) { var_dump($row); }

you see how pdo works.

pdo functions , mysql_* functions belongs 2 different extensions. mixed them up.

php table output

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -