Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




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.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
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?

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!

Comparing Results From Two Tables
I am having some major trouble comparing information from 2 tables. I am attempting to verify the information in similar columns, so that I can come up with a number.  The columns are setup as varchar(30). The basic idea of the program is to obtain the Qualifying results for a race, and then add them to the table with Race results. Code:

MySQL Multiple Tables / Results
I would like to perform multiple queries to a MySQL database and have all
the results in 1 result set.

Print Results From Two Tables Linked Together
I need to be able to pull data from a table (product_status, which has many other fields) and cross reference it with data in another table (warranty). The data in product_status lies in a field called warranty_number, and is simply an id number (1,2,36,etc.) The data in table warranty, field warranty_comment,

is text (30 day warranty, one year warranty, etc.). The warranty table also has a field called warranty_id, which corresponds to each text entry in the table. This number matches the number in table product_status, field warranty_number. So I need to be able to print results of product status, but instead of printing simply the number in field warranty_number,

it needs to check table warranty, field warranty_id, then match the number, then pull the text from warranty_comment and print along with all the other results from product_status. I have some code that works, but it is not at all designed for this, so I won't post. Is this enough info to explain what I need? I have tried searching, but found nothing that I could see that would help.

Display Results From Multiple Tables
I have two tables, one table (article_cat) has four fields ("id", "title", "feature1", and "feature2") and the other table has six fields (articles) has ("id", "cat_id", "title", "content", "feature1", and "feature2").

I am looking to display the "title" from the "article_cat" table that has "feature1" with a value of 1. And I want to display beneath that all the "title" results from the "articles" table where "feature1" has a value of 1. I have tried this a thousand ways with no luck. Code:

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:

Setting Radio Buttons Via A Tables Results.
I'm generating a dynamic table based on a SQL call to a database. For each row returned I need four radio buttons in a group which somebody can make a decision on. The above is no problem but what I want to do is at the same time set the radio buttons to the correct figure based on the data returned. PHP Code:

Results Of Same Field Names But Different Tables In MySQL Query.
I have a SQL string with a couple of JOINs that works perfectly in
command prompt. I get results for all the fields selected just fine.
But when I put it into a PHP page, I can't make variables(?) out of
fields that have the same field name from different tables.
Here's the SQL statement:

$sql = "SELECT orders.companyid,orders.ordernum,orders.address,tb l_ih_accounts.company,tbl_ih_accounts.address
FROM orderstatus ".
"LEFT JOIN orders ON (orderstatus.ordernum = orders.ordernum) ".
"LEFT JOIN tbl_ih_accounts ON (tbl_ih_accounts.id = ihid) ".
"WHERE submitted <> 'yes' ORDER BY orders.ordernum ASC";

Then in the "WHILE" clause after the database is queried:
$o_address = $row[orders.address];
$ih_address = $row[tbl_ih_accounts.address];

I've tried it without the table names in the $row statements, but then
I'll just get the results for tbl_ih_accounts.address.
I'm thinking there must be some way to uniquely "name" the results of
a particular field up in the SQL statement, and then just use that
unique name in the WHILE. But I have no clue, and can't find anything
about anything like that.

Query Array, Sort Results And Display In Seperate Tables
The problem I have it breaking out the results and displaying them (broken out) alphabetically in seperate tables. For instance, I have generated (bookmarked) tables, one for each letter (A-Z) and want to display all recordsets with say, last name
beginning with "A" in one 2 column table, "B" in another 2 column table, and so on... each
table would have two columns (with 2 background colors alternating), each cell containing values of one recordset.

Even more tricky is if I have an odd number of cells, still generating the last cell with empty values (for asthetics). And can anyone say "sort" (yes, I am nuts)? The ability to sort the whole mess by any column value. I have looked at freeware and other third part apps, but they can only do what I already can do (mine is actually cleaner) but not as complicated.

Retrieving,Sorting & Displaying Multiple Results From Mutliple Tables
I need to know how to run a php / mysql query to do the following.

I have 1 database (lets call it "database" for now) within this database there are multiple tables ("News","Feature","Header_feature")

For NEWS I need only the 6 latest results pulled from that table and displayed in a table.  The "News" table has the following columns "ID","Title","Date","Body","Image"

For Feature I need only 1 result retrieved from the database and displayed under the variable $ticker as it will display as a scrolling marquee within a table.  The "Feature" table has the following columns "ID","Ticker".

