Alter Column Name In Query (mysql)
is there any way to alter the column name in the query when fetching an array (mysql)
View Complete Forum Thread with Replies
Related Forum Messages:
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:
View Replies !
Alter Table If Field Or Column Not Exist
Myscript should alter the table if the field or column not exists. I try this but its not working. fieldname = image $DB->query("ALTER TABLE `p17_sections` ADD `image` VARCHAR( 24 ) NOT NULL AFTER `sorting` If not exists");
View Replies !
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.
View Replies !
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.
View Replies !
Mysql Field ALTER To Decimal(10,2)
I have a sql statement generated by phpmyadmin where i changed the field value of a table from "float" to "decimal(10,2)". here it is: ALTER TABLE `BMG` CHANGE `I_PLQ` `I_PLQ` DECIMAL( 10, 2 ) DEFAULT Ɔ' but i need it to also round the existing values up. for example: 2.4875 to 2.49 but for some reason it rounded it to 2.48, and i don't know how to change the statement so it will round values up for existing values in the field. is this even possible? if not, how would you handle it?
View Replies !
How To Query One Column?
this is php mysql query script from the patients table register, i want when i enter one value for example for sex m (male),the script will show only male patients all rows,but this script show all the registered parients in any query Code:
View Replies !
My Query Of A Column Only Returns One Value
I have no idea why this query doesn't work. It only returns one value from the column "groupname," but it should return every value. It does not die and return any of the errors though. I'm pretty sure the SQL is fine, so I think it must be the php somewhere, but I have been working on this for a while, so I have checked it quite a few number of times already. Code:
View Replies !
Search Multiple Column Query
I have some code, this isn't all of it, I figured this is the bit I need to change : $query = "select * from companies where company like "%$trimmed%"  order by company" I want it to search multiple column like 'tel' as well as 'company' I've tried: $query = "select * from companies where company, tel like "%$trimmed%"  order by company" But doenst seem to work. Can anyone tell me what to change or should I post the rest of the code so someone can help?
View Replies !
Invalid Query: Unknown Column
I'm getting this a strange MySQL error that I have never seen before. I have the following code: Code: $labelQuery = "SELECT ID FROM labels WHERE name = $mylabel"; $labelResult = mysql_query($labelQuery) or die("Invalid query: " . mysql_error().__LINE__); Which produces the following error message: Code: Invalid query: Unknown column Ɖp' in 'where clause‘Ë The strange thing is that Ɖp' is not the column name, but rather the criteria that i am using for the 'name' column. The $mylabel variable is fetched from another query run earlier as: Code: $mylabel = $row['label'];
View Replies !
Determining Which Column The Query Was Found In
I'm allowing a query which searches across multiple columns -- and it does work, but since this is a "wildcard" type search where the query (say "foo") could be in any or all of the columns searched, how do I determine which column the hit(s) was/were in. I need this so I when I jump into the for loop I row out the results properly? Code:
View Replies !
Adding Values In One Column From Query Results
I have this query: SELECT *, sum(field_value) as totalValue FROM table_name WHERE field_id = $id GROUP BY field_group the data type of field value is a decimal value, with values such as 125.00 and 150.50 stored in each record. My goal is to have totalValue be the total value of those numbers. So if I have two records that equal 125.00 and 150.50 totalValue would = 175.50. the above query does not do this. What do I need to change here? Should I try to do this from the PHP side?
View Replies !
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!
View Replies !
Query Wildcarding A Joined Table Column?
I've got 2 tables (say t1, and t2), and this works fine and as expected: SELECT * from t1, t2 WHERE t1.columnX = t1.columnY However, I would like to do the following: SELECT * from t1, t2 WHERE t1.columnX LIKE '%t1.columnY%' I believe as written, t1.columnY is used as a string, and thus not what I want (want wildcards prepended/appended to column value). Is there a way to make this wildcard search work?
View Replies !
Query That Stores Column Headers From .csv File In Variables
I have not been able to figure out how to capture the column headings from a file on my web server in variables to be used in a .php script. For example. File Headers: ID, NAME, OCCUPATION, DATE I would like a script that would grab those headers in a file and store them in variables: $ID=ID $NAME=NAME $OCCUPATION=OCCUPATION $DATE=DATE
View Replies !
Invalid Query: Unknown Column In 'field List'
I'm getting this error when I execute my form and it brings up the corresponding .php page. Invalid query: Unknown column 'DCS' in 'field list' Whole query: SELECT DCS#, CLIREF, GUAR, PAT, ADDR1, ADDR2, CITY, ST, ZIP, SS#, DOB, PHONE, DBAL, TBAL, PAID FROM crossroads10 WHERE CLIREF='ZQ02037/8558' Here is my code:
View Replies !
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.
View Replies !
Mysql Add Column
$date = date("F j, Y"); $new = "ALTER TABLE closing ADD May 9, 2007 VARCHAR(30) NOT NULL;"; Is this wrong? mysql says : 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 Ə, 2007 VARCHAR(30) NOT NULL' at line 1 Whts The prob?
View Replies !
MySQL Column
I was looking through the WordPress (blog platform) database structure and was curious about something: for the user table, the id column is bigint(20) and for the post table, the associated user id column is int(4). I was just wondering if the two columns are different types for a specific reason, since it seems they hold the same info.
View Replies !
Mysql Longtext Column
I have a column in a mysql table defined as longtext data type. I am trying to search for key words using php. I know that mysql indexes the first 1k (1024 chars) of data but I can't seem to even search the first byte.
View Replies !
MYSQL TEXT Column
I have a table in mysql with this column called 'keywords'. in eah row, the keywords column consists of a set of words separated by spaces, ex: row1 keywords = 'stuff boing foo'. row3's keywords column might contain SOME of the keywords that were in row1's keywords, and it might contain a few others too. I want to query the table and get a php array of all the UNIQUE keywords in the entire table -- in other words I don't want to have any duplicates in the array.
View Replies !
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.
View Replies !
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 Replies !
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.
View Replies !
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?
View Replies !
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?
View Replies !
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))
View Replies !
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 ?
View Replies !
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>";
View Replies !
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.
View Replies !
MySQL Order By For Varchar Column
I have a VARCHAR column where most rows start with numbers; however, a few rows start with letters. I have ordered the rows to appear in descending order. SELECT * FROM db ORDER BY varcharcolumn DESC With this query the numbers appear in the desired order, but the letters appear before the numbers. This order makes sense based on my query but I don't want the letters before the numbers. Is there a way to force the letters to appear after the numbers?
View Replies !
MySQL Multi-column Indexes
I'm setting up indexes for a number of mysql tables. In some cases, these multi-column indexes (of type INDEX) include the primary key. For instance, in table Users, where pkey is UserID, I also have a two-column index on UserID and UserType (to accommodate queries that look at both these values). phpMyAdmin is complaining that "Primary and Index keys should not both be set for column "UserID" I'm wondering what I should do - do I leave UserID out and just index UserType (and assume that MySQL will use both indexes)? Or is phpMyAdmin wrong?
View Replies !
Column Values Into MySQL Textfile
I have a list of email addresses which I would like to insert into a MySQL (version 2.6.0) table which has the fields id, username, pw, email, lastupdated. Is there a way to adapt the following code to insert all of them at once. I basically want to ignore id, username,pw, lastupdated. INSERT INTO mail(email) VALUES ('bob@bob.com'); INSERT INTO mail(email) VALUES ('geoff@geoff.com');
View Replies !
Variable As Column Name In MySQL Statement
Let's say db has 4 cols: user id, favorite color, shoe size, hair color. User only has the option of entering 2 variables. 1 has to be user id, 2nd one (radio button) can be color OR size OR hair color. Depending on what user entered, php should look up user id #, and then locate parameter under variable 2 col (whatever was entered for variable 2: fave color or shoe size or hair color) that belongs to that user id.
View Replies !
MySQL Auto-increment Id Column
need to set-up a mySQL database with a unique id, so I can have an update section. I have a site with a "events" page (a list of events, date, event name and event description) I have a form with 3 fields (date, name and description)... I need to do 4 things... insert records (not a problem) display records (not a problem) update records (can't figure how to update, need id)
View Replies !
How To Display Each Mysql Row In A Table Column
After I retrieved 3 rows from my mysql product database, I want to display each row in its own column, similar to what you see on this product comparison page. Each row also contains 15 different specs, FYI. reviews.cnet.com/4504-5_7-0.html?id=30569389&id=20536585&id=30525842&id=30527150&tag=compare I know how to display mysql result on a page, but this format presents major difficulty for someone with limited PHP knowledge like myself.
View Replies !
MySQL Number Of Rows In A Column
I have small problem with mysql, i have a large database and one table suppose to have 70 000 rows unfortunately it fits only 65535, i can't add more its seems to be a limit. Is this a hosting setting or is this just a MySQL (or any database) limit?
View Replies !
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>
View Replies !
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)?
View Replies !
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]); }
View Replies !
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.
View Replies !
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' ?
View Replies !
|