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




How To Get The Fields From A Table


Because the fields i make in the table are very subject to change and i want to know them without to have written in the php code. So i want to know all fields names from a table in a mysql database.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Outputting A Table Or Form Using SHOW FIELDS FROM Table
In the code the MySQL database was queried using "SHOW FIELDS FROM table" which and the returned results of column names was then use to build an output for a form and a table with php using a series of if statements along the lines of if the returned field name matches something echo a text input field.

I have never seen this done this way before, so I want to get the opinion of the devshed user. Does it seem like an unsual long process to build up a form. Is there a security advantage doing it this way? Has anyone ever done it this way before?

Returning Table Name As Well As Fields From That Table
I am returning all fields from news and from regional, however I want to determine where the fields have come from when I ouput the data, therefore I need to return the table name with the fields. Is this possible? Code:

Table Fields
how can i get field names of a table

Problem Sorting By 2 Fields From Table
As part of a rating system on my site, data for the total rating and also the number of votes gets added into a table. I am currently trying to query this table to get the highest rated row of data.

This worked fine when I only had "ORDER BY rating DESC LIMIT 1" at the end of my query - It would select the row where the rating was 5 out of 5. I realised that if 2 rows had the same rating, I could not determine which one to select. So i tried changing the code to: "ORDER BY rating, num_votes DESC LIMIT 1". For some reason, this now selects a row where both the rating and num_votes values are 0.

Just in case you need to see the entire query, here it is:

Adding Fields To An Existent Table Through PHP
Is something like this possible? A PHP script that would add for example 3 new fields to a table that already has 5.

Merging Mysql Table Fields
How can I merge multiple fields of a table for my query.

suppose I have 2 table

table1
=============
field1      field1
=============
Lam         20
Ld            9
Auz          3

so I want to check where does keyword "Ld9" Exisit

so what will me my query for
select * from table1 where field1+field2=$keyword

Two Auto Incrementing Fields In One Table?
I have been trying to get two different rows to auto increment in the same table? If so how do i do it? it says u can only have one primary (obviously) and that is the auto incrementing field. Is there any way around this?

here is the mysql error form phpmyadmin...

#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key

Search 2 Fields In A Mysql Table Using Only 1 Input Box
I would like to search 2 fields in a table using only 1 input box in php, at the moment I have 2 input boxes one for the Town search and one for the County searh, I would like 1 input box that would search the 2 fields. Here is my PHP Code:

Change Values Of All Fields In Table In PhpMyAdmin
I would like to be able to change certain values in every row of a table. There are about 1000 or so row, and I need to change the values of certain fields to all the same value, and wondered if that was possible easily (and not having to do each row individually) in phpMyAdmin?

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:

REQ How Would I Compare Multiple Date Fields In One Table To Find The Latest Entry Opps
i didn't explain it correctly before
my table is like this

example fields:
ID name username outcome date1 date2 date3 (etc..) - date15 price1 price2 price3 (etc..)

I know that Mysql query order by will compare records on a specific date, but how do i compare
multiple fields within the same record. Want to find the latest date within the record..

Grab Content From HTML Table And Place Into MySQL Table?
I am in the process of helping a co-worker upgrade some of his old static html pages into dynamic MySQL driven pages. He currently has a lot of pages with huge tables displaying data. Does anyone know if there is a script or class that can convert a table to a .sql file for upload?

Table Background Color Based On Results From MySQL Table
I am trying to get the "Did User Agree" field on a database query to be colored Green for "Agreed" Red for "Disagreed" and Blue for "Agreed (2nd Time)" .. I have my PHP setup to do the query just fine as of right now with alternating column colors, just can't seem to get the colors to work as I am hoping for.  Can anyone help me get the Agreed? table's background color to the colors above? Code:

Finding Matches In A Table And Then Moving That Match To Another Table?
Ok, I have a database that has a table called critiera in this table
is to fields on is ID and the other is critiera.

Now I want to filter out all the one that don't apple to the list and
move the one that match to a different database.

I know how to open a connection, close, select

but I don't know how I would inside of a database use another one as
the way to create the list of critieras....

Mysql Fetch_field Gets Table Alias, Not Real Table Name
After a SQL 'select .... from tablename alias'
the mysql_fetch_field function returns a value $result=>table which
will contain the alias, not the actual table name.
Is there a way to get the actual table name ?

I am running mysql 4.1 and php 4.4

