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




Displaying Rows Of Data As Columns?


Does anyone know of an efficient way to retreive data from a mysql db
and display the record rows as collumns?

I have been doing this:
<display headers>
<while ($row = mysql_fetch_array($result)) { >
<display row 1 of result>
<display row 2... } >
<end table>

but I want to do this instead:
<col 1 header > <row 1 col 1> <row 2 col1> <row3 col1>
<col 2 header> <row 1 col 2> <row 2 col2> <row3 col2>
<col 3 header> <row 1 col 3> <row 2 col3> <row3 col3>




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Display Data In Columns Of 4 And Repeat Rows
What I would really like for it to do is display the results across 4 cells and then start on the next row and so on. Code:

Displaying Columns With A Value
what is the most efficient way to display column names from a database that only have the value '1' in its fields??

I cant seem to work it out, could someone give me a code example??

Displaying Database Information In Columns
I have a database with products in and I want iT to automatically show every product on the page. Now I am able to do this easy enough but what I am struggling to do is that I want the products to be displayed in 3 columns. I can get them to display one under the other easy enough but I want them to be in rows with 3 columns instead.

Displaying Database Records Over Multiple Columns
I am currently using the following to generate a table with a single column with ten entries PHP Code:

Displaying 10 Rows (Newbie)
I need help....I want to display 10 hits from my sql database.....

A function that wil select the first 10 rows of my database and then also provides me with a link to the script itself to diplay the next 10 hits (Or less, if there is no more).

Displaying Entries In Rows Instead Of On Top Of Each Other
I'm altering a voting script for our dog rescue so that we can hold an online photo contest. I'm very new to php & mysql..kinda just muddling my way about with this.

I want to display the entries in a row across about 4 or 5 photos and then keep it going that way, but I haven't a clue as to how to do this....

Drop Down Not Displaying All Rows
I am having an issue with the drop down box. If there is only one row
in the table the drop down box will display nothing. once the table
has two or more rows the drop down displays the row but always one shy
of the total. here is the script i am using:

$query = "SELECT SEC_TITLE
FROM section
WHERE SEC_TITLE != ''";

$result = mysql_query($query);

while ($row = mysql_fetch_array($result, MYSQL_ASSOC))

{ echo "<form action='#'>
<select name=section>
";
while ($line = mysql_fetch_array($result, MYSQL_NUM)) {
$section = $line[0];
echo " <option value=$section>$section
";
}
}

Displaying An Array From Rows Retrieved From Mysql
I have a web site where users can add pages to it. When they make a new web page the url of the page and username of the user who created it is stored in Mysql. When the user logs back in the users previously made pages are displayed as links or atleast should be. Below is the code that I am using. PHP Code:

Displaying Multiple Queries To Same Table Excluding Different Rows!
i've got a table with 224 town listings and their ID's in it from 6 counties, and I want it to displayin a 6 columned table, each county getting their own column. Anyway, here's what I've got and what's happening: PHP Code:

Insert Data On Different Rows
I am still relatively new to all the intricacies of PHP and am having a problem.
I have 10 different students (S1-S10) from the same school who all are given the same foods for lunch on a particular date. 

They each get the same entree, condiment (like ketchup), grain, fruit, veggie1, veggie2, beverage1 and beverage2.

I need to be able to enter the amount of each item consumed (like 8 tater tots for the grain) and proportion consumed (i.e. None, 25%, 50%, 100%, other, etc.) for each student.  The proportion consumed can be a drop down but it needs to allow you to type in a value if over 200%.

This data then needs to go into an Access table with each student (S1-S10) as a separate row. Code:

Insert Data From Mysql Rows Into An Array
I am working on a project where I need to select rows from a table called 'hub' and take the rows where 'to_id' = '$to_id' and put them into an array. How can I get MySql info into an array?

Get The Data From Those Rows That Have Data
Hi Guys,
If i were to have the following php query:


$query = "SELECT * FROM alist WHERE list_id = $id";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
echo "<b>{$row['List_Name']}</b><BR>";
echo "{$row['address']}, {$row['state']}<BR>{$row['post_code']}<BR>Tel: {$row['phone']}<BR><BR>";
echo "{$row['Info']}<BR>";
echo '</blockquote>'

