473,396 Members | 1,724 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,396 software developers and data experts.

Looping through fields in a row

Hi All,

I am trying to display a mysql record on the screen. I would rather
not use specific field names in case the fields change, etc. So, I
just want to create a simple table with the field names down the first
column and the corresponding values in the second. I've tried several
different snippets of code that I found, but I can't seem to get it
working right.

This is what I've been working off of:

$fieldNames=array_keys($myrow);

But this array have every other value as, what seems to be, a row id.
Looks like this:

Array ( [0] =0 [1] =sheet_id [2] =1 [3] =client_id [4] =2
[5] =business_name [6] =3 [7] =business_address [8] =4 [9] =>
business_city)

Any suggestions would be appreciated.

Sep 13 '07 #1
5 1550
On 13 Sep, 15:28, stacey <monkeym...@gmail.comwrote:
Hi All,

I am trying to display a mysql record on the screen. I would rather
not use specific field names in case the fields change, etc. So, I
just want to create a simple table with the field names down the first
column and the corresponding values in the second. I've tried several
different snippets of code that I found, but I can't seem to get it
working right.

This is what I've been working off of:

$fieldNames=array_keys($myrow);

But this array have every other value as, what seems to be, a row id.
Looks like this:

Array ( [0] =0 [1] =sheet_id [2] =1 [3] =client_id [4] =2
[5] =business_name [6] =3 [7] =business_address [8] =4 [9] =>
business_city)

Any suggestions would be appreciated.
use mysql_fetch_object or mysql_fetch_assoc and use a foreach thus

$rows = mysql_fetch_assoc($res);
foreach ($rows[0] as $field_name =$field_value)
echo "<tr><td>{$field_name}</td><td>{$field_value}</td></tr>";

Sep 13 '07 #2
C.
On 13 Sep, 15:44, Captain Paralytic <paul_laut...@yahoo.comwrote:
On 13 Sep, 15:28, stacey <monkeym...@gmail.comwrote:
Hi All,
I am trying to display a mysql record on the screen. I would rather
not use specific field names in case the fields change, etc. So, I
just want to create a simple table with the field names down the first
column and the corresponding values in the second. I've tried several
different snippets of code that I found, but I can't seem to get it
working right.
This is what I've been working off of:
$fieldNames=array_keys($myrow);
But this array have every other value as, what seems to be, a row id.
Looks like this:
Array ( [0] =0 [1] =sheet_id [2] =1 [3] =client_id [4] =2
[5] =business_name [6] =3 [7] =business_address [8] =4 [9] =>
business_city)
Any suggestions would be appreciated.

use mysql_fetch_object or mysql_fetch_assoc and use a foreach thus

$rows = mysql_fetch_assoc($res);
foreach ($rows[0] as $field_name =$field_value)
echo "<tr><td>{$field_name}</td><td>{$field_value}</td></tr>";
Thanks for playing Captain, unfortunately the correct answer was:

while ($row = mysql_fetch_assoc($res)) {
foreach ($row as $name =$val) {
echo "<tr><td>{$name}</td><td>{$val}</td></tr>\n";
}
}

C.

Sep 14 '07 #3
On Thu, 13 Sep 2007 16:28:15 +0200, stacey <mo********@gmail.comwrote:
Hi All,

I am trying to display a mysql record on the screen. I would rather
not use specific field names in case the fields change, etc. So, I
just want to create a simple table with the field names down the first
column and the corresponding values in the second. I've tried several
different snippets of code that I found, but I can't seem to get it
working right.

This is what I've been working off of:

$fieldNames=array_keys($myrow);

But this array have every other value as, what seems to be, a row id.
Looks like this:

Array ( [0] =0 [1] =sheet_id [2] =1 [3] =client_id [4]=2
[5] =business_name [6] =3 [7] =business_address [8] =4[9] =>
business_city)
Don't fetch the result with mysql_fetch_array(), use mysql_fetch_assoc()
instead. mysql_fetch_array() will return both a numerical as named array
by default.
--
Rik Wasmus
Sep 14 '07 #4
On 13 Sep, 15:44, Captain Paralytic <paul_laut...@yahoo.comwrote:
On 13 Sep, 15:28, stacey <monkeym...@gmail.comwrote:


