473,403 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

printing collumn names then contents from mysql query

how can i take every field from a table (where there are many) and
without referencing by name (using a loop) echo there name in a td
followed by the contents? i think the foreach statement is what im
looking for? but i dont understand it.

regards

marc

Aug 2 '06 #1
4 1150
Rik
monomaniac21 wrote:
how can i take every field from a table (where there are many) and
without referencing by name (using a loop) echo there name in a td
followed by the contents? i think the foreach statement is what im
looking for? but i dont understand it.

$result = mysql_query'$query);
while($row = mysql_fetch_assoc($result){
echo '<tr>';
foreach($row as $key =$value){
echo "<td>{$key}:{$value}</td>";
}
echo '</tr>';
}

Grtz,
--
Rik Wasmus
Aug 2 '06 #2
Ive tried that Rik and it deesnt work quite right. it displays each
collumn twice, once with a number as key and the value and again with
the (intended) colname as key and value. How can i modify it to stop
the first bit being output?
Rik wrote:
monomaniac21 wrote:
how can i take every field from a table (where there are many) and
without referencing by name (using a loop) echo there name in a td
followed by the contents? i think the foreach statement is what im
looking for? but i dont understand it.


$result = mysql_query'$query);
while($row = mysql_fetch_assoc($result){
echo '<tr>';
foreach($row as $key =$value){
echo "<td>{$key}:{$value}</td>";
}
echo '</tr>';
}

Grtz,
--
Rik Wasmus
Aug 4 '06 #3
Rik
monomaniac21 wrote:

Do not toppost please.
Rik wrote:
>monomaniac21 wrote:
>>how can i take every field from a table (where there are many) and
without referencing by name (using a loop) echo there name in a td
followed by the contents? i think the foreach statement is what im
looking for? but i dont understand it.
$result = mysql_query'$query);
while($row = mysql_fetch_assoc($result){
echo '<tr>';
foreach($row as $key =$value){
echo "<td>{$key}:{$value}</td>";
}
echo '</tr>';
}
Ive tried that Rik and it deesnt work quite right. it displays each
collumn twice, once with a number as key and the value and again with
the (intended) colname as key and value. How can i modify it to stop
the first bit being output?

Use mysql_fetch_assoc() as per my example instead of mysql_fetch_array();

Grtz,
--
Rik Wasmus
Aug 4 '06 #4
sorry had an urgent deadline with that one :-(

Rik wrote:
monomaniac21 wrote:

Do not toppost please.
Rik wrote:
monomaniac21 wrote:
how can i take every field from a table (where there are many) and
without referencing by name (using a loop) echo there name in a td
followed by the contents? i think the foreach statement is what im
looking for? but i dont understand it.
$result = mysql_query'$query);
while($row = mysql_fetch_assoc($result){
echo '<tr>';
foreach($row as $key =$value){
echo "<td>{$key}:{$value}</td>";
}
echo '</tr>';
}
Ive tried that Rik and it deesnt work quite right. it displays each
collumn twice, once with a number as key and the value and again with
the (intended) colname as key and value. How can i modify it to stop
the first bit being output?


Use mysql_fetch_assoc() as per my example instead of mysql_fetch_array();

Grtz,
--
Rik Wasmus
Aug 4 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Jeroen van vliet | last post by:
I have a program that when clicked i want to print 2000 papers, with the names adress etc of customers. So it have to print every record. How to manage it? Jeroen
0
by: Michelle Keys | last post by:
I am trying to call a print function to print a string from a database using javascript. Which is RC_DATA of Varchar2(2500). This is a javascript is not being used. I have a thing that needs to...
1
by: JackM | last post by:
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...
1
by: monomaniac21 | last post by:
Hi all Can anyone tell me how you can query mysql for all unique entries into a particular table collumn. Ive checked the manual but had no luck! Kind regards marc
4
by: monomaniac21 | last post by:
hi! is it possible to do the aforementioned query - selecting only distinct in 1 col but retrieving all other cols at the same time. regards marc
2
by: mcyi2mr3 | last post by:
hi all ive been looking on the mysql site but i cant find the syntax to set a collumn in an existing table to be unique. could someone please give an example of how to do this. i believe it...
8
by: 1987dan | last post by:
I have made a collumn 7 rows deep where i click an arrow at the top of the column and then a red counter appears in the bottom cell of the collumn. I wish to make this collumn like a connect 4...
4
by: Bob | last post by:
Hi all, I've got a table that I've imported and it has junk at the top of the table, so after import I run a delete query to remove the junk lines then I'm left with the field names I want for...
7
by: Muddasir | last post by:
i am having problem in printing the query result from MySQL db... actually i am developing a very simple search module. when the user select category from the given categories in drop down...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.