....how can i get the data from those rows that have data.
For example, some rows won't have a 'phone' value so i don't want this to display "Tel: " if there is no value associated with 'phone'.
What do i need to add to my script inorder to achieve this?

Thanx...

Displaying Data
Probably a really stupid question to ask, but if i have a number in mysql lets say 180000 and it represents a price is there a way to change that to 180,000 without saving it in the database like that?

Displaying Wrong Data?
I have a PHP script that inserts data into a database: PHP Code:

Displaying Data In Php - Like HTML?
How do I display data from MYSQL in PHP in an attractive and structured table(HTML) format? For example: I want my database to display all the reviews of a particular movie(like metacritic.com) like this: Code:

Displaying Data From Array
I have a data stored in an array. Want to display it in Internet Explorer... However,could not display it.

Inputing And Displaying Data
i have a website that will list certain shops in my area. i want these shops to be displayed in a table with 4 columns on my website, the first being the name of the shop and when you click on the shop it links you to there website. the rest of the columns will be different images depending on what service they provide.

i thought i could create a form that allows me to input the name of the shop etc, but each time i submit the form it adds the information to my database and creates a new row each time i submit a new shop on the table on my website page.

im very new to php and sql so it would be helpful if you could link me to a tutorial that sort of tells you how to do this or add me on msn.

plus i was just wondering if it is worth buying a book about php and mysql or should i stick to online tutorials. if it is, please recommend me some.

Display 5 Columns From 10 Columns
How to the display 5 columns from 10 columns in a page using for loop reading data from txt file.

Grabbing Data From A Table And Displaying It
I'm grabbing data from a table and displaying it but I want to to spand out into multiple pages...I got it all setup but when I click on the next link nothing happens... I got it setup at "3" right now just for testing..I have 5 entries in the database.. anyways could someone help me out? here is the code:

<?php

// Get connection info
include "../connect.php";
// End connection info
if(!$rowstart) $rowstart=0;
// Start database select
$result = mysql_query(
"SELECT * FROM links WHERE notactive='$notactive' order by date desc limit $rowstart,3"); //Select Database
$result2 = mysql_query("select * from links");
if (!$result) {
echo("<P>Error performing query: " .
mysql_error() . "</P>"); exit(); }
// Display the text of each host
while ( $row = mysql_fetch_array($result) ) {
if ($notactive = 1) {
echo ("<table width=500 height=57 border=0 cellpadding=0 cellspacing=0>");
echo ("<tr>");
echo ("<td align=left valign=top><strong>" . $row["name"] . "</strong></td>");
echo ("</tr>");
echo ("<tr>");
echo ("<td align=left valign=top>" . $row["desc"] . "</td>");
echo ("</tr>");
echo ("<tr>");
echo ("<td align=left valign=top><a href=" . $row["url"] . ">". $row["url"] ."</a></td>"); }
echo ("</tr>");
echo ("<br><br>");
echo ("</table>");
}
if ($rowstart>$numrows)
{
echo "<A HREF=$php_self?rowstart=rowstart-3>";
echo "< Previous Page</A>";
}
echo "|";
$numrows=mysql_num_rows($result2);
if($rowstart+3<$numrows)
{
echo "<A HREF='$php_self?$rowstart=rowstart+3'>Next Page></A>";
}
?>

Grabbing Data From A Table And Displaying It
I'm grabbing data from a table and displaying it but I want to to spand out into multiple pages...I got it all setup but when I click on the next link nothing happens... I got it setup at "3" right now just for testing..I have 5 entries in the database.. anyways could someone help me out? here is the code:

<?php

