PHP - Printing Data From A Database Into Html Table
Hello everyone,
i'm Osiris and i'm stuck with this PHP/HTML code, i'm fairly new at this so this might be a dumb question.
i have a database, but i want to output all data into a table from the database using HTML codes.
i had it so far that i could outpust the info in just plain text but it doesn't output in the HTML table.
Can anyone see what i did wrong?
This is my PHP code its in the body section
<?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'password'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } $sql = 'SELECT `Name`, `Color`, `Type`, `Subtype`, `Power`, `Toughness`, `Manacost`, `Rarity`, `Expansion`, `Foil`, `Stock` FROM `mtgtabel`'; mysql_select_db('mtgstock'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not get data: ' . mysql_error()); } echo '<table class=mytable>'; echo "<tr><th >Name</th><th >Color</th><th >Type</th><th >Sub Type</th><th >Power</th><th >Toughness</th><th >Converted mana cost</th><th >Rarity</th><th >Expansion</th><th >Foil</th><th >Stock</th></tr>"; while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) { echo "<tr><td>"; echo $row['Name'] echo "</td><td>"; echo $row['Color']; echo "</td><td>"; echo $row['Type']; echo "</td><td>"; echo $row['Subtype']; echo "</td><td>"; echo $row['Power']; echo "</td><td>"; echo $row['Toughness']; echo "</td><td>"; echo $row['Manacost']; echo "</td><td>"; echo $row['Rarity']; echo "</td><td>"; echo $row['Expansion']; echo "</td><td>"; echo $row['Foil']; echo "</td><td>"; echo $row['Stock']; echo "</td></tr>"; } echo "</table>"; mysql_close($conn); ?>Thanks in advance! Similar TutorialsHello to all, I have problem figuring out how to properly display data fetched from MySQL database in a HTML table. In the below example I am using two while loops, where the second one is nested inside first one, that check two different expressions fetching data from tables found in a MySQL database. The second expression compares the two tables IDs and after their match it displays the email of the account holder in each column in the HTML table. The main problem is that the 'email' row is displayed properly while its while expression is not nested and alone(meaning the other data is omitted or commented out), but either nested or neighbored to the first while loop, it is displayed horizontally and the other data ('validity', 'valid_from', 'valid_to') is not displayed.'
Can someone help me on this, I guess the problem lies in the while loop? <thead> <tr> <th data-column-id="id" data-type="numeric">ID</th> <th data-column-id="email">Subscriber's Email</th> <th data-column-id="validity">Validity</th> <th data-column-id="valid_from">Valid From</th> <th data-column-id="valid_to">Valid To</th> </tr> </thead> Here is part of the PHP code:
<?php while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo ' <tr> <td>'.$row["id"].'</td> '; while ($row1 = $stmt1->fetch(PDO::FETCH_ASSOC)) { echo ' <td>'.$row1["email"].'</td> '; } if($row["validity"] == 1) { echo '<td>'.$row["validity"].' month</td>'; }else{ echo '<td>'.$row["validity"].' months</td>'; } echo ' <td>'.$row["valid_from"].'</td> <td>'.$row["valid_to"].'</td> </tr>'; } ?>
Thank you. the second database found on the cloud
i try to get JSON data but how to insert and update them to another online database with the same table my php script to return json data <?php include_once('db.php'); $users = array(); $users_data = $db -> prepare('SELECT id, username FROM users'); $users_data -> execute(); while($fetched = $users_data->fetch()) { $users[$fetchedt['id']] = array ( 'id' => $fetched['id'], 'username' => $fetched['name'] ); } echo json_encode($leaders);
i get
{"1":{"id":1,"username":"jeremia"},"2":{"id":2,"username":"Ernest"}} Edited March 24 by mahenda I want to print in an html table the Seasons,the Months,and the days of each month. the following code prints the seasons and the days i need another foreach in between that prints the months also Any ideas??? Please help... $seasons=array ( "Fall"=> array ("September"=>"30","October"=>"31","November"=>"30"), "Winter"=> array ("December"=>"31","January"=>"31","February"=>"28"), "Spring"=> array ("March"=>"31","April"=>"30","May"=>"31"), "Summer"=> array ("June"=>"30","July"=>"31","August"=>"31") ); $tab = "<table border=\"1\">"; foreach($seasons as $season => $months) { $tab .= "<tr><td colspan=\"4\">$season</td></tr>" ; $tab .= "<tr>" ; foreach($seasons[$season] as $days) { $tab .= "<td>$days</td>" ; } $tab .= "</tr>" ; } $tab .= "</table>" ; echo $tab ; how i want to display data from database to look like this : <table width="633" height="224" border="1"> <tr bgcolor="#999900"> <td width="45">Bil</td> <td width="121">Course_name</td> <td width="83">session</td> <td width="83">start_date</td> <td width="83">end_date</td> <td width="83">notes</td> <td width="89">pre-req</td> </tr> <tr bgcolor="#6A7AEA"> <td rowspan="2">1.</td> <td rowspan="2" bgcolor="#6A7AEA">Math</td> <td>1st session </td> <td>1 jan 11 </td> <td>6 jan 11 </td> <td rowspan="2"> </td> <td rowspan="2"><image icon that will link to the oter site> </td> </tr> <tr> <td bgcolor="#6A7AEA">2nd session </td> <td bgcolor="#6A7AEA">8 jan 11 </td> <td bgcolor="#6A7AEA">15 jan 11 </td> </tr> <tr> <td bgcolor="#0066CC">2.</td> <td bgcolor="#0066CC">English</td> <td bgcolor="#0066CC">1st session </td> <td bgcolor="#0066CC">1 feb 11 </td> <td bgcolor="#0066CC">6 feb 11 </td> <td bgcolor="#0066CC"> </td> <td bgcolor="#0066CC"><image icon that will link to the oter site></td> </tr> <tr> <td rowspan="2" bgcolor="#6A7AEA">3.</td> <td rowspan="2" bgcolor="#6A7AEA">Science</td> <td height="29" bgcolor="#6A7AEA">1st session </td> <td bgcolor="#6A7AEA">8 march 11 </td> <td bgcolor="#6A7AEA">15 march 11 </td> <td rowspan="2" bgcolor="#6A7AEA"> </td> <td rowspan="2" bgcolor="#6A7AEA"><image icon that will link to the oter site></td> </tr> <tr> <td bgcolor="#6A7AEA">2nd session</td> <td bgcolor="#6A7AEA">16 march 11 </td> <td bgcolor="#6A7AEA">21 march 11 </td> </tr> </table> ** all the view data is called from database including the icon image thanks... hi everyone, i just signed up on this forum. I have issue, my clients wants to save time by copying data into a textarea and then letting the script process it and store it in database. the problem is never done that. the data is made up for eg. Title Mr Name Radio86 Address Chiltren House etc.... how do i split this data up and store it in database, btw ive just started programming in php in other words newbie Please help me, thanks in advance Lets say I have this database: table brand [brandID] [brandName] where brandID -> auto increment and one brand always has the same brandID table product [brandID] [productID] [price] where productID -> auto increment I want to insert new product into the database using only values [brandName] and [price] and want brandID and productID to be created automatically I use this form: <form id="insertingDataToBrand" action="administratorCode.php" method="post"> <div>Brand Name: <input type="text" name="brandName"/></div> <div>Price: <input type="text" name="price"/></div> </form> And here is the php code: <?php //connection to database include 'connectToDatabase.php'; //data retrieveing $brand = $_POST['brandName']; $price = $_POST['price']; //As I am inserting to two different tables I use two INSERT statements $sql = "INSERT INTO brand (brandName) values ('$brand')"; mysql_query($sql) or die (mysql_error()); //as brandID is created automatically I am going to insert the same value to another table $last_id = mysql_insert_id (); $sql = "INSERT INTO product (price, brandID) values ('$price', '$last_id')"; ?> This should work just fine (it doesnt tho) BUT my question is: I have 3 different brands (brand A with brandID 1, brand B with brandID 2, brand C with brandID 3). When want to insert brand D, automatically created brandID should be automatically set to 4. BUT when I want to insert product of the same brand, lets say brand A (with different productID) brandID is automatically set to 4(or higher) as well. What do I have to do(use) so it would be able to realise what brandID should be added? Thanks a lot. Hello Im quite confused at what filtering I should use on my data when pulling it from a MySQL database. I don't sanitize my data on input because I am using prepared statements with PHP's PDO Driver which means I don't need to use mysql_real_escape_string() at all. When I pull the data to be displayed i.e. in a HTML Table I use the below function to make it safe for HTML output. public static function htmlSafe($data) { return nl2br(htmlentities($data, ENT_QUOTES)); } However the rules change when Im using a HTML Form to edit the data, and I am unsure what I need to strip out. I.e. What would I need to do to make all data safe to insert into the following form input. <input id = "someInput" type = "text" value = "<?php echo $someVarThatNeedsFiltering ?>" /> Also, one more question, in my html attributes (Valid ones like class, name, id, style, _target) I use a mixture of double quotes(") and single quotes ('), for quoting my values. Which one should I use or which one is more valid, doubles, or singles? i have 8 division (div), i want to display 4 rows in 4 division and the remain 4 rows in the next 4 division here is my code structure for carousel
<div class="nyie-outer"> second row third row
fourth row fifth row sixth row seven throw eighth row
</div><!--/.second four rows here-->
sql code
CREATE TABLE product( php code
<?php how can i echo that result in those rows
I have a form that is submitting to a database currently. I would like to check the data and be able to update it with a notes section. The form is currently 80 text boxes, dropdowns, and text areas being submitted to the database. I need this info to populate after the user id is entered and a button is pressed. I will have to update this page frequently with notes. I am going to create a new table just for the notes and will attach the customer id to it also. If you can help me out with this i would appricate it. I can post my current code or an example of the code. Hi all, I'm new to php/myslq and I'm going crazy trying to figure this one out I'm building a personal calendar and I want to display the data into a HTML table. Code: [Select] //query the database $query = "SELECT * FROM tbl_events WHERE event_day=$day AND event_month=$month AND event_year=$year"; $query = mysql_query($query); //build the table echo '<table>'; for ($y = 0; $y < 6; $y++){ echo '<tr><td>'; //insert the data here echo '</td></tr>'; } echo '</table>'; When I store the events into the database, I assign a slot for each one depending on the hour. I don't want to use more than 6 events daily, hence the for loop. The problem I have is how to I insert the data into the designed <td>? In a particular day I could have only 2 events: event 1 - slot 2, event 2 - slot 6. I want to be able to enter each event into its own cell I hope I'm making myself clear enough. Sorry for any English mistakes if any. Thank you Hello I have 2 database tables: 1) products which contain 3 columns: id, description and unit 2) units which contains 2 columns: id and description I need to pupulate html table with data from 2 database tables.this is the structu id, description, unit, unit_description (the first 3 columns come from table 1 and the fourth column from table 2 I know hot to pupulate the table according to the 3 columns: (the remarks are for the 4th column that i dont know how to call). I want this column to get the description of the unit in the row from the second table in the database - using the get_unit_desc in the GlDbOra.php file (Not by making a join in the select) How can I do that? I'll be happy for any help index.php <?php require_once("../xxx/Includes/GlDbOra.php"); $cursor=''; $cursor=DBOracle::getInstance()->get_products(); ?> <html> <head> <meta charset="UTF-8"> <title>Products</title> <script type="text/javascript" src="../../Bundles/php-ajax/jquery-3.5.1.js"></script> <script src="../Bundles/bootstrap-4.5.0-dist/js/bootstrap.min.js"></script> <link href="../Bundles/bootstrap-4.5.0-dist/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <link href="../xxx/css/global_style.css" type="text/css" rel="stylesheet" madia="all"/> </head> <body> <div class="container"> <div class="row"> <div class="panel panel-primary filterable"> <div class="panel-heading"> <h3 class="panel-title">Products</h3> <div class="pull-right"> <button class="btn btn-default btn-xs btn-filter"><span class="glyphicon glyphicon-filter"></span> Filter</button> </div> </div> <form id="data_form" name="datatable_form" method="POST"> <div class="table-repsonsive"> <table class="table table-bordered" id="tab_logic"> <thead> <tr class="filters" id="table_header_2_btn"> <th width="12%"><input type="text" class="form-control" name="Id[]" value="" placeholder="Id" disabled /></th> <th width="30%"><input type="text" class="form-control" name="DESCRIPTION[]" value="" placeholder="Description" disabled /></th> <th width="12%"><input type="text" class="form-control" name="UNIT[]" value="" placeholder="Unit" disabled /></th> <!-- <th width="30%"><input type="text" class="form-control" name="UNIT_DESCRIPTION[]" value="" placeholder="Description" disabled /></th> --> <th width="12%"></th> </tr> </thead> <tbody> <?php foreach ($cursor as $cursorCurrentRow) { echo '<tr class="form-group">'; echo "<td width=".'"12%"><input type="text" name="ID[]" value="'.htmlspecialchars($cursorCurrentRow['ID'], ENT_QUOTES).'" disabled style="border:none;"></td>'; echo "<td width=".'"30%"><input type="text" name="DESCRIPTION[]" value="'.htmlspecialchars($cursorCurrentRow['DESCRIPTION'], ENT_QUOTES).'" disabled style="border:none;"></td>'; echo "<td width=".'"12%"><input type="text" name="UNIT[]" value="'.htmlspecialchars($cursorCurrentRow['UNIT'], ENT_QUOTES).'" disabled style="border:none;"></td>'; // echo "<td width=".'"30%"><input type="text" name="UNIT_DESCRIPTION[]" value="'.htmlspecialchars($cursorCurrentRow['DESCRIPTION'], ENT_QUOTES).'" disabled style="border:none;"></td>'; echo "<td width=".'"12%">' . '<a class='.'"add" title='.'"Add" data-toggle='.'"tooltip"><i class='.'"material-icons"></i></a>' . '<a class='.'"edit" title='.'"Edit" data-toggle='.'"tooltip"><i class='.'"material-icons"></i></a>' . '<a class='.'"delete" title='.'"Delete" data-toggle='.'"tooltip"><i class='.'"material-icons"></i></a>' . '</td>'; echo "</tr>\n"; } ?> </tbody> </table> </div> </form> </div> <button class="regular_button" id="add-new"><span class="glyphicon glyphicon-plus"></span> Add Rows</button> <button class="regular_button" id="save_rows"><span class="glyphicon glyphicon-floppy-save"></span> Save</button> </div> </div> </body> </html> GlDbOra.php <?php class DBOracle { private static $instance = null; public static function getInstance() { if (!self::$instance instanceof self) { self::$instance = new self; } return self::$instance; } public function __clone() { trigger_error('Clone is not allowed.', E_USER_ERROR); } public function __wakeup() { trigger_error('Deserializing is not allowed.', E_USER_ERROR); } public function __construct () { $databaseConfig = include 'config.php'; $OracleUser=$databaseConfig['Oracle_User']; $OraclePwd=$databaseConfig['Oracle_Pwd']; $OracleDB=$databaseConfig['Oracle_DB']; $this -> OracleUser = $OracleUser; $this -> OraclePwd = $OraclePwd; $this -> OracleDB = $OracleDB; $this->con = oci_connect($this->OracleUser, $this->OraclePwd, $this->OracleDB); if (!$this->con) { $e = oci_error(); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); exit; } } public function get_products() { $cursor=''; $query = "begin get_products(:cursor); end;"; $stid = oci_parse($this->con, $query); $p_cursor = oci_new_cursor($this->con); oci_bind_by_name($stid, ':cursor', $p_cursor, -1, OCI_B_CURSOR); oci_execute($stid); oci_execute($p_cursor, OCI_DEFAULT); oci_fetch_all($p_cursor, $cursor, null, null, OCI_FETCHSTATEMENT_BY_ROW); oci_free_statement($stid); oci_close($this->con); return $cursor; } public function get_unit_desc($unitid) { $unit_desc=''; $query = "begin :unit_desc_bv := get_unit_desc(:id_bv); end;"; $stid = oci_parse($this->con, $query); oci_bind_by_name($stid, ':id_bv', $unitid); oci_bind_by_name($stid, ':unit_desc_bv', $unit_desc,30); oci_execute($stid); oci_free_statement($stid); oci_close($this->con); return $unit_desc; } } ?>
Hello I have an array with data from `mysql` that I would like to output it in a table using twig. The image is an example of want i want to achieve but without any luck. `print_r` of the array data Array ( [Administrator] => Array ( [0] => Array ( [RoleName] => Administrator [PermissionName] => Catalog-View [PermissionId] => 1 ) [1] => Array ( [RoleName] => Administrator [PermissionName] => Catalog-Edit [PermissionId] => 2 ) [2] => Array ( [RoleName] => Administrator [PermissionName] => Catalog-Delete [PermissionId] => 3 ) ) [Moderator] => Array ( [0] => Array ( [RoleName] => Moderator [PermissionName] => Catalog-View [PermissionId] => 1 ) ) ) The `HTML` code: <table> <tr> <thead> <th>Controller - Action</th> {% for permission in permissions %} {% for item in permission %} <th>{{item.RoleName}}</th> {% endfor %} {% endfor %} </thead> </tr> {% for permission in permissions %} {% for item in permission %} <tr> <td>{{item.PermissionName}}</td> <td>{{item.PermissionId}}</td> </tr> {% endfor %} {% endfor %} </table> OUTPUT: <table> <tbody> <tr></tr> </tbody> <thead> <tr> <th>Controller - Action</th> <th>Administrator</th> <th>Administrator</th> <th>Administrator</th> <th>Moderator</th> </tr> </thead> <tbody> <tr> <td>Catalog-View</td> <td>1</td> </tr> <tr> <td>Catalog-Edit</td> <td>2</td> </tr> <tr> <td>Catalog-Delete</td> <td>3</td> </tr> <tr> <td>Catalog-View</td> <td>1</td> </tr> </tbody> </table> Later Edit MySQL Query: SELECT t3.PermissionName, t1.PermissionId, t2.RoleName FROM tbl_user_role_perm AS t1 INNER JOIN tbl_user_roles AS t2 ON t1.RoleId = t2.RoleId INNER JOIN tbl_user_permissions AS t3 ON t1.PermissionId = t3.PermissionId MySQL Dump: -- Dumping structure for table tbl_user_permissions CREATE TABLE IF NOT EXISTS `tbl_user_permissions` ( `PermissionId` int(11) NOT NULL AUTO_INCREMENT, `PermissionName` varchar(50) NOT NULL, `PermissionDescription` varchar(100) NOT NULL, PRIMARY KEY (`PermissionId`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1; -- Dumping data for table tbl_user_permissions: ~2 rows (approximately) DELETE FROM `tbl_user_permissions`; /*!40000 ALTER TABLE `tbl_user_permissions` DISABLE KEYS */; INSERT INTO `tbl_user_permissions` (`PermissionId`, `PermissionName`, `PermissionDescription`) VALUES (1, 'Catalog->View', 'View Catalog Method'), (2, 'Catalog->Edit', 'Edit Catalog Method'), (3, 'Catalog->Delete', 'Delete Catalog Method'); /*!40000 ALTER TABLE `tbl_user_permissions` ENABLE KEYS */; -- Dumping structure for table tbl_user_role CREATE TABLE IF NOT EXISTS `tbl_user_role` ( `UserRoleId` int(10) NOT NULL AUTO_INCREMENT, `UserId` int(10) NOT NULL, `RoleId` int(10) unsigned NOT NULL, PRIMARY KEY (`UserRoleId`), KEY `FK_tbl_user_role_tbl_user_roles` (`RoleId`), KEY `UserId` (`UserId`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1; -- Dumping data for table tbl_user_role: ~2 rows (approximately) DELETE FROM `tbl_user_role`; /*!40000 ALTER TABLE `tbl_user_role` DISABLE KEYS */; INSERT INTO `tbl_user_role` (`UserRoleId`, `UserId`, `RoleId`) VALUES (1, 13, 22), (2, 14, 22); /*!40000 ALTER TABLE `tbl_user_role` ENABLE KEYS */; -- Dumping structure for table tbl_user_roles CREATE TABLE IF NOT EXISTS `tbl_user_roles` ( `RoleId` int(10) unsigned NOT NULL AUTO_INCREMENT, `RoleName` varchar(50) NOT NULL, `CreatedDate` datetime NOT NULL, `ModifiedDate` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`RoleId`) ) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8; -- Dumping data for table tbl_user_roles: ~7 rows (approximately) DELETE FROM `tbl_user_roles`; /*!40000 ALTER TABLE `tbl_user_roles` DISABLE KEYS */; INSERT INTO `tbl_user_roles` (`RoleId`, `RoleName`, `CreatedDate`, `ModifiedDate`) VALUES (22, 'Administrator', '2014-10-28 09:53:08', NULL), (23, 'Moderator', '2014-10-28 09:53:13', NULL), (24, 'Admin', '2014-10-28 12:22:05', '2014-10-28 12:22:06'), (25, 'User', '2014-10-29 15:10:36', '2014-10-29 15:10:37'), (26, 'SuperUser', '2014-10-29 15:10:45', '2014-10-29 15:10:46'), (27, 'Accountant', '2014-10-29 15:10:53', '2014-10-29 15:10:54'), (28, 'God', '2014-10-29 15:11:02', '2014-10-29 15:11:02'); /*!40000 ALTER TABLE `tbl_user_roles` ENABLE KEYS */; -- Dumping structure for table tbl_user_role_perm CREATE TABLE IF NOT EXISTS `tbl_user_role_perm` ( `RoleId` int(10) unsigned NOT NULL, `PermissionId` int(10) unsigned NOT NULL, KEY `RoleId` (`RoleId`), KEY `PermissionId` (`PermissionId`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- Dumping data for table tbl_user_role_perm: ~3 rows (approximately) DELETE FROM `tbl_user_role_perm`; /*!40000 ALTER TABLE `tbl_user_role_perm` DISABLE KEYS */; INSERT INTO `tbl_user_role_perm` (`RoleId`, `PermissionId`) VALUES (22, 2), (22, 1), (23, 1), (22, 3); /*!40000 ALTER TABLE `tbl_user_role_perm` ENABLE KEYS */; /*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */; /*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;Can you help me to make the coding required so that the correct column have the correct permissions? thank you in advance. Not really sure how to get the images I have stored in MySQL into a html form. I can call-up the text fields from the database but it cannot seem to find the index for the images. Here is my code:- <?php session_start(); mysql_connect("localhost","root","abc") or die ("Error! Cannot connect to database"); mysql_select_db("theimageworks") or die ("Cannot find database"); $query = "SELECT * FROM jobs"; $result = mysql_query($query) or die (mysql_error()); ?> <?php //display data in html table echo "<table>"; echo "<tr><td>Username</td><td align='center'>Message</td><td>Product Image</td></tr>"; while($row = mysql_fetch_array($result)) { echo "</td><td>"; echo $row['username']; echo "</td><td>"; echo $row['message']; echo "</td></tr>"; echo $row['image']; } echo "</table>"; ?> The error message I get is "Notice: Undefined index: image in....." Thanks in advance! http://www.sambob.info/phpfreaks/table.htm the above link is an example of an html table i am trying to pull data out of i need help on starting a code the will pull that first and last name out of that table so in this case i need it to pull out John doe does any one have any idea on how to do this thank you for your help Bob
Hello, I have the problem that only one user is displayed in the table require('connection/db1.php'); // Teilnehmerliste $query = 'SELECT * FROM convoy_part WHERE user_convoy= :I'; $start = $bdd->prepare($query); $start->execute(array(':I' => $_GET['id'])); //fetch $result2 = $start->fetch(); // Zählung der Datensätze $count = $start->rowCount(); <table class="table"> <thead> <tr> <th scope="col">User</th> <th scope="col">Datum</th> <th scope="col"><a class="btn btn-primary" href="convoy_user.php?id=<?php echo $result['id']; ?>&action=part" role="button">Teilnehmen</a></th> </tr> </thead> <tbody> <tr> <th scope="row"><?php echo $result2['name']; ?></th> <td><?php echo $result2['date']; ?></td> </tr> </tbody> </table>
I'm creating a report page and can't figure out how to retrieve multiple rows from a table and display them in html. There are 5 data elements in each row and I'm thinking that using a form in the html might be the best way as I'm totally ignorant about tables in html. I'm a newbie to php and can't figure out how to accomplish this. Here's the code that I have so far: <?php $filename = NULL; session_start(); // start of script every time. // setup a path for all of your canned php scripts $php_scripts = '../php/'; // a folder above the web accessible tree // load the pdo connection module require $php_scripts . 'PDO_Connection_Select.php'; //******************************* // Begin the script here // Connect to the database if (!$con = PDOConnect("foxclone")): { echo "Failed to connect to database" ; exit; } else: { $sql = 'SELECT COUNT(IP_ADDRESS) FROM download WHERE FILENAME IS NOT NULL'; $sql1 = 'Update download t2, ip_lookup t1 set t2.country = t1.country, t2.area = t1.area, t2.city = t1.city where ((t2.IP_ADDRESS) = (t1.start_ip) OR (t2.IP_ADDRESS) > (t1.start_ip)) AND ((t2.IP_ADDRESS) = (t1.end_ip) OR (t2.IP_ADDRESS) < (t1.end_ip)) AND (t2.FILENAME is not null and t2.country is null)'; $sql2 = 'SELECT (IP_ADDRESS, FILENAME, country, area, city) from download where FILENAME is not null'; // Update the table $stmt = $con->prepare($sql1); $stmt->execute(); // Get count of rows to be displayed in table $stmt = $con->prepare($sql); $stmt->execute() ; $cnt = $stmt->fetch(PDO::FETCH_NUM); // retrieve one row at a time $i = 1; while($i <= $cnt){ $stmt = $con->prepare($sql2); $row->execute(array('')); // Do I need an array here? // from here on, I'm lost $i++; I'd appreciate any guidance you can provide or understandable tutorials you can point me to. Larry Hi, Hope somebody can help me because I am relatively new to PHP and I am currently unsure how to implement the following: Let's assume I have a table like this id_number, name, data1, data2. When displayed on HTML page: Column id_number should be hidden. Column name is a link. When you click on this column then value stored in id_number should be used in a query to database. Result should be displayed below the link on the same page. When clicked again data should hide. I have some idea how to toggle visibility with a simple javascript function. How do i populate the table with hidden data and then extract it later on? Any help or suggestions are appreciated. Thanks. Hi, I'm trying to make a dynamic html table to contain the mysql data that is generated via php. I'm trying to display a user's friends in a table of two columns and however many rows, but can't seem to figure out what is needed to make this work. Here's my code as it stands: Code: [Select] <?php //Begin mysql query $sql = "SELECT * FROM friends WHERE username = '{$_GET['username']}' AND status = 'Active' ORDER BY friends_with ASC"; $result = mysql_query($sql); $count = mysql_num_rows($result); $sql_2 = "SELECT * FROM friends WHERE friends_with = '{$_GET['username']}' AND status = 'Active' ORDER BY username ASC"; $result_2 = mysql_query($sql_2); $count_2 = mysql_num_rows($result_2); while ($row = mysql_fetch_array($result)) { echo $row["friendswith"] . "<br>"; } while ($row_2 = mysql_fetch_array($result_2)) { echo $row_2["username"] . "<br>"; } ?> The above simply outputs all records of a user's friends (their usernames) in alphabetical order. The question of how I'd generate a new row each time a certain amount of columns have been met, however, is beyond me. Anyone know of any helpful resources that may solve my problem? Thanks in advance =) I've got a database file from sqlite, there is a multidimensional array in it with 10 metals. I just want two print out each element in a table It won't get all the separate data inside a HEREDOC foreach ($product_prices as $metal => $prices) "<tr><td>$metal</td><td align = 'right'>". round($prices[wire][28]*$l_conv*$w_conv,4). "<tr><td>$metal</td><td align = 'right'>". round($prices[wire][36]*$l_conv*$w_conv,4). "<tr><td>$metal</td><td align = 'right'>". round($prices[wire][45]*$l_conv*$w_conv,4). "<tr><td>$metal</td><td align = 'right'>". round($prices[dust][100]*$l_conv*$w_conv,4). "<tr><td>$metal</td><td align = 'right'>". round($prices[dust][10]*$l_conv*$w_conv,4). "<tr><td>$metal</td><td align = 'right'>". round($prices[dust][1]*$l_conv*$w_conv,4). "</td></tr>"; The following generic code prints out a given table in my database, by first getting the fieldnames and putting them as the title of each column, and then getting the values. How do I change it so that if the name of the field is "password", the value will echo "----" instead of the password? $sql = "SELECT * FROM $tablename"; $result = mysql_query($sql) or die("Query failed : " . mysql_error()); $row = 1; ?> <table width="90%" border="1"><?php //the MYSQL_ASSOC gets field names instead of numbers while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($row == 1) { ?><tr><?php foreach ($line as $col_key => $col_value) { ?><th><?php echo $col_key;?></th><?php } ?></tr><?php } ?><tr><?php foreach ($line as $col_value) { ?><td><?php echo $col_value;?></td><?php } ?></tr><?php $row++; |