Grab Data From A Table, Echo, Then Insert It Into A New Table...
I'm trying to do is count the number of times usernames shows up in a table. I then want to reinsert that information into a different table with the Username in column1 & the occurrences in column2 for every user that is echoed on the page. Code:

Using PHP To Sort Data In MySQL Table 1 By Values In Table 2
I have a MySQL database with 2 tables in it. products and prices.. Products has a field in it called 'prodno'. Prices has a field in it called 'prodid'.

There is one of each item in products and each product has it's own unique 'prodno'

There are multiple instances of each product's pricing in prices.. One for each price.. So if a product had multiple prices depending on quantity it would have an entry for each price.. Example:

id = 1
prodid = 7001
qty = 300
price = 12.5

id = 2
prodid = 7001
qty = 400
price = 15.5

I was wondering if I could query the database getting info from the products table but sort it according to the prices in the prices table.

Kinda like doing a "SELECT * FROM products" ordering it by the lowest price value from each item..

This is all very confusing to me, and I'm the one writing it. Let's try one last time..

Query the database selecting * from products (I plan on using all the info in products) and ordering them by the lowest price for each item in the prices table. I've tried sorting the results of just a basic SELECT * FROM products using Javascript and PHP but with pagination in the results it makes it a bit hard.

Update Table While Insert Data To Another Table
it seem like mine coding din work.
[php]<?

include("checkin.html");
$conn=mysql_connect('localhost','root','') or die ('Could not connect to server');
$today = date("Y.m.d");
mysql_select_db('hms', $conn);

$ok = mysql_query("INSERT INTO check_in(ID,room_no,datein)values ('$ID','$room','$today')", $conn);