// Get connection info
include "../connect.php";
// End connection info
if(!$rowstart) $rowstart=0;
// Start database select
$result = mysql_query(
"SELECT * FROM links WHERE notactive='$notactive' order by date desc limit $rowstart,3"); //Select Database
$result2 = mysql_query("select * from links");
if (!$result) {
echo("<P>Error performing query: " .
mysql_error() . "</P>"); exit(); }
// Display the text of each host
while ( $row = mysql_fetch_array($result) ) {
if ($notactive = 1) {
echo ("<table width=500 height=57 border=0 cellpadding=0 cellspacing=0>");
echo ("<tr>");
echo ("<td align=left valign=top><strong>" . $row["name"] . "</strong></td>");
echo ("</tr>");
echo ("<tr>");
echo ("<td align=left valign=top>" . $row["desc"] . "</td>");
echo ("</tr>");
echo ("<tr>");
echo ("<td align=left valign=top><a href=" . $row["url"] . ">". $row["url"] ."</a></td>"); }
echo ("</tr>");
echo ("<br><br>");
echo ("</table>");
}
if ($rowstart>$numrows)
{
echo "<A HREF=$php_self?rowstart=rowstart-3>";
echo "< Previous Page</A>";
}
echo "|";
$numrows=mysql_num_rows($result2);
if($rowstart+3<$numrows)
{
echo "<A HREF='$php_self?$rowstart=rowstart+3'>Next Page></A>";
}
?>

Grabbing Data From A Table And Displaying It
I'm grabbing data from a table and displaying it but I want to to spand out into multiple pages...I got it all setup but when I click on the next link nothing happens... I got it setup at "3" right now just for testing..I have 5 entries in the database.. anyways could someone help me out? here is the code:

<?php

// Get connection info
include "../connect.php";
// End connection info
if(!$rowstart) $rowstart=0;
// Start database select
$result = mysql_query(
"SELECT * FROM links WHERE notactive='$notactive' order by date desc limit $rowstart,3"); //Select Database
$result2 = mysql_query("select * from links");
if (!$result) {
echo("<P>Error performing query: " .
mysql_error() . "</P>"); exit(); }
// Display the text of each host
while ( $row = mysql_fetch_array($result) ) {
if ($notactive = 1) {
echo ("<table width=500 height=57 border=0 cellpadding=0 cellspacing=0>");
echo ("<tr>");
echo ("<td align=left valign=top><strong>" . $row["name"] . "</strong></td>");
echo ("</tr>");
echo ("<tr>");
echo ("<td align=left valign=top>" . $row["desc"] . "</td>");
echo ("</tr>");
echo ("<tr>");
echo ("<td align=left valign=top><a href=" . $row["url"] . ">". $row["url"] ."</a></td>"); }
echo ("</tr>");
echo ("<br><br>");
echo ("</table>");
}
if ($rowstart>$numrows)
{
echo "<A HREF=$php_self?rowstart=rowstart-3>";
echo "< Previous Page</A>";
}
echo "|";
$numrows=mysql_num_rows($result2);
if($rowstart+3<$numrows)
{
echo "<A HREF='$php_self?$rowstart=rowstart+3'>Next Page></A>";
}
?>

Grabbing Data From A Table And Displaying It
I'm grabbing data from a table and displaying it but I want to to spand out into multiple pages...I got it all setup but when I click on the next link nothing happens... I got it setup at "3" right now just for testing..I have 5 entries in the database.. anyways could someone help me out? here is the code:

<?php

// Get connection info
include "../connect.php";
// End connection info
if(!$rowstart) $rowstart=0;
// Start database select
$result = mysql_query(
"SELECT * FROM links WHERE notactive='$notactive' order by date desc limit $rowstart,3"); //Select Database
$result2 = mysql_query("select * from links");
if (!$result) {
echo("<P>Error performing query: " .
mysql_error() . "</P>"); exit(); }
// Display the text of each host
while ( $row = mysql_fetch_array($result) ) {
if ($notactive = 1) {
echo ("<table width=500 height=57 border=0 cellpadding=0 cellspacing=0>");
echo ("<tr>");
echo ("<td align=left valign=top><strong>" . $row["name"] . "</strong></td>");
echo ("</tr>");
echo ("<tr>");
echo ("<td align=left valign=top>" . $row["desc"] . "</td>");
echo ("</tr>");
echo ("<tr>");
echo ("<td align=left valign=top><a href=" . $row["url"] . ">". $row["url"] ."</a></td>"); }
echo ("</tr>");
echo ("<br><br>");
echo ("</table>");
}
if ($rowstart>$numrows)
{
echo "<A HREF=$php_self?rowstart=rowstart-3>";
echo "< Previous Page</A>";
}
echo "|";
$numrows=mysql_num_rows($result2);
if($rowstart+3<$numrows)
{
echo "<A HREF='$php_self?$rowstart=rowstart+3'>Next Page></A>";
}
?>

