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 .
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
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.
Putting An Array In A Mysql Database Table Field
I want to insert an array into my database but i've got a problem with it. Before i insert the array into the dbase i check if everything is in the array with print_r($array). Everything that should be in the array is in there so i insert it into the dbase. When i check my dbase with phpmyadmin the field that should contain my array has the word array in it so i assume the array is in the dbase. But when i retrieve the data from my dbase and check my array with print_r i get the following error: Warning: Argument to array_values() should be an array in.
Getting Field Count From A Table.
I've searched through devshed but haven't found a reference to how to query a database for the contents of a table, then count the number of fields in that table. Can someone help? Say, for instance, the call was FileName.php?table=Vendors In FileName.php, once you'd done all the happy connect stuff, $result = mysql_query("SELECT * FROM $table",$db); how would you count the fields in the result, regardless of the number of rows? I thought I could use mysql_fetch_row($result), then, with a single row selected count through the $myrow[] until they ceased to exist. Is this doable? It seems this would be fairly straightforward. Is there an easier/faster/better way? I'm still thumbing through my php/mysql tomb working on the problem but haven't found an obvious solution. Your thought are sincerely appreciated.
Nonexistant Field In Table
I have a script that updates some mysql tables using input from a text file. The query that's giving me trouble is this one: "UPDATE $table SET `$f` = '$v' WHERE id = '$new_id'" where $f is the name of the field and $v is the value. The problem is, some of the information in the file is outdated, so some fields don't exist anymore. If I try to run the update with a field that doesn't exist, the script halts and I get an error. Is there any way to have the script ignore this and just keep going?
Set Variable Name Use Field Name From Table
I have a query string that sets the value of Variables below: if ($DB == "Departments") { $tracking_id = $data22['tracking_id']; $dept_name = $data22['dept_name'];} simple and straight forward. Now I would like to set a loop that would set the variable name and value based on the field names in the table queried. if ($DB == "Departments") { $querystring = "Select * from ".$DB; $result=mysql_query($querystring); while(($field = mysql_fetch_field($result))) { $field->name = $data22[$field->name];}} can I set the variable name using the $field->name if so how? I have tried this code with no luck and no luck searching. This is a small example. I have queries with fifteen plus fields. This would also remove the need to modify this code if a field needs to be added to the table. And yes I have had to add fields to the tables.
Select From Table Where Field = String
How to select all lines containg a string (located in $pastmove) in the moves column. I tried several ways, for example: $requete="SELECT moves, opening_id FROM suitemove where moves like '%".$pastmove."%'"; but did not succeed;
Syntax For MIN And MAX Values Of A Field In A Table
I wish to assign a variable name to the MIN and MAX values of a field in a table. The type is int(7). I am extracting the field with many others with the following code from a php call. $ml_collect='SELECT * FROM ml_lopp LEFT JOIN scfmforening ON (scfmforening.scfmnum=ml_lopp.scfmnum) LEFT JOIN ml_newtidplats ON (ml_newtidplats.loppnum=ml_lopp.loppnum) ORDER BY date1, ml_lopp.loppnum' $ml_upg=mysql_query($ml_collect); mysql_close(); The field is contained within the table ml_lopp and it is called loppnum I have been trying combinations of this to extract the min and max of the field from the $ml_upg variable which includes all of the data to be processed. $lownum=mysql_result($ml_upg,MIN('loppnum')); $hghnum=mysql_result($ml_upg,MAX('loppnum'));; Which does not work.
Pulling Data From The Last Field Of A Table
What is the command to view the last result in a table using a DB query? Table Example TABLE PEOPLE >ID >NAME >POINTS one thing, it cant be ORDER BY id DESC If at all possible it has to be SELECT * FROM people WHERE name=jon && id=**last id** **last id** = Last id where the name jon was found.
Displaying Table Field List
I got a function that displays a list of the fields in a certain mysql table. I got it off of this site. The problem is that it only displays the word Array and I'm not sure why. This is the code for the function: Code:
Iinsert The Auto_increment Field Into Another Table?
I have 2 tables ('customer' and 'regcustomer') and 1 form. The user fills in the form with all their details and the script should insert their credentials into the 'customer' table, which has an auto_increment field for the 'customerid'. I then want the script to take the 'username' and 'password' specified in the form, AND the 'customerid' generated in the 'customer' table and insert it into the 'regcustomer' table. The credentials are inserting successfully into the 'customer' table and the 'customerid' is automatically being generated there. I just can't get the generated 'customerid' to insert into the 'regcustomer' table. Here's the code that's generating the error: $query1 = "SELECT last_insert_id(customerid) FROM customer"; $result1 = mysql_query($query1); //echo $result1; $row = mysql_fetch_array($result1); $result2 = $row['customerid']; $datapoint = mysql_result($result2, 0, customerid); $result3 = "INSERT INTO regcustomer (username, password, $datapoint) VALUES ('$_POST[username]','$_POST[password]','$_POST[customerid]')"; The error message i'm getting is: Warning: mysql_result(): supplied argument is not a valid MySQL result resource in....in line 25 Line 25 is the [$datapoint = mysql_result($result2, 0, customerid);] line. I think it doesn't like the '0' argument here as it's turned to red in my editor!
Table Display Grouped By Specific Field
I operate a youth sports website and i display my current alignments in a long running list of teams (one field within my table) with association divisions (another field within table). I would like to group them by divisions, like a two column table for better clarification.
Inserting Data Into A Table With Auto Increment In One Field
i have a table with several fileds in and with the first one being an auto increment field. I want to know what my SQL query should be when inserting data. Here's my current one: Code: $SQL = mysql_query("INSERT INTO $usertable2 VALUES('$subject', '$newstext', '$date', '$usrname')"; The auto increment field is the first in the table and is called 'postid'. can someone give me the correct query please? also do i need the first entry in the table to be a blank one with just the postid entered at one?
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:
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
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.
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?
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?
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());
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 Ɔ' 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?
MySQL Date Field Help Needed
I have a Date type in my MySQL table - I'm trying to do a query on all rows within the last 30 days based on that Date field - I'm having trouble figuring out how to form the query? $php_SQL = "SELECT * FROM basics WHERE creation_date = DATE_ADD(creation_date, INTERVAL -30 DAY)";
Field Number Limitation Into MySQL
Is there a restriction to the number of fields you can work with in a PHP to MySQL connection? I'd used as many as 15 quite a few times and now I have a form with 34 fields and can't seem to get the info inserted into the table even though I'm not getting any connection errors, etc. Since my method is identical, I'm wondering if there's some 'rule' I am unaware of.
Can I Include PHP From A MySQL Field In My Page?
I want to be able to include PHP code from a MySQL field in my PHP pages, similar to using include("filename.php" ); so that the code will be run as if it were part of the page. In other words, I want to include() a string instead of a file but the include() function only accepts a file. Is there a way I can accomplish this?
Attempting To Add Time To A MySQL Field From PHP?
In my feeble attempt to keep track of login session timeouts I have the following code in my login section of my program: $sql = "UPDATE subscriber SET _sessexp = 'DATE_ADD(NOW(),INTERVAL 15 MINUTES)' WHERE _userid = '$_userid' LIMIT 1"; and when run I see NO ERRORS. However, either the field in the DB doesn't change OR this expression is generating a value of Ɔ' for the _sessexp field. I've tried using the ADDTIME function as an alternative but get the same results. I'm kind of at a loss. Any ideas as to why this is NOT behaving as I expect it to? What I am attempting to do is to take the CURRENT TIME and add 15 minutes to it and update a field in the database record. That simple!
Text Field As Date (MySQL)
I have a generic table used for many different generic functions. the fields are mainly varchar's but one of these varchars contains dates (in the format dd/mm/yyyy) for one reason or another. My question is, can I perform a query on this table, using date functions on this varchar field? I.e. search for the latest date?
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?
HTML Inserted From MySQL Field
I am creating a website for a group and there is a linik to a meetings page. This page summarizes the agenda of the meeting. This would be entered into mySQL via a text area or something along those lines. Now, sometimes there may be a power point file they would like to include. What I want to do is create another text area, where the user can put in something like so: <A HREF="meeting.ppt">BlueTooth Meeting</A> and when I retrieve this from the database I want this html to be executed. Then that way all they have to do is simply place the *.ppt into the dir via ftp. Will this work?
Problem Getting MySQL Field Defaults
Im trying to get the default values for my table VARCHAR fields but even though i have them set as NOT NULL, DESCRIBE is showing the Default's as NULL. Even if i enter an empty string into phpMyAdmin it still returns NULL. PHP Code:
Inserting Php Code Into Mysql Field
Im trying to display a variable '$downloadimage' which is in my head.php file. I am trying to display this on my page by inserting this code into one of my mysql database fields: -Code: <? echo $downloadimage; ?> When the page loads there is nothing there (i only have text in the variable at the moment), my html code shows the PHP echo code as text.
Php How To Treat Mysql Field Like A Date?
I have a query that looks like this: (I insert the date created with the php date function) $status = "Active"; //(I cannot use the mysql timestamp function for other reason). $curdate = date("m/j/Y H:i"); $owner = "not assigned"; @ $db_connect = mysql_connect("localhost", "$db_username", "$db_password"); if (!$db_connect) { echo "Unable to connect to the database; exit; } mysql_select_db("$db"); $query = "insert into tickets (user, status, loannum, problem, description, multiples, ticketnumber, ip, office, submissiontime, ticketowner) values ('$user1', '$status', '$loannum', '$problem', '$description', '$multiples', '$ticketnumber', '$ip', '$office', '$curdate', '$owner')"; $result = mysql_query($query); I need to pull out the last fifty records from the database, so I use this query: $order = $order; if ($order ==""){ $order = "user"; } mysql_select_db("$db"); $query = "select * from tickets ORDER by $order"; $result = mysql_query($query); $num = mysql_num_rows($result); if I order the tickets by submission time, it orders the items, but not correctly. It looks like php treating the submissiontime like integer: example: 12/1/2003 16:51 12/1/2003 16:58 12/10/2003 12:29 12/10/2003 12:36 12/11/2003 07:10 12/2/2003 09:16
Php - Mysql Form Field Generator
does anyone know of a simple function/class that will take config options: table name and the database connection stuff(or whatever) It will then print out appropriate form fields to allow editing of a row? The reason being is that in the admin section of a website I am building we are constantly adding columns to a table...It is used for keeping config options of the site. We do not wanna update the form each time we add a column.
MySql Question - Can I Add 90 Minutes To An INT Field
All the timestamps in my code are wrong by 90 minutes. date INT(11), I'd like to add 5400 to every date field in my database. Rather than do this in PHP, I'm wondering if MySql has a command that would allow me to do this directly.
Encrypt And Decrypt A Field Value From Mysql?
how to encrypt and decrypt a field value from mysql? i want to encrpt a password coming from my user before i would insert it to the database.. i used ENCRYPT on my sql statement..however when i checked the field..it was empty.
Inserting Apostrophes Into MySQL Field...
Trying to insert a height input into a MySQL table's field: <select class='normal' name='height' size='1'> <option value='5''>5'</option> <option value='5'1"'>5'1"</option> </select> the height variable is then inserted into the database. Looking at the table afterwards with phpMyAdmin shows that it contains only: 4 I'm escaping the apostrophes and speech marks for obvious reasons, but I imagine there's a proper way of doing this. Of course, selecting the height field from the database and echoing it to the page also just shows: 4
Onclck Update Mysql Field?
i have a script (below) when a user clicks on a link i want it to update a field in a database +1 so that i can see how many times it is clicked. but i cant get it to update the field what am i doing wrong? Code:
|