php - I am trying to add a dropdown menu box within a table with data fetched from mysql -
i using notepad, xampp , mysql , phpmyadmin create football prediction website. on prediction page have page showing fixture in table. want use able post home_sore
, away_score
each corresponding fixture using series of dropdown menus numbers 1-20.
for example:
fixture_id|home_team|home_score|away_score|away_team| 1 man united <dropdown> <dropdown> spurs
is possible? new php coding , appreciate get!:)
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <?php $connection = mysql_connect('localhost', 'root', 'password'); //the blank string password mysql_select_db('mls'); $query = "select * fixtures"; //you don't need ; in sql $result = mysql_query($query); $columns = array(); $resultset = array(); # set columns , results array while ($row = mysql_fetch_assoc($result)) { if (empty($columns)) { $columns = array_keys($row); } $resultset[] = $row; } # if records found if( count($resultset > 0 )) { ?> <table class="table table-bordered" > <thead> <tr class='info';> <?php foreach ($columns $k => $column_name ) : ?> <th> <?php echo $column_name;?> </th> <?php endforeach; ?> </tr> </thead> <tbody> <?php // output data of each row foreach($resultset $index => $row) { $column_counter =0; ?> <tr class='success';> <?php ($i=0; $i < count($columns); $i++):?> <td> <?php echo $row[$columns[$column_counter++]]; ?> </td> <?php endfor;?> </tr> <?php } ?> </tbody> </table> <?php }else{ ?> <h4> echo information not available </h4> <?php } ?> </body> </html>
you can including in td
tag
<select name="myselect"> <?php $result= mysql_query('select * fixtures'); ?> <?php while($row= mysql_fetch_assoc($result)) { ?> <option value="<?php echo $row['your_column_name'];?>"> <?php echo $row['your_column_name']; ?> </option> <?php } ?> </select>
Comments
Post a Comment