Re: [PHP-DB] Newbie alert: supplied argument is not a valid MySQL result resource

2007-07-11 Thread Niel
Hi On my way to bed so too tired too look closely, but at a guess I'd say it's a logic error. I would guess this: $sid = mysql_fetch_array($query) || die ('Could not fetch from database: ' . mysql_error()); // --- line 49 isn't evaluating in the order you expect.. You're using

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

2007-07-11 Thread Kevin Murphy
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 = mysql_query($first_query,$con); $first_id = mysql_result($first_result,0,'id'); $last_query = SELECT id FROM

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] Newbie alert: supplied argument is not a valid MySQL result resource

2007-07-11 Thread Matt Leonhardt
lameck kassana [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] hey just make this $sid = mysql_fetch_array($query) or die ('Could not fetch from database: ' . mysql_error().); try this Yep. I figured that out yesterday. Hit the nail right on the head. As I've learned from

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

2007-07-11 Thread Matt Leonhardt
[EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] SELECT MIN(id), MAX(id) FROM mytable As an aside, is you are using associative arrays, be sure to use the following keys: $array['MIN(id)'] and $array['MAX(id)'] Just something I figured out recently :) Matt -- PHP Database

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] First and Last ID of a table

2007-07-11 Thread Peter Beckman
On Wed, 11 Jul 2007, Matt Leonhardt wrote: [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] SELECT MIN(id), MAX(id) FROM mytable As an aside, is you are using associative arrays, be sure to use the following keys: $array['MIN(id)'] and $array['MAX(id)'] Just something I figured