if( $ok ){

$up = mysql_query("UPDATE studtable SET checked = 'checkin' where [ID] = '%ID');

if(mysql_affected_rows( $up ) == 1)
{
echo'Checked IN!'
}else { echo'No such student to check in' }}
else { echo'Check In FAILED, please check again'}?>[php]

How To Transfer A Data With An Id To Another Table From A Table?
how am i going to transfer let say a name identified using the suer id and copy the name to the other table having the same user id>?

How Can I Find A Name From One Table In A Text From Another Table?
I have one table with a description field and other info, and I also have another table with a list of names and picture url:s. When I display the text description on my site I'd like to know if there are a match with a name from the 'names' table in the text. Code:

Moving Data From One Table To Another Table
Does anyone know how to move one row from a table in a mysql database to another table using php?

Fields
For some reason, the edit field gets messed up when editing if there is HTML in the data. How can I fix this and also how can I make the fields for parasitedescription and parasiteremoval bigger to like 3 lines in height? Code:

How To Delete Fields
I would delete with php, all record of a table mysql where the seven left chars of the field is equal to the data in input($seven_chars).

I have used the the belowe istrucrion but it do not work.how can I do?

mysql_query ("DELETE FROM my_table WHERE substr(myfield,0,7)=$seven_chars");

Getting Specific Fields From A CSV
I've been using fgetcsv to populate an HTML table with CSV data and so far it has been working great. But now I'm looking to call specific data from the table (ie: row 3, column 5), and I'm not sure fgetcsv can be used for this. Every online example of its use involves getting all the CSV data from a file as my table has done.

What function should I use to get specific fields from my CSV? My table doesn't use unique ids, at least not like mysql, with a unique number identifying each row in the leftmost column. What then should I use to identify each row from which I'd like to get data?

I'm making a page that describes a person based on the query string and the information in the database, in which each person has a row. So example.com/example.php?christopher+walken would bring up a page where Walken's information is listed. So I guess the ideal way to do what I want is to query the CSV for the name in the query string (Christopher Walken), then get and print the other information in the row (tall, great guy, etc). Any suggestions on this query?

Spacing In Fields
I have a posting system for news, the admin types in what news he wants to post on his page via an admin section and another script out puts his comments from a database. My problem is as follows, if someone types a post and adds a space in it how to I get php to recognise this as a <BR> or whatever, e.g :

intended post :

"news blah blah etc

regards . . ."

but this is what I get "news blah blah etc regards . . ." as if the whole thing were one line, does anyone know a little trick for this ?

Lookup Fields
What would the code look like to do the following?
Say you were working with customer and order tables. You are entering a
new order, and key in the customer id in the orders table. Or even choose
from a dropdown. Now say you have several other fields about that customer
that you want filled in from the customer table, ie name, address, phone,
etc... Once that customerid is entered and a tab key is hit, how do you
have the other fields looked up and auto filled in in code?
Please be basic here, I am new to php programming. But the auto fill in is
wat I am trying to learn. By the way, I'm not looking for a short list type
of thing, assume the customer table has several thousand records. Ive
heard of doing thing this with ajax. Ok how? I have no idea how the code
would look. So far I'm only up to a simple flat file database. I'm trying
to learn more now. Please see this for a more detailed description of what
I'm after. http://www.codecomments.com/archive...5-9-623448.html

Search Across Two Fields?
Say i have two fields, first name an surname There is a person:

First Name = David
Surname = Jones

Could I make a search which would find this person whether David was entered or Jones was entered. i.e. what you put in the one search box would check both fields to see if this record was there. Also, say I search david Jones on the form, and it searches the first word from First Name and the second word form surname.

Query Used Over Two Fields...
Is it possible to make a query to find a field using another field of a table without using any user ID. Because basically i have:

House table
country Table

in country table i have "cityID" and in house table i have "cityID" so what i wanted to do was call up a variable as: $Country by using CityID in house table and searching that cityID in country table to find the country name and put it to "$Country"

can this be done using a query.. im only used to using queries using sessions of user ID this is the first time it wont use a session...

Passing Fields
I got a problem with passing parameters, and hope for some help. The problem is as below: I got a website, and would like to pass a field from one page to another. So forexample, if this is how the url will look like when someone comes into the site:

www.mysite.com?id=xxx

Then, there is a coding on the site:
$id = $_GET["id"];

and this allows me to get the id parameter and store it for use, so that on links in that page, I can just put:

www.mysite.com/linkpage2.php?id=<?echo $id ?>

and this will allow me to pass the id=xxx onto another page.

Now the problem is this. If suppose someone came and for some reason, the id=xxx field is missing. So their url will look like www.mysite.com. Now the $id = $_GET["id"] will give an empty field, and when someone hovers over the link, it will just show www.mysite.com/linkpage2.php?id= . Is there anyway to code it so that if $id is empty, as in this case, then it will automatically fill $id=noid or something similar, so that if someone hovers over the link, it will show www.mysite.com/linkpage2.php?id=noid . I tried putting this line in:

if ($id == "") {id == "noid";}

but it doesn't work. When hovering over the link, it still shows www.mysite.com/linkpage2.php?id= .

How Do You Get Required Fields In PHP
In HTML forms you use the 'required-value' to ensure that a field is completed before submission,  is there any way to do this check in PHP? If so could you please give me an example or a link to where to find it.

Adding Fields With PHP
Basically i have created a shopping cart in PHP but before that there is a page for the item and a selction of variables e.g. sizes and colours all with different prices, How would i go about having a total underneith that automatically calculates the total of the options the user selects?

Duplicating Fields
I would like to duplicate text fields and then insert that data into MySQL. So if I have one text field, I click for instance a plus sign and another text field appears.

Formatting Excel Fields Using Php
I have managed to create and excel file using php, I display the results in html and have a link to create the excel file. I need to format one of the fields as "text", is this possible?

Process Form Fields
Hi, I need to process a generic html-form. Is there any way to access to the form elemts as an array?

Stripslashes() And Text Fields
I have got a file that acts as an news edit form for people to edit info pulled from a database.

There are a few fields but specifically a title and a content field, both of which pull existing content from the db and set this as the initial value of the fields in the form.

When i echo these to the page i run the stripslashes function on both fields.

When both entries in the database have inverted commas stored in the fields only the text area will display them. The text field shows nothing. I have checked the table and the data is there stored correctly, (ran addslashes on ther way in).

I can echo them straight to the page but not to the text field. Strange?

The code is:

<td><input size="50" maxlength="250" type="text" name="auntyTitle" value="<? echo stripslashes($rows->auntyTitle); ?>"></td>
</tr>
<tr>
<td><textarea name="auntyContent" cols="40" rows="10"><? echo stripslashes($rows->auntyContent); ?></textarea></td>

Empty Fields For Every Record
If i have a table structure like in my attachment, how can i check for empty fields.That is, I want to check for every record in the table if lastname, street, zip, city and pwd are filled.

For example, in the second record that is with id no:2, street and city are empty.Similarly for the next record with id no:3, lastname,zip and pwd are empty.

So, idno:2 and idno:3 are incomplete.
Now, what i would like to do is, if i press a button, i want to send an e-mail to the respective e-mails which are in idno:2 and idno:3 that they need to fill their information again.

Could somebody please tell me how can i do this one?

Using Distinct With Other Fields In Same Query
I have a mysql db with a list of doctors in it. Each doctor has a unique medid, but can have multiple entries because they have different specialties and departments.

In generating a phone list, I need to pull their distinct medid's so that they aren't in the phone list twice, but dont seem to be able to generate a query that gives me the right results.

Here's a sample..

217 450 Neuroscience Neurology Abbott Faith
37 173 Medicine Allergy Akbar Raana W.
264 2 Radiology Interventional Radiology Akbar Jamal U.
279 2 Radiology Radiology Akbar Jamal U.

fields are uniqueid/medid/dept/specialty/lastname/firstname/middle

I have used "SELECT distinct medid .... " and that works, but as soon as the other fields are added, I get duplicate records.

Jamal Akbar, medid=2, should only have 1 record pulled.

Trying To Duplicate Form Fields.
What I would like is to when someone writes in one field. The same text is written in a seperate field. But without sending anything. all internally. Anyone have a clue?

Form Validation- One Of Three Fields
I've been looking for a PHP script to accept a search form for either the name or town or postcode fields to search a MySQL db. I would like the user to put in any one search field but not none.

Also I am trying to figure out a select statment to select one item on a drop down form list or any item on the list eg the list would be dog, cat, horse, fish or all, the column would be pets. The search would pull out any single pet or all pets.

Populate PDF Fields With PHP Variables
I have a HTML Form that needs to take the variables and place them into a PDF with the corresponding fields that I have created with acrobat. I guess there is a two-part question coming up.

1. What is the process of taking my HTML variables and placing them into the PDF fields in the PDF file I created?

2. Does PDFLib that I hear so much about accomplish this task?


Making Fields Equal
I have two tables in a database and I have an html form. The tables both include a field called id# and that's how I have linked the tables in my SQL statement. I would like to set up my form so that when someone enters an id# it will write the value to the id field in both tables. Does anyone have any idea how I'd go about doing this?

Empty Fields In Forms
I'm working on a script for a form for people to submit their info ( Name, e-mail, AIM, website URL etc). Now it is possible that some people don't have AIM or a website. I'm using a html table to display the info on the member page and empty fields make the table look strange. Is there a way to set some default value (like N/A) that would be displayed in case a field is left empty?

Testing If Two Fields Have Data In Them
Im trying to test if two fields have been entered at the same time
I have tried many combinations but cant get it. My last effort was

if(isset($_POST['Link'] && isset($_POST['uploadedfile'])){
die('You can't select to upload a link and a file at the same time.');
}
else
{
STUFF HERE;
}

but still cant get it to work.

Searching 2 Database Fields At Once....
How can i search two database fields at once. PHP Code:

Two Tables Selecting Fields
Suppose I have two tables A and B

Table A has fields A1, A2, A3, ... A9
Table B has fields B1, B2, B3, ... B9

I want to select all fields in A and only B3 in table B. I dont want to
list individual fields for A because they are too many I simply want to
use a *.

How do I do this?
I tried this way but they are not working
Select * from A1, B3 from B
Select *, B3 from A, B

Adding New Fields To PHPMYADMIN
How to you add a new field to an existing field on the PHPMYADMIN.. please help.

How To Check Empty Fields
If i have a table structure like in my attachment, how can i check for empty fields.That is, I want to check for every record in the table if lastname, street, zip, city and pwd are filled. For example, in the second record that is with id no:2, street and city are empty.Similarly for the next record with id no:3, lastname,zip and pwd are empty.

So, idno:2 and idno:3 are incomplete. Now, what i would like to do is, if i press a button, i want to send an e-mail to the respective e-mails which are in idno:2 and idno:3 that they need to fill their information again.

Fill In Form Fields On PDF
Looking for classes or libraries which allow you to fill in form
fields on a PDF document.

Updating Auto_increment Fields ?
I have a table with quiz questions. Each question has a unique ID, based on
an auto_increment field.
Now I've discovered that with deleting rows from the table the deleted ID's
are not reissued. Makes sense, just thought of that a bit late.

How can I simply re-index or update or how one would call it, the columns
holding the ID numbers ? Is there a ready-made mysql command or do I have to
load all rows in PHP and modify where necessary ?


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