Displaying Data Based On Variable
A Newbie to PHP so please forgive any ignorance of simple methods.

I am trying to develop a site that is driven by a MYSQL database. Dependant on which domain you have been redirected from I need to somehow pickup the domain redirected from and set a global constant to only pull from relative MySQL data e.g FOO = xyz.

This site will obviously have multiple users and I need a way to ensure that user A will be browsing xyz while user B will be browsing abc.

The way I can think of but not entirely sure how to get working in PHP is to assign a Value to the session (FOO) and then on database queries uses WHERE foo_ID = (FOO).

PHP MySQL Query Not Displaying Data
I am having some problems with a database query that I am trying to do.
I am trying to develop a way to search a database for an entry and
then edit the existing values. Upon submit, the new values are updated
in all corresponding tables (the function of the pages in question).
However, on the page that does the DB update, I also want to do some
checks on the data before performing the update.

Now, the problem that I am running into is that when I don't update the
primary key field (keyid) the page is running into the section where it
displays a message that the keyid already exists. This only happens
when the keyid on the previous page is not changed.

Upon troubleshooting the problem I found that the very first SELECT
statement does not seem to be returning any rows despite the fact that
the statement, when run on the SQL server, returns exactly one row. If
any could provide some assistance with this matter, I would be most
appreciative.

Code:
<?php
session_start();
header("Cache-control: private"); //IE 6 Fix

