Web Hosting Talk







View Full Version : whats wrong with this query??


matt2kjones
11-05-2002, 07:11 PM
Hi i have a question. I got this query :

$hostid_query = "SELECT hostid FROM webhosts ORDER BY hostid DESC";

now then, i following that with this :

$result = mysql_query($hostid_query);
$data = mysql_fetch_array($result);
$last_hostid = $data['hostid'];

Now then, i thought that it would put the highest hostid into $last_hostid by it doesn't

the last host_id is 22, and it puts 7 in there for some reason

anyone know what im doing wrong

thanx

Noldar
11-05-2002, 08:04 PM
Couple of things to look at:

1) What is the data type of the hostid field?

2) What result do you get if you do this query from the mysql client or from phpmyadmin?

Richard

parawing742
11-06-2002, 12:18 AM
Try running the query in a program such as phpMyAdmin and that a look at all the results returned. The problem may be more visable then.

refcom
11-06-2002, 08:44 PM
And if you don't like the web-based-idness of phpMyAdmin or don't have access, you can use something like MySQL-Front - a windows based program, really nice work. Download mirror and forum/informational links are available at .mysqlfront.referable.com

jtrovato
11-06-2002, 09:21 PM
I use MySQL Front and love it. That's how I trouble shoot queries.

It looks like it should work but then you don't see a mis-spelling or a wrong command or what ever.

MarkIL
11-07-2002, 01:52 AM
Hrm, I believe it should be


$q = "SELECT hostid FROM webhosts ORDER BY hostid DESC LIMIT 1";

$result = mysql_query($q);
$data = mysql_fetch_array($result);
$last_hostid = $data['hostid'];

matt2kjones
11-07-2002, 08:50 AM
found the problem

i set hostid as VARCHAR not tinyint

Thanx why it was displaying the data wrong

thanx for the comments and sugestions

thanx :)