473,785 Members | 2,466 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pqsql fieldnames

This is a function that returns the names a table field on a pgsql database

$skips is simply the field names that will be left out of the result.

This function acts differently on two different servers
Both servers have PHP Version 4.3.10-10ubuntu4.3
AND PostgreSQL(libp q) Version 7.4.6

On one server, the function acts as expected, returning an array with
the field names. On the other server, some of the field names come up 6
times instead of once. Apparently, something in my sql is creating
multiple values for some names. My sql is kind of fuzzy, can you see the
mistake ?

function fieldnames($tab le, $skips=NULL){
$sql="SELECT a.attname FROM pg_attribute a, pg_class c WHERE
c.relname = '$table' AND a.attnum > 0 AND a.attrelid = c.oid ORDER BY
a.attnum ";
$result=q($sql) ;
$skips=mkarr($s kips);
while($row=pg_f etch_assoc($res ult)){
if(in_array($ro w['attname'], $skips))continu e;
$fnames[]=$row['attname'];
}
return $fnames;
}
Mar 9 '06 #1
1 1638
meltedown wrote:
This is a function that returns the names a table field on a pgsql database

$skips is simply the field names that will be left out of the result.

This function acts differently on two different servers
Both servers have PHP Version 4.3.10-10ubuntu4.3
AND PostgreSQL(libp q) Version 7.4.6

On one server, the function acts as expected, returning an array with
the field names. On the other server, some of the field names come up 6
times instead of once. Apparently, something in my sql is creating
multiple values for some names. My sql is kind of fuzzy, can you see the
mistake ?

function fieldnames($tab le, $skips=NULL){
$sql="SELECT a.attname FROM pg_attribute a, pg_class c WHERE
c.relname = '$table' AND a.attnum > 0 AND a.attrelid = c.oid ORDER BY
a.attnum ";
$result=q($sql) ;
$skips=mkarr($s kips);
while($row=pg_f etch_assoc($res ult)){
if(in_array($ro w['attname'], $skips))continu e;
$fnames[]=$row['attname'];
}
return $fnames;
}


Since the problem seems to be in the SQL code, might I suggest that a
PostgreSQL newsgroup would be more appropriate?
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Mar 10 '06 #2

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

Similar topics

3
11335
by: Josep | last post by:
Hi, I'd like to poll a database and get the table contents, as well as the field names from that table. I've been to php.net but this time I cannot find something helpful. I can get the data, and retrieve it into an array noproblem. I can get the data+fieldnames and put it into a list.
2
1660
by: rdack | last post by:
how can i retrieve database names and fieldnames from mysql 4 using MySQLdb 0.9.2 from python 2.3? (on mac osx 10.2.6)
7
3287
by: | last post by:
How do I get to the fieldnames of a table in a recordset? I have a recordset which I output into HTML. And on data from certian columns I need to perform different actions. I would like to use the fieldnames rather then theit sequential numbers, to avoid the need to re-do the code if another field is inserted into the table.
4
2018
by: Little PussyCat | last post by:
Hello, I have had a request, one of our tables is used as a report and I have been asked that all fieldnames for months have dashes in them, like Jan-05 instead of Jan05 and so on... Now what we have is a CURSOR which loops through all values in another table generating these fieldnames, like 'Jan-05', Feb-05' etc.. Then the table definition is modified so these months display as fieldnames.
1
1076
by: Jay Balapa | last post by:
Hello, Iam creating a query page, in which a Drop Down List will have collection of fieldnames. Is there a elegant way of doing it? Currently Iam opening up a datareader and using GetName()/FieldCount() to get to fieldnames.
3
1987
by: Beren | last post by:
Hello, I have an sproc to query a couple of tables, that have the same fieldnames, for example DateCreated. ------------------------------------- Select a.* , b.* From tablea a Join table b On b.keyfield = a.keyfield -------------------------------------
6
4706
by: Miles Keaton | last post by:
Is there a simple way to list fieldnames in a table, from PHP? When on the command-line, I just do \d tablename But how to get the fieldnames from PHP commands? ---------------------------(end of broadcast)--------------------------- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to majordomo@postgresql.org so that your message can get through to the mailing list cleanly
6
2132
by: Gerrit | last post by:
Hello, I try to display the fieldnames and the primary key of a table, with this code: using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.Odbc;
2
1480
by: john | last post by:
In the query builder I made an edit-query in which I have linked table A to table B on IDnr. For every record that matches I want 5 fields of table A to get the values of corresponding fields in table B. I'm able to make this query but only by typing the table B fieldnames in the 'change to'-row. Is there some easy way to drag those fieldnames to that row or another way to make this easier? Thanks, john
0
9647
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10161
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10098
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9958
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8986
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7506
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3662
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.