PHP - Problem With Html Table
First the code:
Code: [Select] <?php $columns = 4; $num_results = mysql_num_rows($result); $col_rows = intval($num_results / $columns); $count = 1; ?> <table cellspacing="2" class="tabela"> <tr> <td> <?php while ($row = mysql_fetch_array($result)) { $count = $count++; $title = $row["Rim"]; $model = $row["model"]; $dimenzija = $row["Dimenzija"]; $ime = $row['name']; echo "$model<br>$dimenzija<br>$ime" ; if ($count == $col_rows) { echo "</td>\n"; echo "<td>\n"; $count = 1; }} ?> </td> </tr> </table> (table is 100% width and td is 25%) Problem with this is that td will go in linear like structure. I want it after 4 td's to go into new row (something like <br> tag). How to do this? Also when their is one result, td is 100% width (it stretch across hole screen). How to define it to be 25% at all time? Similar TutorialsHello I've registered here last March and I'm just lurking around reading threads about php. Yesterday I've started to self studied php and today I've test some basic codes and I'm having difficulties on creating a table rows and columns. Here's my code. Code: [Select] <?php echo "<table width=\"100\" border=\"1\">"; $text = 'php'; $mac_var = 1; $mac_plus = 4; while ($mac_var < $mac_plus) { echo "<tr>"; { while ($mac_var < $mac_plus) { echo "<td>". $text . "</td>"; $mac_var++; } } echo "</tr>"; $mac_var++; } echo "</table>"; ?> what I want is, it should have 3 columns and 3 rows. But I'm getting only 3 columns and 1 row only. I wonder what is the problem? Sorry for my ignorance as I'm on the 1st basic phase of using php codes. TIA!
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 not sure if my problem is with the PHP, MySQL, HTML, or all of the above, but I've used a tutorial from ScriptPlayground (http://scriptplayground.com/tutorials/php/Printing-a-MySQL-table-to-a-dynamic-HTML-table-with-PHP/) to print a table to HTML. My problem isn't that I couldn't get it to work, as you can see from my site, http://dollapal.com/offerlist.php I've used the code on my site, trying to display a list of offers, with links to each, but I actually have two questions: Is there a way to EXCLUDE columns of the table? I would rather not show the 'id' or 'points' columns, since they don't offer any worth to the user. I would also need to hopefully add a dollar sign before the 'pay' quantities if possible. I would also like use the 'title' field as a hyperlink to the URL listed in the 'URL' field, instead of simply printing the URL. Are there any simple ways to do this and not have it look terrible? I have included a copy of the script that I'm working with so far. Thank you in advance! Hello, I need some help. Say that I have a list in my MySQL database that contains elements "A", "S", "C", "D" etc... Now, I want to generate an html table where these elements should be distributed in a random and unique way while leaving some entries of the table empty, see the picture below. But, I have no clue how to do this... Any hints? Thanks in advance, Vero I know I'm doing it something right, but can someone tell me why only one table is showing up? Can you help me fix the issue? Heres my code: function showcoords() { echo"J3st3r's CoordVision"; $result=dbquery("SELECT alliance, region, coordx, coordy FROM ".DB_COORDFUSION.""); dbarray($result); $fields_num = mysql_num_fields($result); echo "<table border='1'>"; // printing table headers echo "<td>Alliance</td>"; echo "<td>Region</td>"; echo "<td>Coord</td>"; // printing table rows while($row = mysql_fetch_array($result)) { // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row AS $Cell) echo "<tr>"; echo "<td>".$row['alliance']."</td>\n"; echo "<td>".$row['region']."</td>\n"; echo "<td>".$row['coordx'].",".$row['coordy']."</td>\n"; echo "</tr>\n"; } echo "</table>"; mysql_free_result($result); } I have 2 rows inserted into my coords table. Just frustrated and ignorant to php. hi... i have a table ... i add and remove data in the table...when i add new record , information add to center of the table ! whats problem? i want add data in first of table. please guide me.thanks
Hello all is there any way to save a dynamic table to xls file as is? i mean the colors and all the style i use for the table. is there any function that do this? i found PHPExcel.... but i dont have the time or the power to start learn all the functions.... any simple class that do so? Hi, Have taken a look around and cannot find an answer to this one. I have the following page producing an HTML table http://www.weatherweb.net/weathertest.php I'd like the table to export (automatically) as a csv file. Is this possible, and if so how? With thanks, Simon I have a table with x ammount of rows and x ammount of columns, in each TD there is an input box which the user fills in, when they press save the information is input into the database in this form at 6,1,2,3,4,5,6,A,1,2,3,4,5,6,B,1,2,3,4,5,6 - the first number is the number of columns, 1- 6 is the top line of TDs (column headers) and then A 1-6 is row 1, B 1-6 is row 2 etc.. so i then out put the information into a table via a for loop : Code: [Select] while($row = mysql_fetch_array($r)) { $data = explode(',',$row["content_bottom"]); $datacount = count($data); echo"<table border='1'><tr><td>Tool Type</td>"; $k = 1; for ($i = 1; $i <= $datacount; $i++) { if($data[$i] !=""){ echo "<td>".$data[$i]."</td>"; if($k == $data[0]-1) { echo"</tr><tr>"; $k = -1; } $k++; } } echo"</table>"; I can see how i would delete a row of information, eg delete B 1-6, but any ideas how I could delete a column? or is there a better way of storing this information? Afternoon Freaks, I'm trying to display the results of a MySQL query in an HTML table, unsuccessfully. The query returns six rows, but my HTML table only returns one (besides the header row). Here's the code: Code: [Select] </head> <table border="1"> <tr> <th>Fuel type</th> <th>Number of units</th> <th>Output</th> <th>Capability factor</th> <th>Pollution, in tons<sub>2</sub> emitted</th> </tr> <?php $db_hostname = "localhost"; $db_name = "dbname"; $db_username = "joeblow"; $db_password = "password"; $cxn = mysql_connect($db_hostname,$db_username,$db_password) or die ("Could not connect: " . mysql_error()); mysql_select_db($db_name); $sql = "SELECT output, fuel, numunits, capabilityfactor, pollution FROM db1 GROUP BY fuel ORDER BY sum(output) DESC"; $result = mysql_query($sql, $cxn) or die ("sorry, try again"); while ( $row = mysql_fetch_assoc($result)) { extract($row); $capfactor = number_format($capabilityfactor,2)*100; if ($fuel == "fuel1") $fuel1_total = $output; if ($fuel == "fuel2") {$fuel2_total = $output; $fuel2_pollution = $pollution;} if ($fuel == "fuel3") {$fuel3_total = $output; $fuel3_pollution = $pollution;} if ($fuel == "fuel4") $fuel4_total = $output; if ($fuel == "fuel5") $fuel5_total = $output; if ($fuel == "fuel6") {$fuel6_total = $output; $fuel6_pollution = $pollution;} $waste = number_format($pollution); } ?> <tr> <td><?php echo $fuel; ?></td> <td><?php echo $numunits; ?></td> <td><?php echo $foutput; ?></td> <td><?php echo $capfactor; ?></td> <td><?php echo $waste; ?></td> </tr> </table> <body> </body> </html> What I get is the html table with the right header row but the only data row is the one corresponding to fuel6. Something tells me the problem is with the positioning of the PHP tags, but I've tried all sorts of combinations and they usually produce an error that indicates I'm missing a curly bracket or the ?> tag. I'm stumped. Anybody have an idea what I'm doing wrong? Hi guys, im trying to parse a html table from an existing website to my own. However ive run into a few problems. Does anyone know how to parse html tables?? im using the PHP DOM Parser but at the moment i am only able to return all the data on the website rather then the specific table. Thanks for any help! Hi there I followed this post http://www.phpfreaks.com/forums/index.php?topic=95426.0 to get a multi-column layout of search results. All's well but I seem to have an extra blank row at the bottom of the table. This is my code for the table Code: [Select] echo '<table width="800px" class="center" border="1">'; echo '<td>'; if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 3; while ($list = mysql_fetch_array($result)) { // make the variables easy to deal with extract($list); // open row if counter is zero if($i == 0) echo "<tr>"; echo '<td><a href="word.php?w=' . $list['word'] . '">' . $list['word'] . '</a></td>'; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; } echo '</tr>'; echo '</table>'; Any ideas on how not to have it there? Thanks in advance. <?php function money($amount,$separator=true,$simple=false){ return (true===$separator? (false===$simple? number_format($amount,2,'.',','): str_replace('.00','',money($amount)) ): (false===$simple? number_format($amount,2,'.',''): str_replace('.00','',money($amount,false)) ) ); } $income = 5000000000; $daily = money($income*24,true,true); $weekly = money(($income*24)*7,true,true); $monthly = money((($income*24)*7)*30,true,true); ?> </center> <center> <table border="1"> <tr> <td>Daily</td> <td><?php echo $daily ?></td> </tr> <tr> <td>Weekly</td> <td><?php echo $weekly ?></td> </tr> <tr> <td>Monthly</td> <td><?php echo $monthly ?></td> </tr> </table> </form> </center> What am I doing wrong? Im fairly new to this Hi, I'm a little bit new to php and I'm having some issues selecting some data from a mySQL database and fetching it into a fluid html table..... Basicly what I want is a table with 4 columns and a X number of rows depending on how much entry is stored in the DB. Here's the SELECT code : Code: [Select] <?php mysql_connect("host", "user", "pass") or die(mysql_error()); mysql_select_db("DB") or die(mysql_error()); $id = $_GET['id']; $data = mysql_query("SELECT * FROM artist_gallery WHERE artist_picid='$id'") or die(mysql_error()); while($info = mysql_fetch_array( $data )) { Here the part I just can't figure.... what I want is to fetch the x number of picture in the DB into a html table : Code: [Select] echo " <table border=\"1\" cellpadding=\"1\" cellspacing=\"0\"> <tr> <td><img src=\"".$info['picture']."\" border=\"0\" /></td> <td><img src=\"".$info['picture']."\" border=\"0\" /></td> <td><img src=\"".$info['picture']."\" border=\"0\" /></td> </tr> </table> "; } ?> The pictures are just repeating 3 times at each row... Any help will be greatly appreciated!!! Thanks! I have a table that allows users to add rows, depending on how much data they need to insert. upon submit I'd like to populate another table for review. Now I can generate the data, but I'm having trouble putting the array into a table. Here is the output from the initial page: Code: [Select] Array ( [quantity] => Array ( [0] => 1 [1] => 2 [2] => 3 ) [description] => Array ( [0] => 1 [1] => 2 [2] => 3 ) [unit_cost] => Array ( [0] => 1 [1] => 2 [2] => 3 ) [shipping] => 4 [tax] => 5 [review_po] => Review ) I need it to look like this: Quantity | Description | Unit Cost 1 | 1 | 1 2 | 2 | 2 3 | 3 | 3 Tax | 4 Ship | 5 I think it's a foreach statement, but I'm not having any luck.. If someone could point me in the right direction??? Have never done this before, but I'm sure many of you have. What I am trying to do is take the information that the user fills out in this form and when they hit submit, it will be displayed into a html table on the next page. I don't need someone to do the entire table for me, just looking for some help to get started and a general idea of what to do. Here is my code for my form that I have created... Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Lab 4</title> </head> <body> <?php ?> <form method="POST" action="lab4form.php"> <label for="first_name">First Name:</label> <input type="text" id="first_name" name="first_name" /><br /> <label for="last_name">Last Name:</label> <input type="text" id="last_name" name="last_name" /><br /> <label for="coverage_amount">Coverage Amount:</label> <input type="text" id="coverage_amount" name="coverage_amount" /><br /> <label for="gender">Gender:</label> <br> <input id="male" type="radio" value="radiobutton" name="male" /> <label for="male">Male</label> <input id="female" type="radio" value="radiobutton" name="female" /> <label for="female">Female</label> <br /> <br> <label for="Age">Age:</label> <input type="text" id="age" name="age" /><br /> <br> <label for="health">Health Conditions</label> <br /> <input type="checkbox" name="health" value="heart" /> <label for="health">Heart Disease</label><br /> <input type="checkbox" name="health" value="diabetes" /> <label for="health">Diabetes</label><br /> <input type="checkbox" name="health" value="blood" /> <label for="health">High Blood Pressure</label><br /> <input type="checkbox" name="health" value="Smoker" /> <label for="health">Smoker</label><br /> <input type="checkbox" name="health" value="lung" /> <label for="health">Lung disease</label><br /> <FORM METHOD=POST ACTION="lab4form.php"> <P>Employment Status<BR> <SELECT NAME="employment"> <OPTION VALUE="lab4form.php">Unemployed <OPTION VALUE="lab4form.php">Full-Time <OPTION VALUE="lab4form.php">Part-Time <OPTION VALUE="lab4form.php">Student </SELECT><br /> <br> <label for="comments">Comments</label> <input type="text" id="comments" name="comments"/><br /> <br> <input type="submit" value="Add User" name="btn_add" /> </form> </body> </html> 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 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 ; We have booking data in spreadsheet looks like table in below, and each booking is for a full week. | wk1 | wk2 | wk3 | wk4 | wk5 |..........| wk52 | ================================== E1 | resv | |resv | |resv | |resv E2 | | resv |resv |resv | E3 | resv | resv |............................................... E4 | resv | E5 | ... | resv | resv|.................................... ... | E50|resv | resv | | resv It looks great excel but required one person to manage all bookings. So we moved to web interface and allow users to make their own bookings. Now, data moved to sql database with fields (id, wk#, room, other....), and records like below. 01 wk1 E1 02 wk1 E3 03 wk1 E4 ..... etc.... nn wk2 E2 nn wk2 E3 ... and more Now, I need a method in PHP to print above data in HTML table that looks like excel table in above. It doesn't have to print 52 wks in one page, but at least something like 4 wks view and next page to show the next 4 wks. At start it will print the first 4 wks from the current week (wk 11), and next page will print wk12 to wk15, etc. | wk1 | wk2 | wk3 | wk4 =================== E1 | resv | |resv | E2 | | resv |resv |resv E3 | resv | resv |............... E4 | resv | E5 | more rows...... Can someone here give me a direction how to code this in PHP? Thank you very much! bobo |