Hi All,
I am trying to display a mysql record on the screen. I would rather
not use specific field names in case the fields change, etc. So, I
just want to create a simple table with the field names down the first
column and the corresponding values in the second. I've tried several
different snippets of code that I found, but I can't seem to get it
working right.
This is what I've been working off of:
$fieldNames=array_keys($myrow);
But this array have every other value as, what seems to be, a row id.
Looks like this:
Array ( [0] =0 [1] =sheet_id [2] =1 [3] =client_id [4] =2
[5] =business_name [6] =3 [7] =business_address [8] =4 [9] =>
business_city)
Any suggestions would be appreciated.

use mysql_fetch_object or mysql_fetch_assoc and use a foreach thus

$rows = mysql_fetch_assoc($res);
foreach ($rows[0] as $field_name =$field_value)
echo "<tr><td>{$field_name}</td><td>{$field_value}</td></tr>";- Hide quoted text -

- Show quoted text -
Yes of course it was!

I have spent so long using mysql through a framework, that I totally
forgot what the raw functions do!

Sep 14 '07 #5
Rik Wasmus wrote:
On Thu, 13 Sep 2007 16:28:15 +0200, stacey <mo********@gmail.comwrote:
>Hi All,

I am trying to display a mysql record on the screen. I would rather
not use specific field names in case the fields change, etc. So, I
just want to create a simple table with the field names down the first
column and the corresponding values in the second. I've tried several
different snippets of code that I found, but I can't seem to get it
working right.

This is what I've been working off of:

$fieldNames=array_keys($myrow);

But this array have every other value as, what seems to be, a row id.
Looks like this:

Array ( [0] =0 [1] =sheet_id [2] =1 [3] =client_id [4] =2
[5] =business_name [6] =3 [7] =business_address [8] =4 [9] =>
business_city)

Don't fetch the result with mysql_fetch_array(), use mysql_fetch_assoc()
instead. mysql_fetch_array() will return both a numerical as named array
by default.
--Rik Wasmus
Or just:

mysql_fetch_array($result,MYSQL_ASSOC); // MYSQL_ASSOC, MYSQL_NUM,
MYSQL_BOTH are allowed. Default is MYSQL_BOTH.

Norm
Sep 14 '07 #6

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

Similar topics

4
by: Roy Adams | last post by:
Hi posting again because no answer to previous.. tring to loop through a recordset and update a record, thing is it only updates the first record in the table rather than searching through the...
4
by: David | last post by:
Hello. I am looking for advice on what is "best practice" regarding looping through a form to check its checkboxes and associated data fields. Here is what I am trying to do (Here is the page...
8
by: RC | last post by:
I have a table that lists many box numbers. Each box number has a Pallet Number (indicating which pallet the box is in). When the Pallets are loaded into a shipping Container I need to update the...
20
by: Stewart Graefner | last post by:
Here is a chunk of code that works for an individual record. It evaluates dates and checks or unchecks boxes as it goes along. It may not be pretty but it works. What my problem is that I need it...
11
by: Dacuna | last post by:
Is it possible to use a recursive function to loop through a recordset faster? I have a table that I need to edit its contents after doing some calculation. The table has one field has an RawData...
5
by: Jeff | last post by:
Hey gang. I have a script that gets stats from a mssql db, and then inserts those stats into a temp table. where i can work with them as i wish. the problem is it isn't looping through all the...
11
by: Liam.M | last post by:
Hey guys, If anyone could spare sometime to help me out, it would be very much appreciated.....what I am trying to do is automate a "Command" that sends me an Email. I have created a Query that...
5
by: talktozee | last post by:
Hello, everyone! Here's are the basics: 1. The query looks at all positions that are active and haven't been filled. 2. It then has to look at every single position and determine three...
1
by: pds79 | last post by:
Hi everyone, I'm a newbie to the forum. I have an issue and was hoping to get some assistance/ideas: Im trying to read a XML file into two record sets. I can acheive looping through the...
1
by: darrel | last post by:
Hi vb master i need help on this here my code: If Combo1(0) = rs.Fields("TimeStart") And Combo4(0) = rs.Fields("TimeEnd") And Combo2(0) = rs.Fields("ROOM") And Combo3(0) = rs.Fields("DAYS")...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.