For Header_feature I need only 1 result retrieved from the database and displayed in the following manner <a href="$link"><img src"$header_feature">[/url]  The "Header_feature table has the following columns "ID","image","link"

How would I code this all into 1 page?  I cant seem to get the query to do everything I want it to and display the results properly.  You can see what I have so far at www.getlivemedia.com  The $ticker is the scrolling text near the top of the page and the news is obviously the bulk of the page and $feature_image is the broken image.

Generating Multiple Alternating Columns And/or Tables Within Tables
I am having a little bit of trouble generating the code for a table with 2 columns. The columns contain tables within themselves. Not sure why as that part was an existing design. Here is the output so far and it is correct but not how i want it to be (i'll explain) Code:

Search Brings Back Different Results Or Sometimes No Results
The problem Iv got is that when searching the site - it brings back different results or sometimes no results. For example: "i026", "i 026" and "026" do not bring back results for "I-026" which is the correct model number. Any ideas on how to make it search more variations or of a "Did you mean... I-026" script?

Search Results ($num_rows) Does Not Match $search Results (PHP,MySQL)?
For example, when I do a database search for a term I get 2 results but the $num_rows says there are 3 results.

I suspect it's because there are similar keywords within different search fields of the SQL statement. But I am stumped as to how I can change this. Any Suggestions? the code:

Formatting
Does anyone know how to keep the formating of a textarea box (i.e. keep the lines and spaces between lines) when it gets put into a mysql table (the column set as text).

Formatting Of Dates From MDB With PHP
I am having a problem with Date formatting I am running PHP on an IIS box and my date formatting is coming out quite strange utilizing the following query:
$strSQL = "SELECT Indiv.Lastname, Indiv.Firstname, IndivClient.StartDate, IndivClient.Type, IndivClient.StartDate FROM Indiv INNER JOIN IndivClient ON Indiv.NameID = IndivClient.NameID WHERE (((IndivClient.Type)='QSuspect') AND ((IndivClient.StartDate) Between $workday And Date()));";
and the following output code
print "<td>$directory->value</td></tr>";

I get dates in this format
1021006800

If I use a simple date string I get dates in the normal d/m/y format.

Formatting Error In IE
I've created a form in php which displays and works perfectly in Opera. However, when I bring it up in IE, the text and input boxes are separated by almost half the page and the submit does not work. The code follows - any assistance would be appreciated.

PHP Text Formatting
I'm wondering if someone can help me out with a small but no less importam problem I have?

I'm using the code below to call text from a MySQL database field

<td>".$rs[2]."</td>

The problem is that the text appears with the web page like

Sentence 1 Sentence 1 Sentence 1

and not like

Sentence 1
Sentence 1
Sentence 1

as it should be, any suggestions?

Formatting A Date
I need to format a date in php to look like Sunday September 2.
If the code is like this:

Date Formatting
I am trying to work out how to convert UK date format (DD/MM/YYY) to a format that will be accepted by MySQL (YYYY-MM-DD), so far I have been almost successful by using the following:- PHP Code:

Formatting Dates?
Im reading a csv file with php and getting a date in the form 30/09/07
Which I am trying to insert into a mysql table which has the field formatted
as yyyy-mm-dd hh:mm:ss . I cant get it to insert the field remains blank
How do I do this?...

Formatting Strings?
i have a row in one of my databases, and i use a timestamp to imput the current time into the row. Now, when i output the timestamp i get something like 20001218155634. I tried reading the php manual to help me on editing strings, but it wasn't of much help.

So does anybody know any websites with good php string manipulating tutorials? or can anybody show me how to format the timestamp?

Formatting Text
I am currently looking for a way to have text that is entered in my news service (it is added to a databse, then displayed) to be cut off after a certain length on some pages (mainly the front page)...kind of like what you see on some sites with the "read more" at the end. I want it so i could enter a long news/article update, then on the home page it would be shortened, and when the user clicks on the title, it takes them to the detail page with the full length article. I am using dreamweaver, if that makes any difference.

Formatting Dates
I can't get my date to properly display. It is $birthday. It is formatted as a time stamp. Previouslu, I had it in yyyy-m-d format. Neither worked! The output I get from the code below is Age: 33 (December 31, 1969). WHY?

$today = time();
$age= ($today - $birthdate)/60/60/24/365.25;
$f_age = sprintf("%01.0d", $age);
echo "Age: $f_age ";
$f_birthday = date("F d, Y", $birthday);
echo "($f_birthday)<br>";

Date Formatting
how do I retrieve the current year to insert to the database. And how the date data is stored? is it yyyy/mm/dd or yyyy/dd/mm?

Formatting String
i have a variable that holds a string, the held string can be any string including HTML tags, here is an example. PHP Code:

String Formatting
i have built a forum for my site with php an mysql. a user submits raw text from a textarea into a table. when the text is pulled for display i run it through a function called "format_post( )." PHP Code:

Textarea Formatting
I am using a php html form with data which is loaded from a mysql
database. Three of the fields are textareas. The data loads into these
fields fine, except that the loaded text starts at what appears to be 2
or 3 tab characters to the left. See illustration:

+---------<this is a textarea object>---------+
| This is about the way that|
|the text loads from the database field. |
| |
| |
+---------------------------------------------+

It's almost as if there's a textarea "align" property which is set to
"center" by default unless otherwise explicitly stated.

Is there some setting in the wrap property that will fix this, or should
I be looking elsewhere?

Formatting Problem
I am using stripslashes(htmlspecialchars($myrow[1])) to display a record from the database. When I enter data in the form in the backend, I want to put <b>text</b> but this actually turns out as <b>text</b> on the webpage instead of bolding the word text.
How do I make it so I can enter HTML in the backend textarea form fields?

Formatting A String
if i have a string like this:
id=14,15,16,17

and some of the ids can be missing
e.g. id = 14,,16,17

I would like to strip out the extra commas. Ive had a few goes trying different ways.

#$!%& Date Formatting.
I've looked through every OTHER date format thread, I've even tried 2 or 3 different methods of formatting the date. I even had a thread back in May about this, and I still haven't gotten it to work. PHP Code:

Formatting XML Data
I am currently working quite a bit with XML files and i keep running into the same problem. Many times i want to split the text into a paragraph, or make it an unordered list. How do you all format your XML idea.

Formatting Numbers?
How can I get from "5.99" to just "5"? I tried researching the manual, but they are full of rounding numbers and decimal points.

Formatting From TXT File
I am using a txt file to store site URL's and names here is the code I am using:
PHP Code:

Textbox Formatting
say you've got this textbox that asks for a visitors first name. Is there a way to make the first letter of their name CAPITALIZED even if they typed it in lower-case? (i.e. they type "billyjoe" and I want the output to be "Billyjoe" with a capital B) I've been searching for a while, but haven't been able to come up with anything yet.

Formatting Number
Can sombody tell me the best way to format a number in this way.

456.45657 must be 456,46

So the point becoms a comma and I would have 2 digits i.pv. 5

PHP And Number Formatting
When I add 2 items in the cart less than $1000.00, the formatting of the numbers display fine. When for example I got 2 items that cost 3475.00, the total cost the the two items is displayed as 6, and NOT 3475.00.

I am using the the sprintf function, and I believe my problem lies in the fact that I don't know the correct format to display numbers in excess of 1000.00?

Text Formatting
I'm having a problem with PHP, mysql and HTML. I am writing a message board for my site using PHP and mysql. I am running into a problem however with text formatting. Right now, the text for a message is entered into a text area. When the user submits the form the text is sent to a mysql database. All this works fine. My problem comes when reading the text FROM the database.

If I use PHP to create a table and read the text into a cell, all of the formmatting is lost. No line breaks, tabs, etc... it just lumps all of the text together. I can use a <PRE> tag and then put the text in and it will preserve the formatting with line breaks, etc. The problem with this is that it wont word wrap. So if i type alot without a hard line break, then when it reads from the database using a <PRE> tag it puts all of the text on one line and stretches the table.

Because the <PRE> tag will display it with its original formatting I know that the formatting is being stored in the mysql. So I either need to find out how I can wordwrap a <PRE> tag (in IE). OR I need to know how I can get PHP and HTML to restore the original format of the text without using a <PRE> tag.

Currency Formatting
i'm trying to format the output of a record in access, which i am
pulling from through php (odbc) and the formatting is set at 4 decimal
places, which i don't want. i want currency and no decimal places.
I was trying to use this example, but i have no bloody idea howo to use it.
or where to put it for that matter:

<?php

$number = 1234.56;

// let's print the international format for the en_US locale
setlocale(LC_MONETARY, 'en_US');
echo money_format('%i', $number)."
";
// USD 1,234.56

?>

Formatting Strings
I am currently using sprintf to format a report from a MySQL database data. I was wondering if there is an easy way to format text besides using sprintf. See below for the example I need to recreate. If any lines exceed the 75 column the need to wrap to the next line and indent 24 spaces. PHP Code:

Formatting Number.
I am trying to display prices on a shopping cart system, but need to be able to display the prices in the form £x.yy, at the moment I am getting things like:

£4
£4.2
£4.123

How can I make PHP display a floating point number with only/at least 2 decimcal places?

Php Date-Formatting
I have a date value that I pull from a .csv file.
After reading the file and storing the values in an array the value of
the date could be found in $array[1], for example.

while (($data = fgetcsv($handle,5000, ",")) !== FALSE) {
$mydate = $data[3]; // here is the array value that holds the date
}

The date will be in either m/d/yyyy or mm/dd/yyyy format.
Here is the problem. I need to display this date on the page
in "long" format - i.e. January 5, 2005 instead of 1/5/2005 or
01/05/2005.

I have tried to use the date() function, however I can only get the
formatting to work with the current date and not with an 'existing' date.

date("d.m.Y", $mydate); // this does not work, I get a date from
1969...

Number Formatting
I have a page that multiplies an amount of a part by the quantity of that part, then gives a total. For example: PART (costs $5.00, quantity of 3) That yields a total of $15. I want to it say $15.00 and I want it to round to the hundreths place in circumstances where a part may cost $3.6554, for example. How can I achieve this?

String Formatting
I have the following string -

&=120=-&=127=-&=131=-&=135=-&=170=-&=171=-&=174=-&=175=-&=194=-&=196=-&=206=-&=222=-&=230=-&=236=-&=237=-&=240=-&=249=9

249=9

The important part are the numbers e.g. 120,127 and the dash or value after the = and before the & e.g. 236=  (-)   &

The red part. I would like to separete them to get to display the dash only. how would I do this?

Formatting Currencies From An Int
If i have $Money = 200000;  Then how can i get it to automatically place "," within that number, to convert it to a string?  I can easily add "$" etc. but im stumped on this "," buisness.

Date Formatting
I have a table with a datetime field which is in the format "2007-06-20 00:00:00.000" using the following code I can display this nicely as dd/mm/yyyy (e.g. 20/06/2007).

<?php 

$Format_Start_Date = ($Start_Date != '')?date("d/m/Y",strtotime($Start_Date)):''; ?>

My question is this.... I now want to be able to edit these values by updating a form and I want the users to be able to enter the date in the format dd/mm/yyyy, can I edit the field so that it reads and updates as dd/mm/yyyy or alternately how would I convert the entry back to yyyy-mm-dd hh:mm:ss for the database to be updated?

Formatting A Date
I have two varibles, one called

$cycle_through_the_month

and another called

$display_month.

"$cycle_through_the_month" displays a date, such as "5" for the 5th day, "18" for the 18th day and so on

"$display_month" displays a month and year, such as "MARCH 2007" or "NOVEMBER 2007".

Combined together like "$cycle_through_the_month $display_month" produces something like 2 APRIL 2007 or 26 JUNE 2007.

What I want to do is to format these so that they print out like

02/12/2007

or

29/11/2007

Email Formatting
I have a php form that is filled out and then submitted.  When it is submitted a copy of the information that was submitted is sent to me via email and another person that is named on the form is also sent this same email.  The copy the other person receives is fine. 

The copy I receive is all messed up, as if it is just all one single line with all formatting ignored. The form also generates a separate message to the person that filled out the form.  This message is fine as well. Only the copy sent to me is messed up. To be sure the form is one php file, but it refers to another php file.

Ok. I will admit that I am new to this. This form was created by someone that recently left the company. It was handed to me with the instructions to get it working. I just don't know where to start. I would copy and paste something, but I'm not sure what part you would want to see. Any direction would be most appreciated. I will try to learn PHP, but I cannot do it on the timetable my boss expects.

Paragraph Formatting
we have some paragraphs that have <BR>,<P> buried in them and want to modify them so that <BR> stars a new line and <P> begins a new paragraph. We tried
the below:

$NOTE = str_replace("<P>","n
",$NOTE);
$NOTE = str_replace("<BR>","
",$NOTE);

It looks like the  1st replace does not work and the second one does. We  are outputting the  paragraphs to  a PDF  generatorn and it needs a text file  with proper  line and paragraph codes.


Copyright © 2005-08 www.BigResource.com, All rights reserved