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




MySQL Field Type For Arrays


What type of field type are arrays stuffed into? VARCHAR ? TEXT?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Determining Type Of MySQL Field.
I have a problem of migrating a database from one host to another.
I can't do a dump on the source server. The only access I have is thru
queries. So it looks like I'm going to have to query all the
tables and insert to the destination.

I'm trying to come up with a general solution to this problem which
uses queries to determine the structure of the source db, and create
the tables on the destination, which I've already done using the nice
"show create table" query syntax combined with the PHP
mysql_list_tables() function.

The problem comes with doing the inserts. It looks like I'm going to
have to do a "select * from table" thing and then loop thru the
recordset doing insert after insert.

Q: Do I have to do it that way? Is there a way I can insert all the
records from source to destination more efficiently?

Q: How can I determine the type of value in a field returned from
a query? PHP's is_string returns true on ALL fields regardless of type
used in the database itself. I need to know whether to wrap the values
in quotes or not before I insert them.

I'd like to be able to at least fetch a record and insert the record
without having to process it. I'd like to grab the whole table and
insert it, but haven't a clue how to do this.

Q: Is there some kind of select/fetch that I can do that will give me a
record ready to insert i.e. with commas and quotes?

Best MySQL Field Type For Unix Timestamp?
What do you recommend as the best type of field for a timestamp in a MySQL
database? I've considered varchar(10) or INT but I'm not sure what is the
best, most efficient, and most reliable field type.

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:

