Formatting Mysql_fetch_array Results In HTML Table
This looks like a simple problem, but I just can't seem to wrap my
head around it.
I'm trying to build a table dynamically, based on a result set from
mysql. There will be 9 results for a full page, with 3 table rows of 3
table cells. One result per cell. But all of the pages won't be full.
Here's one of many ways I've tried to do it:
<html>
<head>
<title>test</title>
</head>
<body>
<table width="100%" border="1">
<?php
include_once('db.inc.php');
$query = "SELECT DISTINCT title FROM mytable LIMIT 9";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
$title = $row['title'];
}
for ($i = 0; $i < 3; $i++) {
print ' <tr>' . "
";
for ($e = 0; $e < 3; $e++) {
print ' <td align="center">' . "
".
' title : ' . $title . "
".
' </td>' . "
";
}
print ' </tr>' . "
";
}
?>
</table>
</body>
</html>
This prints out 3 rows of three like I hoped, but $title is the same
in all 9 cells. I also have tried it with the for loops inside the
while loop, which prints out 9 rows of 9 cells 9 times!
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Printing Mysql_fetch_array Results In Multicolumn Table
I'm not sure if this qualifies as a mysql or a php question so I'm asking in both groups. I am pulling the results of a mysql query from my database and want to print the results into a two column table. I know how to get the results into a single column table just fine using: while($row = mysql_fetch_array($result)) { print "<table border=2><tr><th>" . $row[name]; print "<tr><td>"; print mysql_field_name($result, 0) . ": " . $row[ID]."<br>"; print mysql_field_name($result, 1) . ": " . $row[name]."<br>"; print mysql_field_name($result, 2) . ": " . $row[address]."<br>"; print mysql_field_name($result, 3) . ": " . $row[city]."<br>"; print mysql_field_name($result, 4) . ": " . $row[telephone]."<br>"; print "</td></tr>"; print "</table> "; print "<br><br>"; } and it works fine. But my efforts to get the reults into a two column setup have become frustrating. My latest attempt was: while($row = mysql_fetch_array($result)) { print "<table border=2 width=ྖ%'>"; print "<tr>"; print "<td>"; print "<b>" . $row[name] . "</b><br>"; print mysql_field_name($result, 0) . ": " . $row[ID]."<br>"; print mysql_field_name($result, 1) . ": " . $row[name]."<br>"; print mysql_field_name($result, 2) . ": " . $row[address]."<br>"; print mysql_field_name($result, 3) . ": " . $row[city]."<br>"; print mysql_field_name($result, 4) . ": " . $row[telephone]."<br>"; print "</td>"; print "<td>"; print mysql_field_name($result, 0) . ": " . $row[ID]."<br>"; print mysql_field_name($result, 1) . ": " . $row[name]."<br>"; print mysql_field_name($result, 2) . ": " . $row[address]."<br>"; print mysql_field_name($result, 3) . ": " . $row[city]."<br>"; print mysql_field_name($result, 4) . ": " . $row[telephone]."<br>"; print "</td>"; print "</tr>"; print "</table> "; print "<br><br>"; }
Results From Two Db Tables Into One Html Table?
I have a query below that gets its results and puts them in a table. The current results are from two fields in a db table. I am wondering if it is possible to create a second query to get results from a different db table and echo them out in the same html table as the ones already there? Code:
Output Query Results To Html Table
I have a MySQL table "products" and I want to output product's data to html table as below: - A products contain 4 fields: image, name, description, price. - 4 products is nested in 1 html table 4 rows x 4 columns. Code:
Getting Results To Display In Two Columns Of A HTML Table
How can i get the following script to display in two columns of a HTML table? At the moment i have it displaying in one column. If there are 5 results from the DB then the left HTML table column will display the 1st, 3rd and 5th result. The right HTML table column will display the 2nd and 4th results. Code:
Divide Mysql Results Into Rows In An Html Table
I need to divide my mySQL results into rows with 4 results on each row. Its for a small image gallery script, I wanna show 4 thumbnails per row. I have all the code ready to get the info and show it, I just need an example of how I can take the data from the table and have it automatically go to a new row every 4 entries.
Table / Mysql_fetch_array
I can't keep my columns at a fixed width. About every five rows that are returned the last couple of columns will scrunch in. How do I keep everything perfectly aligned? Code:
Mysql_fetch_array And Table Aliases
I'm using mysql_fetch_array to run a query along these lines: SELECT A.name, B.name FROM A, B WHERE A.id = B.id I tried this code: while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo $row['A.name']; } .... but the echo statement produces "Notice: Undefined index: A.name". Of course, using just 'name' would be ambiguous because the query also retrieves B.name (and my actual query will involve more tables and probably select '*' [i.e. all columns], so it isn't trivial to use 'AS' to provide individual column aliases).
Formatting SQL Results In Tables
Fairly new to all this, but, I can return results from MySQL into a table without any problems - but what about formatting. I need the 6 columns to be of fixed width. Currently, due to the variable length of the data in the columns, they keep changing each time I cycle through a set of results.
Formatting Problem With Query Results
I have a minor problem with a script. I have written a piece of code (do...while loop) that will return results of a query a row at a time, with the proper formatting in a table. Everything works fine when there are results to lay out in the table. The problem arises when the query yields no results. When this happens, the loop below iterates once (without data) instead of not executing at all: $result2=mysql_query("select * from ...) or die(""); $myrow2=mysql_fetch_array($result2); do { ...bunch of stuff... } while($myrow2 = mysql_fetch_array($result2)); Where do we go from here?
Table Background Color Based On Results From MySQL Table
I am trying to get the "Did User Agree" field on a database query to be colored Green for "Agreed" Red for "Disagreed" and Blue for "Agreed (2nd Time)" .. I have my PHP setup to do the query just fine as of right now with alternating column colors, just can't seem to get the colors to work as I am hoping for. Can anyone help me get the Agreed? table's background color to the colors above? Code:
Formatting Of Decimals In A Table.
I'm not sure how to format : 15.00 155.00 so the .00 part lines up in a cell row I'm using a while loop to display the prices from an array. How do I get them to line up?
Formatting A Date With Php From A Mysql Table
I have date and time in my mysql table in the form 2007-05-03 00:00:00 which I have dispayed on my webpage using echo $selldatetime I want to know how I can display it in the form 03-05-2007
PHP/MySQL SQL HTML Formatting
I am writing a PHP script that populates dynamic PHP data from a MySQL column, and evaluated a variable in that column (or at least that's what I want it to do). I have this code:
Formatting Html And Php For Data
I'm having trouble formatting information from a MySQL database using PHP. I'd like to dynamically insert the <title> information, as well as the first name, last name and price range. Here's what I have, but it pulls up the correct information, but it's not within the table and the <title> information pulls up a blank. Code:
MySQL To HTML Formatting
I'm working with a mysql/php setup and have run into a major problem (for me atleast). We have mysql TEXT fields that contain line breaks and the kind something like FIELD CONTENT ------------- First paragraph Second paragraph Third Paragraph -------------- END FIELD CONTENT While that is fine in MySQL when it is output to HTML it comes out as NETSCAPE --------- First paragraphSecond paragraphThird paragraph --------- END NETSCAPE Does anyone know of a php function that can add in the needed <BR> and <P> so that the output will actually look as intended?
Formatting Of Phpinfo() With HTML Under CLI PHP
In the code below, invoked with CLI PHP, it would make good sense to have phpinfo() include HTML tags with its output. Is there any way to effect this? My attempt using ini_set("html_errors", "1"); did not make any difference. <?php $ie = new COM("InternetExplorer.Application"); $ie->Navigate("about:blank"); $ie->visible = true; ob_start(); phpinfo(); $phpinfo = ob_get_contents(); ob_end_clean(); $ie->Document->Write($phpinfo); ?>
Help Formatting HTML Emails Using Sendmail
A client of mine requires the ability to send out HTML formatted emails after a database post. When I send the email out to yahoo or hotmail, the actual HTML tags are visibile. Using these same yahoo and hotmail accounts, i can view emails from other providers that are formatted with HTML, so this tells me my code is wrong. PHP Code:
HTML Formatting From MySQL Fields
I don't create very complex databases, but the formatting of the text within the fields is something that I have become used to. I want the user to be able to cut and paste from one source or another, and want the text that is returned to the public from a search or whatever, to have the original formatting. What is the easiest route for this solution?
Formatting Form Entry Into HTML
I was wondering how to go about allowing the information submitted into a form for something like a news service with a Mysql backend to have the ability to be formatted by the user for HTML attributes such as bolding text etc. This question came about because I set up a press release and news section and have noticed that a number of users have asked if there was any way to make list items in their posts, and I wasn't sure what was needed to allow that type of functionality. Does it mean I have to start getting into WYSIWYG editors and the likes, or are their easier ways of doing it?
Formatting Email In HTML From PHP Form
I have a multi-page form called Dodosmail running our online questionairre. Its written in PHP and works great. I just want to know if there's a snippet out there that anyone knows about that can format the results from the form into an HTML formatted email. There are so many fields that it is hard to read the data if they arent put in columns or tables. Any help would be appreciated. Im not a programmer and hope I am in another life!
Grab Content From HTML Table And Place Into MySQL Table?
I am in the process of helping a co-worker upgrade some of his old static html pages into dynamic MySQL driven pages. He currently has a lot of pages with huge tables displaying data. Does anyone know if there is a script or class that can convert a table to a .sql file for upload?
Place The Results In Another Table
I am trying to take the results from a query and place the results in another table. I want to take all the results from $row join them together. is this possible to do? And can the results be stored with the information from the print statement? (<br> from each row) Code:
Colour Top 3 Results In A Table
I'm currently trying to make a poker league whats seem to be going well. I have populated a table with the league results, but would like 1st position in gold, 2nd in silver and 3rd in bronze. These will be the first three rows of the table, as the data has already been arranged in the correct order. I'm a little unsure how to go about doing this, and wondered if anyone could point me in the right direction. Code:
Sorting Table Results
I tried searching Google for some stuff about sorting table results. I want to be able to click the different headers and sort the results by each field. Anyone know some good sites/tutorials?
Dynamically Generated Results Table
I'm trying to write a script that dynamically generates HTML tables depending on the results from an SQL query. So far, I have managed to set the HTML table headers to be the same as those in the MySQL table. [thanks to rod k -cheers !] Now i'm trying to put the results in the table. Basically, I need a MySQL function to retrieve data and put it into the table until there is no data left.... (At the moment I am using "mysql_fetch_array()", but with this it is necessary to know the names of the columns to retrieve the information for each result set. Since my table is dynamic and should be able to build itself from different MySQL tables, the column names aren't fixed and so i can't use this to put the data in the tables...)
Creating A Link Within Table Results?
I am using php and mysql. Does anyone have any pointers on how to include links within table results that point to additional information also pulled from the same db table? I have some extensive info that I want to query. The intial results are going to be displayed in a simple wire frame html table layout. I would like each row to include a link that will take the reader to a more detailed version of the data for that particular row, and that more detailed data will of course come from the same db table. My problem is I don't know how to setup the code to create such link.
Display Query Results In A Table
$sql = "SELECT name FROM employee_tb; $result_query = @mysql_query ($sql);// run the query while ($row = mysql_fetch_array($result_query,MYSQL_NUM)){ $name = $row[0];} // assuming i have 8 results how can i display the results from this query in a table with 3 rows each column?
Displaying Array Results In Table
I'd like to display the results of an array in a table format with the Alias, Alias Destination & Username as column headings & the results underneath. PHP Code:
Putting Database Results In A 5x1 Table
I have a db of tens of thousands of entries. It's not too hard to pull all the entries and build a table that displays them one at a time, but in my case, that will be a huge waste of space. What I want to do is put one record in each of the columns. I thinks it's possible to do because I have seen very elaborate thumbnail gallery scripts to do this. I just want to be able to put two or three strings of text from each record into each row, and a checkbox. Here's sample of what I mean: <table width="76%" border="1" cellspacing="1" cellpadding="1"> <tr> <td>$record1Line1<br>$record1$Line2<br> <input type="checkbox" name="$record1checkbox" value="checkbox"></td> <td>$record2Line1<br>$record2$Line2<br> <input type="checkbox" name="$record2checkbox" value="checkbox"></td> <td>$record3Line1<br>$record3$Line2<br> <input type="checkbox" name="$record3checkbox" value="checkbox"></td> <td>$record4Line1<br>$record4$Line2<br> <input type="checkbox" name="$record3checkbox" value="checkbox"></td> <td>$record5Line1<br>$record5$Line2<br> <input type="checkbox" name="$record5checkbox" value="checkbox"></td> </tr> </table> I want to pull about 200 records at a time from the db and display as described above. How can I tell php to take five records from my result set and display above, then loop through the result set until I'm done?
JOIN Table Results W/MySQL
I have a query with a simple JOIN. For example: SELECT * FROM Companies INNER JOIN CompanyTypes ON Companies.CompanyID = CompanyTypes.CompanyID The query returns all fields from both Companies AND CompanyTypes. I would like all fields from Companies only.
Getting Data From A Table Based On The Results From Another?
This is the second part of my problems with a top ten list: I'm making a site for guitar effects. I'm trying to make a list of the top ten effects pedals, based on how many effects settings (patches) people have submitted for each pedal. There are two tables, pedals and patches: I want it to select patches and find out which "pedal_id" is most common, then select that pedal ID from pedals, echo some tuff, then do the query again, except search for the SECOND most popular value, echo it, then the third, echo it, etc etc etc
Display Results Of Survey In A Table.
Is it possible to have them fill in a survey with about 10 form fields, then display the results of everyone's survey in a table that can be sorted by different criteria so new users to the site can instantly see which one of our services is better for them.
Loop To Print Formatted Table From Sql Results
I'm trying to create a 3 column table now, and each cell will contain info from a single record. All the records will be pulled from a mysql database. What makes this a bit difficult is that I want the center column to be blank. Only the first and third columns will contain the results. I can't get the desired effect, and I'm not sure my loop logic is even correct. Does anyone know what's wrong with my code? Code:
Displaying SELECT Results In A Formatted Table
I was wondering how to show a table with a max limit of 20 results per page. I have various data being pulled and its putting it in a table, but its displayed all in one row. I want to format it so its a 4 column/5 row table. With that I then want the page to generate a numbered list at the bottom that calculates how many pages it takes to show 20 items on each. Code:
Displaying SQL Query Results In 3 Column Table
I would like to be able to display the results of an sql query in an html table, but the results need to be displayed in three columns, for example: Column 1 Column 2 Column 3 Result 1 Result 2 Result 3 Result 4 Result 5 Result 6 Result 7 Result 8 Result 9 I've tried to find the answers on the internet but i can't find anything that suits my needs!
Advice On Sorting Results (in A Table): Session Variables?
I have a table of query results (from PostgreSQL) that I am displaying using PHP. I would like to give the user the option to sort the results by clicking on one of the various table headings. I know that I can sort them at the time that I query them, but this would require a new database query each time. I am thinking of making the heading a hyperlink similar to the following: <a href=myresultspage.php?sort=price> //this would be the link to sort by the price collumn. I have managed to make a simple sorting function, by putting the results into an array then sorting the array by the appropriate dimension of the array as indicated by the value of $sort. My question is this: If I keep the results in an array, how can I pass the array when the user clicks on the hyperlink that tells which collumn to sort by? Do I need to use session variables? It doesn't seem like I can pass an array as a GET variable.
How To LIMIT Results In Html Php/sql Query?
I need to limit results in the following query type: http://www.somewhere.com/php/sql-a....ql_order=&pos=1 I found a reference that says I should be able to use LIMIT x[,y], but I don't know where/exactly how to add that to the string. Once I know what it's supposed to look like, and can write something to generate it. If someone could post an example using the above and limiting the output to 100 records starting at position.
Sending Mail: Choice Between Sending Receipt, Or HTML Formatting
I'm using PHP's mail function to send out a message via email. I would like for this email message to send a receipt when read as well as send an HTML formatted email. Both aspects are important to me. I know this is a product of the mail header. This is the format I currently have: mail(to, subject, body, "From: name <email> Disposition-Notification-To: name<email> Content-type:text/html;charset=utf-8"); This prompts the email program to send a reciept, but the email message is not in the HTML format, and even contains "Content-type:text/html;charset=utf-8" at the top of the body. If I switch the order to this format: mail(to, subject, body, "From: name <email> Content-type:text/html;charset=utf-8 Disposition-Notification-To: name<email>"); This sends the email with HTML formatting but does not prompt the sending of the receipt. I also get "Disposition-Notification-To: name<email>" at the top of the email message. This tells me there is a problem in the transition between the headers, which currently is "". What am I doing wrong?
Html Form Results To Excel Spreadsheet
This sounds like overkill, but is there any way I can take the results of an html form, and plug them into their respective cells on a excel spreadsheet?
Put A Html Table In A Variable
I want to do the following: I want to draw a table in html (with the echo command) and put that in a variable so I can draw that table via that variable. I got the following (large table ;-) Code:
Php Condition In A Table With Html And Php
I would like to show a line in a tabel in html if there is quantity of article choosed. My code is: <? if ($quantite1 0) { echo(' <tr> <td align="left" nowrap="nowrap">Article 1</td> <td align="center"><? echo $quantite1 ?</td> <td align="center">20 €</td> <td align="center"<? echo $montant1 ?€</td> </tr>'); } else{ echo(""); } ?> If there is no article >no line If there is article >show the line Problem: I can have the variable $quantite1 and $montant1 en php
Extract An HTML Table
I have an html-file, in which there are a table. I wants to extract this table. PHP Code:
HTML Table To Excel
I am running a MySQL SELECT query to dump the output to an excel file. I have tried various methods (CSV, PHP Classes to build excel docs, etc.) I ended up using a variation of a lot of the ones I have tried. I am using an HTTP header in PHP: PHP Code:
Displaying A HTML Table With PHP
I'm new to PHP and I'm trying to get my head around databases at the moment. So far I have a page that kinda takes the mickey and takes a few details from you, it then creates a cookie that can be removed later. It also prompts you to add the data you gave to a database. All this works perfectly, but when it comes to displaying the results of the database, all I can show is the first entry in the table. Can someone please tell me how I'm supposed to see all of them? I've read other articles but they don't make much sense to me. BTW, the database details are as follows: Database name: visualanteorg Table name: people Fields: id, name, shoe_size, job As you will see if you choose to look at the pages, getting the information out is not a problem, it's just formatting it how I want it, so each entry appears under the other in the table.
Convert Html Table To Csv
i need to write a script to automatically convert some statistical data from an html table to csv there are two problems that i'm having, depending on the user or the options selected, some rows won't be shown, and some will so in the code, there are a heap of if statements to hide/show columns which makes it especially hard when we need to add new columns for the html view, something else i need to look into i guess. i thought the easiest way, might be to use file_get_contents() to grab all the html code cos it's all laid out nicely already but then i thought about the colspans which would affect the comma seperatedness of the header columns (if you get that) does anyone know of a good, effective, scalable solution to this problem? Code:
How To Parse HTML TABLE
I have a problem with parsing html table. I need a script witch will pars html table from one site to another.
|