//continue if authenticated
if ($_SESSION['auth'] == 1)
{

//get variables from post
$keyid = $_POST['keyid'];
$username = $_POST['username'];
$corpid = $_POST['corpid'];
$usergroupname = $_POST['usergroupname'];
$oldkeyid = $_POST['oldkeyid'];
$oldcorpid = $_POST['oldcorpid'];
echo("Keyid: $keyid");

// Connect to MySQL
mysql_connect ("address.com", "user", "pass")
or die ('I cannot connect to the database because: ' .
mysql_error());
//select database on server
mysql_select_db ("seniorproject");

//SQL Statement
$sql = "SELECT keyid, corpid FROM users
WHERE keyid='".$keyid"'";

// Execute the query and put results in $result

$result = mysql_query( $sql )
or die ( 'Unable to execute query.' );
echo mysql_result($result,0);

// Count number of matches and print to screen
$numrows = mysql_numrows( $result );
if ($numrows == 1)
{echo(" SQL Query: $sql");
$result_ar = mysql_fetch_row($result);
$result_ar = mysql_fetch_row($result);
$dbkeyid = $result_ar['keyid'];
$dbcorpid = $result_ar['corpid'];
echo("<br> CorpID: $corpid <br>");
echo(" DBCorpid: $dbcorpid <br>");
echo(" DBKeyID: $dbkeyid <br>");
if($dbcorpid == $oldcorpid)
{
//If this condition is true, then KEYID has not changed. Execute
code

// Formulate the query

$sql = "UPDATE users
SET corpid = '".$corpid."', username = '".$username."',
usergroup = '".$usergroupname."', keyid = '".$keyid."'
WHERE keyid = '".$oldkeyid."'";........

Displaying Data In A Editing Form
I have a form that has three checkboxes. A,B&C. Data from A & C has been entered into the database by serializing it.I now want to create a edit form where the user can view his choices ticked.

<form action="postoDb.php">
A<input type="checkbox" name="Choice[]" value="A">
B<input type="checkbox" name="Choice[]" value="B">
C<input type="checkbox" name="Choice[]" value="C">
</form>

//postodb.php
$bn = serialize($Choice);
sql ="insert into table (choice) values('$bn')";

Question About Displaying MySQLl Data
Could someone point in the correct direction with regards to displaying my
data in "nicer" format. I have figured out ( with the tutorials on the web,
and the O'Reilly PHP & MySQL book) how to store, retrieve, manipulate, and
display my data using PHP. But when I do display, it is the block format.
I can't seem to find a tutorial that gets into a "prettier" type of display.

Is this a HTML issue?

I am a newbie to this stuff

Displaying Data In Html Table.
I wondered if anyone could offer some guidance, I trying to write a
php script to connect to a database, and display the records in a
table.

I found the code here in a php4 text, and when I run this directly
through the php intrupeter, the line Successfully connected is display
and 4 as the number of rows.

The database table we connect to, has three field username, firstname,
surname.

When I tried a while loop, to display the data in a table. No values
were displayed.

Could anyone possibly demonstrate how to display the username,
firstname, surname values in a basic table?

<?php
function db_connect(){
global $MYSQL_ERRNO, $MYSQL_ERROR;

$link_id = mysql_connect("localhost","user04", "password04");

if(!$link_id){
$MYSQL_ERROR = "Connection failed";
return 0;
}
else if(empty($dbname) && !mysql_select_db("database04")){
$MYSQL_ERROR = mysql_error();
return 0;
}
else return $link_id;
}

!$link_id = db_connect();
if(!$link_id) die(error_message('Error connecting'));

$result = mysql_query("SELECT * FROM users");
if(!$result) error_message('Error in selection');
else echo "Successfully connected. ";

$query_data = mysql_fetch_row($result);
$total_records = $query_data[0];

if(!$total_records) error_message('No records');
else echo "$total_records.";
?>

Displaying Data From A Flat File?
ive got a flatfile database sorted out, all i need now is how to store individual flat files per user and how to paginate that data. Just to make sure i'm doing everything right, i'll post the code below Code:

Drop-down Displaying MySQL Data
I've got this dropdown trying to call the data in...basically, I only want it to show if it is an upcoming event. Past events are hidden away in the archives.

I can get it to work if I remove the if ($row['date'] etc, but not with it in. Can anyone spot any errors with my code? Code:

Displaying All Data From Fetch Array
I'm having a problem displaying more then 1 result from a mysql_fetch_array statement in my php application.....

Displaying Line Breaks From MySQL Data
when i retrieve data from a MySQL database which i have put line breaks in they do not show in html, i understand that this is because HTML ignores spaces unless they are formatted as &nbsp; i know i could use the <pre> tag to show it as it was given, which removes all styling from the text, i need to convert the breaks in MySQL into <br> or <br><br> (to start a new paragraph)

Combining Data From Two Fields, Displaying With Another Table
What I am trying to do is pull data from two tables and display it on one page. The code below doesn't display any errors, but all it prints is the results from the first query. Ideas? Thanks.

(I also need to somehow put a variable in for the warranty table data so it is tied to the product_status table data. You can see there is a WHERE in the first query of pid, but no WHERE in the second query. That is a seperate question, though. It would make this way too long, so I will post it separately). PHP Code:

Hide Characters When Displaying Recordset Data ?
i have a mysql and php website, some of the products have an _ underscore (epson_dx500 eg) . i display these items listed vert down the page, i want the data in the table to stay the same but when displayed on the page i want to hide the underscore.

Displaying Binary Data To Browser And Set Mime Type
I am looking for a link or help on how to set the
mime type in my php script as well as send binary data to the browser
window instead of having it ask me to save the file.

Displaying Data From Mysql Database In A Drop Down List On Form.
I'm trying to do is display data from two different mysql tables from the same database in a drop down list on a html form. I have a fixtures table with the player1(userid), player2(userid), gameid, game, score1 and 2, what I want is to use the userid to get the players first name and surname from the members table (as it is a unique id), I need to do this bit before displaying it in the drop down. I think i need 2 querys to do this but when I have tried it it just echo's a blank value or the userid not the forname and surname that I want. I'm using the fetch_array function but just can't see where I'm going wrong, Code:

Count Amount Of Rows In Same Query Of Selecting Rows
I am selecting some rows from a table and i wonder if i can count
the amount of rows in that same table in the same query? I tried something like: PHP Code:

Help With Displaying Selecting A Date Range And Displaying Results
I wish to create a simple form that allows the selection of a start date and a stop date with the ability to select what columns to be displayed in the result page.

Sortable Columns
Hi there, I am new to this Forums...I am currently learning PHP and I was wondering if any of you guys knows how to make columsn in a table sortable. What would I have to change in the code? Thanks!

UPDATE Columns With PHP
So you know I'm going through Kevins book.

I'm updating data in a test table. I'm adding names to each joke, say I have 7 jokes and 3 of them go to the same person. I can update each one seperately but I can't find a way of bulk updating. In this case it's not a problem.

I've looked though Kevins book and a couple of others but can't find anything. Tried several sites to but I may just be searching wrong.

I can do this:
mysql> UPDATE Jokes SET AID="1" WHERE ID=2;

but I'd like to update WHERE ID equals 2,3,4,5 all at once.

How To Print All The Columns In A Row?
I want to display all the columns in a row without have to write the code for them all, is that possible?

Columns In Html
I am trying to make a table with two columns. I am really close. The problem is the table's first row has three TD's. ie

one two there
four five
six seven

PHP Code:

Sortable Columns
Does anybody know here how to make columns in a table sortable? I know that with a sql query I can accomplish that. PHP Code:

Grouping The Columns
Let's say I have a very simple Table:

+---------------------+
| id |  name  | level |
+---------------------+
|  1 |  Adam  |   1   |
|  2 |  Jack  |   7   |
|  3 |  Bill  |   1   |
|  4 |  Pete  |   3   |
|  5 |  Ross  |   7   |
+---------------------+

but I want the PHP to output their id's and names, but group their Levels together like so:

Level 1:
Adam (id: 1)
Bill (id: 3)

Level 3:
Pete (id: 4)

Level 7:
Jack (id: 2)
Ross (id: 5)

And then afterwards, If I create someone with a new level, PHP will automatically create a new heading (e.g. Level 10) and put the corresponding names under it.

How should I approach this? Should my PHP contain two "while"s? Or do I use the SQL <group by> function?

Creating Columns
I've been using this code to split records from a db into columns when it displays the data. Items are shown with 3 on a row and then a new row starts. It works really well but if ever there is only one item on a row it causes me a problem in this instance.

I have far left and far right columns which display a background image, which is a border. The problem is this only works if there are three columns visible in a row.

Is it possible to manipulate the following code so that there are always three columns present, they're just empty if there's no more records to fill them? Code:

Count The Number Of Columns
I was wondering if there is a way to calculate the total of columns in a table? (something like $totalRows= mysql_num_rows($Recordset1); , but than for columns)

Best Practices For Sortable Columns
I have several forms that display information from the database after
users log in. I would like the column titles to be sortable so that
when the user clicks on a column heading, the data re-displays in
sorted order of that column. Next time they click on it, it toggles
the order from ascending to descending, and then back to ascending
again.

Since I have many forms and each form has different columns, I was
wondering if there was a method that would be better than a brute force
approach. What are the best practices for this functionality?

Query Results In 2 Columns?
I'm struggling to figure out how to do this properly. I have done a mySQL
query to extract a list of names, and done a mysql_num_rows to determine how
many results I've gotten. I want to split the list in to two columns. I've
created $percol = $mysql_num_rows/2 but I'm not quite sure how to "loop"
through the first half of the list, echo </td><td> and then list the
balance. Can anyone give me some guidance on how best to structure this?

Printing Columns And Its Values
What would be the best way to get the columns of a table and the values I tried following code:

Index On A Combination Of 2 Columns ?
on a Mysql table i have 2 columns:

- banner views
- banner clicks

now i want an index on the MySQL table so that i can make an overview with the order
set to bannerclicks/bannerviews so i need an index on (bannerclicks / bannerviews )
is there a way to do this in MySQL without the need of an extra column ?


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