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 =
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
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
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
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
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 /
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 =
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,
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
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
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
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
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
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
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
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
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
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
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
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'];
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
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
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
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
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.
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
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
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
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
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
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
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
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
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,
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);
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.
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
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.
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
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.
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
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
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
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
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
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
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
47 matches
Mail list logo