English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I want to use select min(ID) from mysql so I can get the minimal number in the ID. But how can I get the number?

This is my query
$query = "SELECT MIN(News_ID)FROM News WHERE News_ID > $News_ID";

and what kind of php I need to make that certain ID (minimal ID after the current one) shown in a variable?

2006-08-30 05:38:25 · 4 answers · asked by Fleea.Com 2 in Computers & Internet Programming & Design

4 answers

Here's a little sample code:

$rs = mysql_query($query);
$minId = mysql_result($rs, 0); //get the item in the first row
echo("The minimum news id is: $minId");

2006-08-30 05:43:46 · answer #1 · answered by Djibouti 4 · 1 1

The Query:
I'm not sure if your query is right. There is no need for that “WHERE” clause you have used. Because of the MIN() function there is going to be only one recored for the answer, so the WHERE clause is not needed. Delete that clause and see if the new query works or not. But if you want to apply the MIN() function on some of the records that are returned through that where clause, so it means that you wanted to narrow your answers before applying the MIN function. I suggest use this syntax for your query instead:
SELECT MIN(ID) FROM (SELECT * FROM News WHERE News_ID > $News_ID)

The PHP:
you can use direct mysql access by using mysql_connect(), mysql_query(), ... or you can use the DB class from the PEAR. I suggest you if you have the PEAR system working for your PHP, use the DB calss. It is very easy and also your code will be portable for other DBMSs. The syntax would be something like this:
requires DB.php
$my_db_connection = DB::connect(“mysql://user:password@host/database_name”);
$my_query = $my_db_connection->query(“query string ....”);
$my_result_array = $my_query->fetchrow();
...

i'm not sure if i'm recalling these methods right, you can go to pear repository (google php AND pear), and read the mannuals there. It is much easier to use than the native mysql_function functions.

2006-08-30 06:42:31 · answer #2 · answered by farzad 2 · 0 1

they would not make the decision this early except they were waiting for a monster hurricane. They ususally make the decision early sufficient so as that workers (like bus drivers) can locate out college has been stated as off and in no way bypass artwork. there will be an section on your college's website that receives as a lot as date, or there will be a television station that keeps present day cancellations on their website. The snow may not be as undesirable as they're predicting, or the hurricane would end numerous hours early and provides them the probability they prefer to get the roads sparkling in time. do not assume it till you spot it on the reveal. through how, the asker can not choose an excellent answer till the question has been up for 4 hours.

2016-12-05 23:47:07 · answer #3 · answered by remond 3 · 0 0

mmmmmmm .. what subject is this ??

2006-08-30 05:44:00 · answer #4 · answered by sandras 2 · 0 1

fedest.com, questions and answers