Is There A Universal Field Type?
Is there a field that will accept any type of data? like varchar, blob, or any special combination, that will hold the data I insert into a table... exactly as it was entered (including quotes ' and "). .. and not let mysql parse through it?

Determine Field Type
When a form is submitted I can get the field names and the entered values with $_POST, but is there a way to determine what type of field?  For instance, can I determine if a field was a textarea or an input field?

Read Mssql Field Type From Php
this question is 50% mssql and 50% php. To get field definitions and other
informations for table 'myTable', I use with sql server:

EXEC sp_help myTable

The problem with php is this command returns several result sets, and
informations about field types is not in the first one. If I query mssql
from php and fetch result, I only get informations about the first one, and
php completetly ignores the other one.

Is there a mean to read other result sets, or is there another sql command
that returns field definition?

Changing Form's Field Input Type
We have the form which uses checkboxes for several fields and the target
action points to outside webservice. Unfortunatelly they do not support
checkboxes. How to pass it as a radio buttons or pull down select box with
Yes/No options for example (which they support) using still checkboxes as an
input entry.

Problems Sending Arrays By Form When Type=checkbox
I have a problem when I try to send an array using a form when
the type="checkbox".

This is my form input row:

<INPUT type="Checkbox" name="flg[]" value="y" <? if($row['flag'] ==
'y') echo 'CHECKED' ?>>

Since this is an update form, I set the status of the flg[] according
to the field "flag" stored in a MySQL database. The user may check or
uncheck each of the checkboxes on the form.

This form is sent to another PHP file with other fileds of type
<SELECT> and type="Text". Here's the code which process the checkbox
input:

$max_i = count($flg);
for($i=0;$i<$max_i;$i++)
{
if($flg[$i] == 'y')
{
$flag = 'y'
}
else
{
$flag = 'n'
}
echo $i.'-->'.$flg[$i].'-->'.$flag.'<BR>'
}

I have no problems processing the array associated with the SELECT
and "Text" fileds, but when I try using the Checkbox, this is what I
receive:

0-->y-->y
1-->y-->y
2-->y-->y
3-->y-->y
4-->y-->y
5-->y-->y

Trying with this other code:

$num_of_checkbox_fileds = 12;

for($i=0;$i<$num_of_checkbox_fileds;$i++)
{
if($flg[$i] == 'y')
{
$flag = 'y'
}
else
{
$flag = 'n'
}
echo $i.'-->'.$flg[$i].'-->'.$flag.'<BR>'
}

I receive this output:

0-->y-->y
1-->y-->y
2-->y-->y
3-->y-->y
4-->y-->y
5-->y-->y
6-->-->n
7-->-->n
8-->-->n
9-->-->n
10-->-->n
11-->-->n

Help On A Multiple Keyword Search On A TEXT Field Type
Working on a php/mysql driven site which requires me to have a search facility based on multiple keywords. I read the tutorial "quick and dirty search engine". What i want to know is :

1. Is there any SQL query i could perform which could to almost the same thing ( i dont really need the accuracy ) ?

2. Any other methods of achieving it?

Check What Type (integer, String Etc) A Database Field Is
If i have a datebase field like so:

$username = $row['username']; //after SELECT and mysql_query etc.

how do i check what file type it is? i have tried using is_string to
check it but it returns all fields back as strings, even the ones i
know are integers. i would like something that would tell me the data
tyle (integer, varchar, text etc). are there any other ways or am i
doing this wrong?

Show Stored Value For Form Field Type=file
I have a file-uploading form to uploads a .jpg file and stores its name in a table in my db as co_bannerfile. I'm trying to now write an update form so the user can update their .jpg file. I've successfully written a query to retrieve the stored file's name.

How can I display the stored file's name so the user can see its name within the input TYPE="file" field and then decide to update it or not? The following doesn't display the stored file name. What do I have wrong? Code:

Save Date To Table Field Date Type
I have a calendar picker on a form that fills a text box with  XX/XX/XXXX  date format. If I run a insert statement  the date field in the database shows 0000-00-00. If i change the field type to varchar  the correct format displays. 

What is the correct way to save a date to a mysql database?  Furthermore to query on the date  how about a select * from db_name where servicedate >= $startdate  and  servicedate >= $enddate  I supose this will not work
Any pointers?

Select Both Field Name And Field Value- Mysql ?
What function to use to select both field name and field value from a mysql table ?

Mysql Row Type?
what do I have to set a mysql row to, too be rank them in order when the numbers in the database are &#390;.00' format?

FILE Type For MySQL ?
Is there a FILE type in MySQL??? to store files as a column in a registry of certain table?

MYSQL BOOL TYPE
Im trying to make a setion in my table, true or false, but when i try to make it i get an error. this is what i do and the mistake they say i did. not totaly sure what it means, im using phpmyadmin: SQL query:

ALTER TABLE `user_info` CHANGE `active` `active` BOOL( 5 ) NOT NULL

MySQL said: Documentation #1064 - 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 '(5) NOT NULL' at line 1

Mysql Data Type Int(10)
i understand that int is 4 bytes, but what does the (10) means?

MySQL Date Type Vs Varchar In Php..?
What are the real advantages and disadvantages behind using varchar length 15 and populating it with a date using date("m/d/Y") opposed to using a date type field.

When you store a date weather it be of Date or Varchar type the date is the same example:01/01/2002. The only difference I can see is how you search or retrieve data. With SELECT staements it seems to be a piece of cake either way. Just a cariousity question becuase I was told if you are going to search using dates you should make it a date field but I really do not see the difference. In some languages using a Date type field can actually come back to huant you later when you need to take the date out and leave it blank or NULL. (Like VB as a front end with access as a backend).

Dynamically Checking Mysql Row Type
Is it possible to check the types of columns in a mysql resultset so you
don't need to know the type of data returned beforehand?

I'd like to be able to do something like:

if($coltype == "datetime") {
// parse date
}else if ($coltype == "varchar") {
// parse string
}

Determining Mime Type Of MySQL Blob?
Is there any PHP function that will allow me to determine the MIME type
of a blob stored in MySQL?

Specifically, if I'm storing an image as a blob in MySQL, is there any
PHP function that can determine whether it's a gif, jpeg, png, etc?

Column Data-Type For Storing Serialized Array In MySQL?
I'm really not sure - I used BLOB in the past- but the arrays are only a few kilobytes. But VARHCAR only allows 255 characters at most and the arrays might contain many more characters than that.

Form Type=submit Vs Type=image
I'm wanting to create a form with quite a few SUBMIT buttons that use an image rather then the stock (plain grey) button. Everything works fine when I use this line:

print "<INPUT TYPE="submit" NAME="editaction" VALUE=$id>";

I know which SUBMIT button was pressed by checking the value of $editaction in the receiving page. Now if I replace that line with this one:

print "<INPUT TYPE="image" SRC="icon.gif" NAME="editaction" VALUE=$id>";

I no longer get a value in $editaction. I know about $editaction_x and $editaction_y. Is there no way get to the 'VALUE' (from the VALUE=$id part) as well? Am I missing something? Has the variable name been modified to somthing like $editaction_value?

TIA for any light you can shed.

Arrays In MySQL
Can I store an array into an SQL database and then take it back out and it would still be an array?

Arrays Into Mysql
The mysterious message: Couldn't add data to the CATLINK table:Unknown column 'Manufacturing' in 'field list' PHP Code:

MySQL Query And Arrays
I have a 'links' category on Table A and I want to retrieve the links from the Table and display them in a list-like fashion when the page is called upon. How would I go about seperating the links from one another (there a space inbetween each link.. EXAMPLE: http://asdf.com http://asdasd.com http://asdfff.com), loading them into an array (or using the best possible method to acces them easily) and then displaying them in a list like fashion..?

Arrays And MySQL Querys
I can't get an $array[key] to be used as a select query on a mySQL database.

I have a 'parts list' which displays on a page (works fine) and is a form.
At the end of each row is a input type='text' (quantity) cell with a default
0

The quantity can be altered.
At the bottom of the table (form) is a submit to basket Button

echo "<form action='basket.php' method='POST'>....

Arrays And While Mysql Functions
How can I get this array to work? I am trying to add data to an array for every row of data? This is a sellection of queries that I need to parse into an array so a function can use the arra to draw a graph. I am new to arrays how can I get this to work? Code:

Arrays Working With MySQL
How can I grab a certain field of a Multi-Dimensional Array using the ID. I have set for that Array? I just want to be able to create a simple function to do pretty much what this function does, but for an array. Code:

PHP, MySQL And BIT Field
my MySQL table contains bit field

Registered BIT(1) NOT NULL DEFAULT 0

I read records using

$result = mysql_query('SELECT * FROM MyUsers');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$registered = $row['Registered'];

Command "echo $registered;" shows nothing or rectangles depending on the
value, it's ok. But I do not know how to use it in IF statements or so.
Whatever I try does not work. How can I work with such values in PHP?

Passing PHP Arrays To Mysql Best Solution
I am relatively new to PHP and until now I have only needed to use relatively simple php/mysql solutions.

I am working on a problem where I need to store CD information (Artist Name, Album Name, Track Names, Catalog Number)

I am working on a solution with two tables "album" and "tracks" and I am using the catalog number as a key to link the two.

The problem I am having is coming up with the best way to populate the tracks table as there are several tracks for each release. I am assuming that an array would be the correct way and maybe a dynamic form to input the tracks where you decide the number you need to add and this then creates a form with "n" input boxes?

Insert Multiple Arrays Into Mysql
I am having problems writing the code to generate my SQL INSERT query. I have 3 arrays and one static variable ($cat_number):

$track_name[]
$music_link[]
$track_number[]
$cat_number

Should I be using a foreach command. I know how to insert multiple values but its generating the query that i'm not sure about.

INSERT INTO table (track_name, music_link, cat_number, track_number)
VALUES
(var1,var2,var3,var4),
(var5,var6,var7,var8),
(var9,var10,var11,var12);

I don't want to store the actual array in the dataabase, I am just using an array to catch the data.

Multiple Arrays And Foreach To Put Into A Mysql Db?
I created 3 arrays with data and i want to insert them i a mysql db. PHP Code:

Multiple Selections, Arrays, And MySQL
OK this place has been great with explaining things that are way over my head, now I could use a boost to get my brain working again. I have a form with a drop down menu with multiple selections. When the form is submitted it shows up in the DB field as "array", as well as the page where I how the form's info. I think I have to set up an array, and loop(?) it, or do I need to implode the array? And how and where would I put these commands on this incredible messy form page. Would someone mind helping me get started?

Here's the form: (please don't make fun of me, I used to a Dreamweaver extension to create the form using PHP, before I decided to try and write this stuff myself. I am re-doing the form but this actually works for now, so I am using it. Code:

Sorting Arrays Retrieved From A MySQL Db
I am trying to make a news system. I have done it, but the news are listed with the last on at the bottom. This makes it kind of troublesome to read the latest news when you enter the site and there are a lot of news items, cause you would have to scroll down.
PHP Code:

Populating Arrays From MySQL Query
I have the following code: http://pastebin.com/746601

The field 'material' in 'is_material' contains multiple values for each
record in 'is_details'. Because of this I have used
'is_material_lookup' as a reference lookup table containing the
'style_code' and 'material_code' which refer to their full details in
the respective tables.

Currently I have got the script outputting all the details and one
material then in the next block of data, repeating the details with a
different material. What I would like to achieve is having 1 block of
data with a list of all materials in that, instead of the repeat, but
sadly I can't know exactly how to do it.

How To Insert Arrays Into Mysql Database
This is my order.php file. Now I try to make a new php-file for processing the ordered items on this page, into another table "ordered_products" in the database. I want to INPUT following values into the table "ordered_products":
'order_num', 'order_item' and 'order_ant'

I know how to insert rows in a table using the INSERT query, but I don't know how to do it while looping the arrays. I have to fetch the arrays from this page, and insert them row by row in the "ordered_products" table. Code:

Using Arrays With Mysql Query Results
im currently in the process of making a piece of code that will firstly take all the data from a table in mysql and then assign it to an array. This data will consist of several different rows of data each with different infomation for each field in the table.

i want to be able to use an array in a loop so that depending on which number of the loop is on will change the infomation that is assigned to a certain array. Code:

Merging 2 Mysql Resultant Arrays
im currently executing sql queries on two seperate mysql servers.  i take back each of these results into individual tables to display them. 

What i wanted to do was perform a merge of the two arrays, so that i could order the results by my "TimeStamp" field.

When i try to perform a basic " $mergedresult = array_merge($result, $isaresult); " i get the following.

"
Warning: array_merge() [function.array-merge]: Argument #1 is not an array in C:Program Filesxampplitehtdocsseatpub.php on line 164

Warning: array_merge() [function.array-merge]: Argument #2 is not an array in C:Program Filesxampplitehtdocsseatpub.php on line 164   "

Im rather new to this and so havent delt with arrays before, but im under the impression my results from the sql queries, are Assoc arrays.  can these be merged ? do i need to use an alternate php function ?

Retrieving Field From Mysql With Php
I want to select as in the code, an email matching a username, and after I want to make a variable called $email_a to send to this user an email. What is the way to retrieve the email address from the database and insert it into the variable?

$query = "SELECT email from users WHERE username = '$username'";

mysql_select_db($db_name);

$result = mysql_query($query, $connection) or die ("Error in query: $query. " . mysql_error());

Get Max Value In MySQL Table Field
I have a 2-field table "pageref".

The fields are: "pagerefno" - which is index and primary key, and "url".

I need to find the max value in "pagerefno", so wrote the following code:

$query ="SELECT max(pagerefno) FROM pageref";
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());
$row = mysql_fetch_row($result);
echo row[0];

But this results in a blank screen. I'd be grateful for a steer, here.

How To Get A Field In The Last Row Of Mysql Table.
There is a certain field that I wish to get in the last row (it will always be in the last row, even if I add to the table) of my mysql table. How do I output this? I assumed that I would be using a LIMIT command and a DESCRIBE command, however I looked at mysql.com and couldn't find anything .

Adding +1 To Mysql Field
Is it possible to add +1 to a current value been stored in a int field in a mysql table.

Updating A Field In A MySQL Db
I am having trouble updating a background_id field (integer type) in a MySQL database. What I'm trying to do is use the associated background ID (in the background table) of the background that is selected by the user to assign its value to the background_id field in the member table. PHP code:

Mysql Month_and_year Field
how can i have a mysql field that has just the month and year in it, and so it can be ordered correctly?

What Is Better - One Field Or Eight - Mysql Bit Testing
I have to store up to eight boolean bits of information about an item
in my database.

e.g.

[ ] with restaurant
[ ] drive-through facility
[ ] yellow windows
[ ] wifi factilities
etc...

There are three ways of storing this information in my mysql database
A. add eight fields (tiny integer)
B. add one tiny integer and create a function in PHP that can translate
the number stored into a eight boolean values (the bits)
C. create a table which list
ItemID
Associated characteristics
In C, you will only list the characteristics that are true for the item
listed.

Option B is the most efficient in MySql, but would you recommend it
when creating a PHP website. The problem is that the user needs to
enter them with a nice webform, etc...

Using A Mysql Timestamp Field In PHP
I have a table where one of the fields is a timestamp. I would like to use this field in PHP, and separate the Year, Month and Day into separate variables. For some reason I'm always getting 1970, 01, 01.

Mysql Field List
We would like to be able to  get the column list of a mysql Table from PHP code.  I know from the mysql prompt we can get it, but we want to  generate PHP  code
that  will retun an array  of columns  If   there is a column descriptor containing
name, size, etc, that would be great. Something that I could loop thropugh an array in
PHP4 and   get  the names of all the columns in the table as well as perhaps
other column  parameters as well. I believe that can be done in CGI, but want to use
PHP4.

Mysql Text Field
I have a DB with a column that is set as Text format. The data stored in the field will be stored in many lines. When I get the data from the DB I want it to display where the line breaks are I'm not sure how to write the script to do this. I have worked withe explode before but there is nothing come at the end of each line to do this with.

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 &#390;'

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?


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