Displaying MySQL Column Names Using PHP
I'd like to be able to display the column names of a table on a page. Is there a way to read that information in using SHOW? And then to display that information again? Or would I have to store these names in a seperate table and display these values?
I tried this, but it sure didn't work:
$result = mysql_query ("show columns from industries");
print ("<table>");
if ($row = mysql_fetch_array($result)) {
do {
print ("<tr><td bgcolor=#cccccc>");
print $row["field"];
print ("</td><td bgcolor=#cccc00>");
print $row["type"];
print ("</td><td bgcolor=#cccc00>");
print $row["null"];
print ("</tr>"); }
while($row = mysql_fetch_array($result)); }
else {print "Sorry, no records were found!";}
print ("</table>");
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Numeric Column Names In Mysql?
i am trying to create a table with a column name called 2004. But I keep getting a mysql error? Is there any workaround? Unable to execute: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near �� TEXT,2004_reference TEXT,2005 TEXT,2005_reference TEXT,200 CREATE TABLE test (id int(6) NOT NULL auto_increment, membership_number TEXT,first_name TEXT,last_name TEXT,spouse TEXT,phone_priv TEXT,phone_bus TEXT,address_street TEXT,addr_town TEXT,addr_city TEXT,membership TEXT,donor TEXT,1998sa TEXT,1999sa TEXT,2000sa TEXT,200s1 TEXT,2002sa TEXT,2003sa TEXT,2003_reference TEXT,2004 TEXT,2004_reference TEXT,2005 TEXT,2005_reference TEXT,2006 TEXT,2006_reference TEXT, PRIMARY KEY (id),UNIQUE id (id))
Column Names
how can i get the column names of ms access table?
Need Column Names, Not The Array Key...
I am running a script that exports a MySQL table into an excel file. The problem I am having is the column (header) names are not showing up in the final .xls file. I instead get the key value 0, 1, 2, etc. Here is the section of the code that should write the actual names. I can't figure out what's wrong. It looks good to me. Am I missing something? Code:
[ot] Using Original Column Names In Pages/forms
I just want to know if using the original column names in web forms is a good idea or is it better to use fake/alias names so those viewing the source will not get the original column names. However, alias names would add a level of complexity and might impact performance.
JOINING 2 Tables, Duplicate Column Names
I am trying to JOIN tables together to allow me to get data based on a lookup table: But it is displaying columns with identical column names as they are they same but from different tables. In this case its "module_id" and "student_id" being displayed twice. I have tried to edit it to only display one instance of each in the results, but am having no joy as yet. This wouldnt be such as problem but when I try and compare/pull the data with PHP identical column names (even if they contain the same data), wont PHP fall over? PHP Code:
Displaying Single Row For Same Column No
I have a table as follows: ---------------------------- Auth Name | Paper No ----------------------------- Gupta 7 Daiya 7 Daiya 8 I want the above table to look like if two rows have the same paper no ----------------------------------------- Auth Name | Paper No | Paper No ------------------------------------------- Gupta 7 Daiya 7 8 Can you please modify the below code: if ($result){ echo "<table border=1>"; echo "<tr><td><b>Author Name</b></td><td> <b>Paper No</b></td></tr>"; $numOfRows = mysql_num_rows ($result); for ($i = 0; $i < $numOfRows; $i++){ $name = mysql_result ($result, $i, "aname"); $email = mysql_result ($result, $i, "apno"); echo "<tr><td>$name</td><td><a href="abstract/$name.pdf">$email</a></td></tr>";} echo "</table>";}
Displaying Information In A 1 Row/2 Column Table
I'm very new to php scripting and haven't quite figured out what I need to do here. I need to display information in a 1 row/2 column table. I have the MySQL query working fine, but the scripting part in php is killing me! In the first column a graphic about 70x70 will be shown (plus some additional padding). In the second column will be the description information. The second column will be around 400 pixels wide. How do I set this up in php? It's easy enough in HTML, but I've about killed myself trying to figure out how to properly lay this out in php!
Problem Displaying One Column Of One Row From A Database With PHP.
I have a small script with PHP that queries a MySQL database to pull out one row, where I want to be able to access each of the columns separately. I have tried several different variations and am able to get the entire row to print, but when I attempt to access the individual columns I get an error. Here is what I have so far: if (isset($_POST['memberNo'])): $link = mysql_connect('...','...','...'); mysql_select_db("..."); //Perform a test query $query = "SELECT * FROM users WHERE 'id' = " . $_POST['memberNo']; $result = mysql_query($query) or die(mysql_error()); $line = mysql_fetch_assoc($result); print $line; //Close connection mysql_close($link); The point of this code is to retrieve the user information to validate the login information sent in the previous form. I do not get an error with this code, but it also does not print anything. I know there is an entry in the database that matches data sent in the $_POST['memberNo'] variable, it is the only entry in the database. Changing the 'print $line;' to 'print $line["id"];' does not display anyting either.
Displaying SQL Query Results In 3 Column Table
I would like to be able to display the results of an sql query in an html table, but the results need to be displayed in three columns, for example: Column 1 Column 2 Column 3 Result 1 Result 2 Result 3 Result 4 Result 5 Result 6 Result 7 Result 8 Result 9 I've tried to find the answers on the internet but i can't find anything that suits my needs!
MySql Column ??
What i want to do is this. I have an field in one of my database tables with money price of product, i want to display the total amount of the table, i try to use "select sum(fieldname) from table where" but is not working.
Counting Names In Mysql Database
I want is to have the number aof how many times a name is existing in a table_row. you know, my tably is like this status author text: 1 dominik hasjfghkasdfhsk 1 dominik djwkhflwjfv 1 egon jdskljfsldjf I want php to count dominik and view the result on a php-page.l
Setting Variable Names Using Field Names?
I'm having trouble creating dynamic variables using field names. Basically I got a heap of fields named after Players and I want to grab the field name and make a variable called it while assigning it a value from a post variable which is also the player name. This is the code I'm using: $result=mysql_query("SELECT * FROM playerstats"); while($fld = mysql_fetch_field($result)) { if ($fld->name!='match_id' && $fld->name!='opponent' && $fld->name!='map') { $fld->name=$_POST[$fld->name]; } }
PHP Code For Max Val In A Column In Mysql
I am trying to display the maximum value of a field called 'quesid' when the value of a other field 'id' is 15...i have to do this in php..i have to display this max value...
MySQL Select From (no Column)
Is it possible to select from a table using WHERE without putting in a column name? Kind of like this: mysql_query("select * from flights WHERE LIKE '{$searchfield}'");
Alter A MySQL Column With Php
I have a table named sentcards with a field called cardid with a current type int... I wish to change the type int to bigint(30) with an attribute that is unassisgned and a default of 0... This is my code:
Print Out A List Of All Mysql Field Names
I'm trying to make a drop down menu which has got a list of all field names that are in a database so you can do a search in each field seperatly but i can't find out how to do it.. can it be done with mysql_field_name and if so then anyone knows how ??
Loading A MySQL Column Into An Array
ok i have a forum i am creating and i store the id of the forums where people are moderators in their userinfo. i speperate them with a comma. i need to either load them into an array or use explode() but i'm not sure how to create the array. i'm thinking that using an array would be faster because i could search in it to find out if the user is a mod.
Check If Column In Mysql Exists With Php
I wanted to know if you can let php check if a column exists in a table. cuz i have a 1 script script and i want it to check a table for having the following columns and if 1 o fthem is missing it would automaticly add the column.
Get Mysql Unique Column Fields
I have data with the field name "monthyear" and I am trying to get a list of all the different field names without repeating like "may2003, january2001, june2002", this is for my news script i am making, im going to use it to make an archives page which is organized by month any ideas?
Should I Add A Multi Column Index To MySQL?
I have a mysql table. Two columns in the table are used to pull out stories from the table. One of the columns stands for categories of the stories, and the other column is the primary key and has the id for each story. I am thinking of writing queries like this: mysql_query("SELECT * FROM articles WHERE category='Science_Fiction' AND story_id=ཀྵ'"); I am wondering if I should create a multi column index that covers both "categories" and "story_id" columns. -- INDEX (categories, story_id) Would this increase performance?
Question About Datetime Column In Mysql
i tried this question in the mysql group, but have not heard anything. i have a database with about 20 tables. The some of these tables have datetime type columns in them. What i am basically wondering is if there is a way to make a default value of now() apply if it is not specified when the row is created. i know this is possible with a timestamp, but is it possible with a datetime column ? and if so, how ?
MySQL, Turn Column Into Array
Today is the first time I've used MySQL with PHP. What is the best way to turn a column into an array? This is how I am doing it at the moment, surely this is sub-optimal: $query = 'SELECT something FROM table' $result = mysql_query( $query ); $i = 0; while( $arrayTemp = mysql_fetch_array( $result ) ) { $array[ $i++ ] = $arrayTemp[ 0 ]; } echo "<ul>"; foreach( $array as $string ) { echo "<li>$string</li>"; } echo "</ul>";
Exclude A Column From A Mysql Command
Is there a way to exclude one specific column in a mysql database from a command. IE: I want to use the command $sql = "TRUNCATE TABLE DailyDataSF_copy"; But have it affect all columns except just one specified column that'll stay the same. Any solutions to this? The table has like 90+ columns, which is why I'd like to do it this way if at all possible.
Results Of Same Field Names But Different Tables In MySQL Query.
I have a SQL string with a couple of JOINs that works perfectly in command prompt. I get results for all the fields selected just fine. But when I put it into a PHP page, I can't make variables(?) out of fields that have the same field name from different tables. Here's the SQL statement: $sql = "SELECT orders.companyid,orders.ordernum,orders.address,tb l_ih_accounts.company,tbl_ih_accounts.address FROM orderstatus ". "LEFT JOIN orders ON (orderstatus.ordernum = orders.ordernum) ". "LEFT JOIN tbl_ih_accounts ON (tbl_ih_accounts.id = ihid) ". "WHERE submitted <> 'yes' ORDER BY orders.ordernum ASC"; Then in the "WHILE" clause after the database is queried: $o_address = $row[orders.address]; $ih_address = $row[tbl_ih_accounts.address]; I've tried it without the table names in the $row statements, but then I'll just get the results for tbl_ih_accounts.address. I'm thinking there must be some way to uniquely "name" the results of a particular field up in the SQL statement, and then just use that unique name in the WHILE. But I have no clue, and can't find anything about anything like that.
Searching A Mysql Column Against Multiple Variables
I have an array of zipcodes which I am trying to check against a mysql table. I want to search in the column "zipcode" in a table of a bunch of entries. I want to search each rown to see if the value of the zipcode column is listed within my array. This could be said vis vera, that I want to check the mysql table to see if any of the rows have one of the values from the array inside the zipcode column. I've tried the statement "select * from table where zipcode IN ('$zipsearch')", but it seems to return an odd sequence of data. It doesn't seem thurow enough. similarly the entire statement is : select * from table where description like "%$trimmed%" OR title like "%$trimmed%" AND zipcode IN ('$zipsearch') order by date" I can't seem to get the statemtent to break up my requests right so that the logistics of teh statement are : select from table where (descriptions like variable or title like variable) AND <zipcode search problem>
How To Display Newly Added Mysql Column
I have a mysql table and i want the user to add columns using a php interface and then display the table with the newly added column. I was thinking about putting all the columns names in a special table but there must be another more efficient way. as an example this is my query to display the table: $result = mysql_query("select * from news"); while($r=mysql_fetch_array($result)) { $title=$r["title"]; $message=$r["message"]; //display the row echo "$title <br> $message <br>"; } now if the user alter the table and add a column "rank", how can i update my query automatically so it can display the newly added row (or column)?
MySQL Query Returning Empty Column
Here's my code: $query_get_machine = sprintf("SELECT machines.ID, machines.NotifyID, machines.Name, notify.ID, notify.`Data` FROM machines RIGHT JOIN notify ON machines.notifyID = notify.ID WHERE machines.ID = %s", GetSQLValueString($colname_get_machine, "int")); Can anyone tell why the notify.`Data` column might be returned empty? All others display as they should.
Select Single Column From Mysql Into Array
Is there a way to select a single column from a mysql database and directly put the results into an arrray? Here is the workaround below, but I would like to elimniate the array_push step: $uids=array(); $res = mysql_db_query("db", 'select uid from tbl;', $link); while ($row = mysql_fetch_row($res)) { array_push ($uids, $row[0]); }
MySql VCHAR Column Converted To Float By PHP :-(
I fetch the following value from a string (VCAHR(250))colmun in a MySql table: "30000000000000000000000000000000000000000000000000 0" When I write it out using echo() I get : 3E+50 Appearently the PHP interpreter converts the VCAHR value automatically in a float despite the fact that the value is defined as a VCAHR in MySql. While trying to convert float to string back in PHP using type casting or settype() I get always the string "3E+50". Does someone know how one can fetch the VCHAR as string? Does someone know how to print a formatted float to get the desired result? I tried printf() but no success.
MySql Error 'Unknown Column' From PHP Variable
I'm getting an error message that makes no sense to me. I have a table with a field named 'testkey' for a list of "keys" in the form of ABC10102. I have a php variable holding a specific key number. The relevant code is - $_testkey = 'LAL10102' $sql = "SELECT * FROM `pro_keys` WHERE `keynum`=`$_testkey`"; $result=mysql_query($sql,$db_conn); echoing the $sql gives - SELECT * FROM `pro_keys` WHERE `keynum`=`LAL10102` But I get the following error - MySQL error #1054 - Unknown column 'LAL10102' in 'where clause' ?
Comparing Values Of 2 Arrays Combined With Mysql Field Names
I am trying to create an edithistory table that has a text column into which I will put a string that can be read using strtok later to revert changes if necessary. I want to build this function so that it's dynamic enough to be applied to every table so that I don't have to write one for each table that might be updated. When a row is added to any table (a new entry), it retrieves the next available editid # from the edithistory table and assigns it to that item in the "edits" column for its row in its own table. Every edit made is a new entry in the edithistory table (entryid auto_increment primary key), and the editid is a reference back to the object being edited. Code:
Valid MySQL Database/table/column Name Regexp
regular expression in PHP which could be used to check that a proposed (My)SQL database/table/column name is valid, i.e. shouldn't result in an SQL error when created? The user of my (hopefully to be opensourced) program has the ability to create database/table/column names on the fly. I'm aware of obvious characters such as ., [space], things like >, etc., which won't work, but haven't been able to source a definitive list, including having googled the MySQL site. Obviously certain characters need to be filtered out, as noted above, but I want to be as unrestrictive as possible; hence just [a-z]* isn't good enough because things like _ are acceptable. Ideally, I'd prefer a regexp that applies to _all_ vendors' databases, not just MySQL as I'm about to migrate the program to being database-independent, probably using PEAR DB, but even a MySQL-specific regexp would do the job. In the longer term, I plan some sort of entity conversion script so that theoretically any character could be used, using some sort of escaping mechanism probably.
MySQL Query - INSERT - Unknown Column 'test' In 'where Clause'
I have a registration script on my website, and it was working fine, I added a second MySQL INSERT query to it, for another table so I can use JOIN's later on with the second table, but I keep getting the same error: Unknown column 'test' in 'where clause' can someone see whats wrong with this? Code:
How To Query From One Column Then Sort Using Another Column
I am trying to get the last 100 albums I entered into my database using the album_id (Highest being the latest entry) then sort them alphabetically using the album_title column. I can get the latest 100 easily but cannot figure out how to also sort the results by the album_title before I display them. This is what I have so far which gets what I want but not in alphabetical order. <?php $sqlquery = mysql_query("SELECT * FROM albums ORDER BY album_id desc limit 100", $db); while ($result = mysql_fetch_row($sqlquery)) { echo "<a href='music_info.php?album_id=$result[0]'><span style='text-decoration: none'>$result[1]</span><br></a>"; } ?> I have been trying to add a second ORDER BY to the query like so. $sqlquery = mysql_query("SELECT * FROM albums ORDER BY album_id desc limit 100 ORDER BY album_title", $db); but this obviously isn't the way I should be doing it.
PHP, MySQL And Displaying JPG Images
I got a script that is supposed to display a JPG image from the database, but, instead of displaying the image, it displays the JPG binary output with those alphanumeric characters. Coule this be a Header MIMI type problem in my script?
Displaying A MySQL String Using PHP
I've got a multiline string of data held in a MySQL database. I can extract the data using PHP and display it on the screen but when I do so, the string loses all of its formatting (i.e. The carriage returns and line breaks get lost and the string is placed all on one line). How can I display the string correctly without using a <pre> tag and without putting the string into a <textarea>.
Displaying MySQL Tables
I am creating a database that allows anyone to fill out a form and be added to the MySQL database. My problem is, I can't see who has been added. Could anyone please help me with the PHP code for this? I have tried the following: PHP Code:
Displaying Mysql Querry
I have problem displaying this mysql table from datbase: I need to show column hrt1 from table hrt order by id CREATE TABLE hrt ( id int(11) NOT NULL auto_increment, hrt1 varchar(255) NOT NULL default '', hrt2 varchar(255) NOT NULL default '', hrt3 varchar(255) NOT NULL default '', PRIMARY KEY (id) ) TYPE=MyISAM; I tried this but it isn't working: PHP Code:
Displaying An Image From A MYSQL DB
Can someone point me in the right direction as to display an image in PHP that is being stored in MySQL? Basically I know how to store the image in MySQL, but getting it to display on a web page is what I am having trouble with.
Displaying The Top 4 Mysql Database's
I was wondering how I would Display the top 4 mysql database's? I was thinking of using the switch function but I don't know what the variable would be.
Displaying Text From MySQL
I am working on a very simple news page for a website. I've setup a simple form that writes news to my database and the data is then displayed on my news page. I have gotten everything to work successfully but the content in the article loses all its paragraph formatting when I try to display it. I can use break tags to make the formatting show up but there has to be an easier way. This is the code I am using now, which I found on a tutorial somewhere and then tried to modify to work for my site: Code:
|