Re: [PHP-DB] First and Last ID of a table

2007-07-11 Thread tg-php
SELECT MIN(id), MAX(id) FROM mytable :) Hope that helps! -TG = = = Original message = = = I have a table where I need to figure out the very first ID and the very last ID, so here is what I wrote: $first_query = SELECT id FROM mytable ORDER BY id LIMIT 1; $first_result =

Re: [PHP-DB] First and Last ID of a table

2007-07-11 Thread tg-php
Sounds about right... you can also do something like this (syntax should be right): SELECT MIN(id) as minid, MAX(id) as maxid FROM mytable $array['minid'] and $array['maxid'] Basically it's going to be whatever the heading of that column is. Using as gives it an alias for less ugly

Re: [PHP-DB] sql statement - complex order by

2007-07-02 Thread tg-php
Try this: SELECT * FROM productgroup WHERE groupid = $productid ORDER BY label = 'Cats' DESC, title The test SQL I did to make sure I understood it was this (against our Users table): select * from users order by first = 'Bob' DESC, first, last It put all the Bobs first, sorting them by

Re: [PHP-DB] Search for whole words in MySQL 3.23

2007-06-13 Thread tg-php
I suck at regex, but looks like 3.23 may actually support it. And most regex implementations have a word boundary code for doing exactly what you're talking about. Referring to this page: http://dev.mysql.com/doc/refman/4.1/en/regexp.html I found this example.. hopefully it'll help you (and

Re: [PHP-DB] Values in a date field

2007-03-17 Thread tg-php
Assuming you're using MySQL, try MONTH(). As in: SELECT MONTH(SomeDateField) FROM SomeTable http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html If this isn't a database question, but a general PHP question, try this: // For numeric month without leading zero, use n echo

Re: [PHP-DB] SQL Query - Using variable from another SQL Query

2007-02-12 Thread tg-php
Try this as your SQL. It should give you all the results, then you can use PHP to sort it all out. SELECT * FROM egw_cal WHERE cal_category='501' and cal_id in (SELECT cal_id FROM egw_cal_dates where cal_start $tstamp) -TG = = = Original message = = = Hello Everyone Got a simple /

Re: [PHP-DB] 2 queries -- 1 array

2007-01-12 Thread tg-php
Not sure if this is exactly what you're looking for, Matt, but I think it is. ?php $query = SELECT t1.NAME, t1.BUSINESS, t1.ADDRESS, t1.CITY, t1.PHONE, t2.CONTACT_NAME, t2.CONTACT_VALUE FROM Table1 as t1, Table2 as t2 WHERE t1.ID = t2.CONTACT_ID $result = mysql_query($query); while ($row =

Re: [PHP-DB] 2 queries -- 1 array

2007-01-12 Thread tg-php
Ok, in your original message you said something about using the name as dominant key (or whatever you want to call it). All the SQL does is gather all the data together in an associated fashion. You can use the array you build to organize the data. I'm still not 100% sure what you're doing,

Re: [PHP-DB] Filter array results... no copies

2007-01-11 Thread tg-php
If all you want is a unique list of adr_one_region codes, then use the DISTINCT keyword in your SQL: SELECT DISTINCT adr_one_region FROM egw_addressbook WHERE cat_id='8' ORDER BY adr_one_region -TG = = = Original message = = = Hello everyone I'm back working on the website again... I'm

Re: [PHP-DB] Order By [blank]

2006-12-21 Thread tg-php
This is a little weird looking, but should do the job. Remember that items in your 'order by' can be manipulated conditionally. In this case, I'm looking for NULL as well as '' (empty) and changing it to something that should come after all your normal alphabetical values, but it doesn't

Re: [PHP-DB] Order By [blank]

2006-12-21 Thread tg-php
This is a little weird looking, but should do the job. Remember that items in your 'order by' can be manipulated conditionally. In this case, I'm looking for NULL as well as '' (empty) and changing it to something that should come after all your normal alphabetical values, but it doesn't

Re: [PHP-DB] Order By [blank]

2006-12-21 Thread tg-php
You shouldn't have to do that. the IFNULL() handles all that. If the item is null, it returns an emptry string ''. If it's blank/empty, it returns an empty string. This is just used for the comparison = ''. This determines if it's empty or null and if so, returns

Re: [PHP-DB] MSSQL Server

2006-12-21 Thread tg-php
I had some issues a couple years ago connecting to the MS SQL Server where I was employed at the time. I was probably just doing something wrong, but what I ended up using that worked for me was using the ADODB database abstraction layer. Helped me connect to MS SQL , Oracle and some other

Re: [PHP-DB] search result error message

2006-12-21 Thread tg-php
Sorry, don't have time to test and noodle through why yours may or may not be working, but I see some differences in how you're doing it and how we tend to do it here. After doing the connection and database selection, this is how we handle stuff (simplified): $query = select * from

Re: [PHP-DB] running program after insert w/MySQL 4.1

2006-07-07 Thread tg-php
cron or Windows Task Manager would work if you want to check the status of the data periodically, but I believe you can also use Access to hit a web address (it doesn't have to display anything) so you could, at time of insert, have Access activate a PHP script on your web server that does the

Re: [PHP-DB] Problem with list#2

2006-07-07 Thread tg-php
You may get duplicate messages sometimes when someone responds directly to you as well as copying the message to the main mailing list. Like in this ccase, my To: field is the PHP DB list, and my CC: field is your personal email address. If that's not the issue, then try what Dave suggested

RE: [PHP-DB] LIMIT

2006-07-05 Thread tg-php
Here are some thoughts on the couple of methods shown: 1. SELECT count(*) as MyCount FROM aTable # Fast query done on server size SELECT * FROM aTable LIMIT 5 # Fast limited data return query done server side 2. SELECT * FROM aTable # Potentially slow query, lots of data stored in PHP

Re: [PHP-DB] Select distinct field won't return distinct value

2006-06-06 Thread tg-php
Correct me if I'm wrong, but it sounds like you have something like this: 123 Joe 124 Joe 125 Sue 126 John 127 Joe 128 Frank 129 Sue And you want to output something like: Joe 123, 124, 127 Sue 125, 129 John 126 Frank 128 But what you're getting is: Joe 123 Joe 124 ..etc You have

Re: [PHP-DB] Automatically +1 every 30 mins to a value in the database.

2006-06-02 Thread tg-php
An alternative to cron jobs or scheduled tasks (if they're not an option) is to have a marker somewhere (probably in your database) that records a timestamp for the last 'gold' update then when someone does get around to accessing the database through normal operations, have it figure out how

Re: [PHP-DB] MySQL/PHP Left Join Question

2006-05-25 Thread tg-php
One thing I've done in situations like this is just load your returned DB data into an array. Something like this would do: $dvdarr[$result['call_number']]['Title'] = $result['title']; $dvdarr[$result['call_number']]['Publisher'] = $result['publisher'];

Re: [PHP-DB] Adding url to google

2006-05-12 Thread tg-php
Sounds like you're asking how to programmatically add your web site to Google's search. I didn't dig very deep, but it doesn't look like Googles API provides for the ability to submit (only search) and by Google's addurl page (http://www.google.com/addurl/?continue=/addurl) it appears that

Re: [PHP-DB] Too stupid to UPDATE...

2006-05-12 Thread tg-php
Don't have time to totally disect it, but you might change the if($num_rows) to if($num_rows 0) just to make sure. Also, try echoing out your SQL statement to check and make sure things like $table got a real value or other silly things. Lastly, I usually use single quotes for SQL

Re: [PHP-DB] Excel to CSV

2006-03-11 Thread tg-php
The other response is half correct.. I havn't seen anything to read data from Excel with PHP (although it's technically possible, just kind of complicated) so the easiest solution is to use Excel and just have it load the file and save it in CSV format. The part that's not entirely correct

Re: [PHP-DB] Installing PEAR

2006-03-03 Thread tg-php
I remember the quick install/test I did using PEAR and I kind of had a similar experience, but I figured out what the issue was for me. PEAR installed perfectly but doing the pear install thing where it pulls the package down and puts it where it needs to put it, I was doing what you were

Re: [PHP-DB] Duplicate rows

2006-03-01 Thread tg-php
Depends on how you determine if something's a duplicate or not. For example, if it's just one column that can be used, you can do something like this: select ItemName, count(ItemName) from ItemListTable group by ItemName having count(ItemName) 1 That'll show you if ItemName is repeated.

Re: [PHP-DB] Duplicate rows

2006-03-01 Thread tg-php
Haha.. oh yeah.. DISTINCT works too.. in this case you'd get a list of all totally 100% unique records. If you had an auto_increment column though, you'd want to exclude it from the list. -TG = = = Original message = = = SELECT DISTINCT * FROM `tablename` On Wednesday 01 March 2006 7:24

Re: [PHP-DB] Storing money values in MySQL

2006-01-20 Thread tg-php
Thanks Balazs and David.. I think that's exactly what I was looking for. I searched for hours (and I consider myself a fairly decent researcher) and was just getting frustrated..hah.. I think my problem was I was searching for money and float problems and such and not monetary. I think

RE: [PHP-DB] Date Time 90 minutes ago

2006-01-19 Thread tg-php
Bastien's example is probably the quickest and easiest. I just wanted to point out that you can use math within the mktime() function as well in case the relative date/time you need isn't right now. $month = 1; $day = 19; $year = 2006; $hour = 17; $minute = 08; $second = 05; echo date(Y-m-d

[PHP-DB] Storing money values in MySQL

2006-01-19 Thread tg-php
Again.. your forgiveness. This is a MySQL question. If the MySQL mailing lists would include a [MySQL Help] tag in their subject lines, I'd use them. What I receive from them is difficult to distinguish from spam half the time so I gave up. We had a problem a few months ago and now I can't

Re: [PHP-DB] Refreshing text question!

2006-01-18 Thread tg-php
Two ways I can think of to update part of a page without doing a full refresh: 1. Use an IFRAME so you're technically updating a page, but it's the page within the frame (not my favorite but works ok) 2. Or you can use asynchronous javascript (AJAX) to update just that one section of the page

RE: [PHP-DB] MySQL date casting..

2006-01-17 Thread tg-php
Unfortunately, no. The dates and times are stored as text. So here's what I get: 2006-01-10 07:00 PM 2006-01-10 08:00 PM 2006-01-10 09:00 AM 2006-01-10 09:00 PM (notice the AM out of order) For anyone interested, here's the big ugly version.. if anyone knows of a function that I can use

Re: [PHP-DB] MySQL date casting..

2006-01-17 Thread tg-php
Ahh! Thank you Philip! That's what I was looking for! I see what I did wrong now. I was using the date format strings wrong. I was using it like I'd use it for DATE_FORMAT() instead of as an input filter. This is what I was trying to do: select STR_TO_DATE('2003-11-05 06:00 PM', '%Y-%m-%d

RE: [PHP-DB] Formatting a form box

2006-01-12 Thread tg-php
What? Nobody said This has nothing to do with PHP and databases? Sheesh... someone must be sleeping. :) Ok, so it sorta does relate.. But yeah... no2br() will do it for you. Textarea input types DO send a newline and/or carriage return (didn't test and might be system specific), so if you

Re: [PHP-DB] Date Formatting Question

2005-12-14 Thread tg-php
You got the right idea, but you're making it more complicated than it needs to be. your $sDate after using explode() is going to contain an array. strtotime doesn't take an array, it takes a string. $monthName = date(F, strtotime($row_events['Sdate'])); $monthNumber = date(m,

Re: [PHP-DB] Minor Change

2005-12-12 Thread tg-php
This isn't really a MySQL error (sorta), it's a PHP error. You probably forgot to update a variable name when you updated everything else. Here's an example sequence for querying using PHP/MySQL: $TestQY = SELECT * from SomeTable; $TestRS = mysql_query($TestQY) or die(Error executing query);

Re: [PHP-DB] Need a Help!

2005-12-12 Thread tg-php
Couple of things you can do: 1. Drop the song ID and only get the artist information SELECT distinct(Artist) from songtable. It doesn't look like your SELECT statement needs a song, but you include the song ID as $id anyway. Any reason for that or can you drop it so you only get artist? 2.

Re: [PHP-DB] Storing an array on a table?

2005-09-01 Thread tg-php
Sorry, didn't catch this thread from the beginning, but did anyone recommend trying the serialize() and unserialize() commands? They'll convert the array to a block of text that can be stored, retrieved and unserialized. My gut instinct is that if you're trying to store any array in a

Re: [PHP-DB] Storing an array on a table?

2005-09-01 Thread tg-php
Ahh..thanks Jordan.. sorry I missed that one and thanks for the info. I assumed serialize was just magic and worked properly. hah. Now I know. I always thought it was sloppy to use anyway, but in a pinch, it's nice to know there's an option like that. Imploding does sound better though.

Re: [PHP-DB] SQL Injection attack

2005-08-25 Thread tg-php
I'm pretty amateur at this too, but have done a little reading on the subject. Here's some nuggets to ponder while the real experts write their responses: :) 1. Magic quotes + mysql_escape_string = double escaped stuff. I think the general opinion is the magic quotes is evil, but I'm sure

Re: [PHP-DB] SQL Injection attack

2005-08-25 Thread tg-php
Haha.. what the hell? Ok, I know this is an older copy of the script I wrote because I know I took out the All this does is escape the data comment and I KNOW I saw the thing about mysql_escape_string() being deprecated... don't know why it's still in there. Hah Thanks for pointing that out.

Re: [PHP-DB] Case sensitive

2005-08-24 Thread tg-php
One trick is to force the case in your comparison: $ucstringinput = strtoupper($stringinput); $qry = select * from sometable where upper(address) like '%$ucstringinput%' Didn't think LIKE was case sensitive, but regardless... forcing upper or lowercase in your comparison doesn't affect output

Re: [PHP-DB] Connecting to SQL Server

2005-08-10 Thread tg-php
If I remember right, PHP's built-in database functions don't allow for a DSNLess connection. Meaning you have to set up an ODBC source on the machine PHP is running on (or do a remote ODBC connection) and connect to a DSN (a named datasource manually set up). BUT.. if you know the address of

Re: [PHP-DB] Integrated Authentication on IIS 6.0

2005-05-23 Thread tg-php
Maybe I'm not understanding the situation properly, because I can't see why you would have had it working under IIS5 if your configuration is how I think it is. Integrated authentication basically allows a workstation that's logged into a domain to automatically pass it's credentials from the

RE: [PHP-DB] Integrated Authentication on IIS 6.0

2005-05-23 Thread tg-php
Ahh.. ok.. I was mostly doing DSNless connections. You might want to look into the setup for your ODBC source called Datasource in your example below. That might be what's actually passing the authentication, not PHP itself. PHP makes a call to the local ODBC source which in turn actually

Re: [PHP-DB] GROUP BY? Urgent help needed with selection list

2005-01-22 Thread tg-php
Well, first of all.. your subject line mentions GROUP BY which is a database function for telling the query what to use when performing aggregate functions like sum, count, average, etc type functions. That's really not what you're looking at doing here it sounds like. Sounds like you just

Re: [PHP-DB] to many addresses

2004-12-27 Thread tg-php
Sounds like pre-loading the addresses into javascript or something is also going to be just as cumbersome and that's the only other method I can think of to have the addresses auto-complete realtime. Yahoo has a little helper app that works with Yahoo mail to auto-complete names from your

Re: [PHP-DB] Comparing Two Values

2004-12-21 Thread tg-php
To be honest, I havn't had much use for it myself but I've done a lot of 'hack' projects that didn't need to be this specific. But as I understand, you might want to use the triple-equal sign to determine if they're exactly the same. Are you comparing... 2 with... 0002 (integer versus a