Query the maximum value of a field and assign it to a variable
I see a lot of code on the Internet, but inserted into my file can not, please help me to see, how to query the maximum value of a field and then assign it to the variable, I am the query to add 1 calculation.
$db _host= "localhost";//server
$db _user= "root"; User name
$db _psw= "123456"; Password
$db _name= "Test";//Database name
$conn = mysql_connect ($db _host, $db _user, $db _psw) or Die ("link wrong");
mysql_select_db ($db _name, $conn) or Die ("link is wrong");
mysql_query ("Set names Utf-8");
$line = 0;
$file = fopen (' Upload/amazon_erp.csv ', "R");
$STRSQL = "Select MAX (SKU) from table";
$query = mysql_query ($STRSQL, $conn);
$resulta = Mysql_fetch_row ($query);
$maxid = $resulta;
Print_r ($resulta);
while ($result = Fgetcsv ($file)) {
Every time you read a line in a CSV
if ($line <> 0)
{
$maxid + +;
$sku = $result [0];
$name = $result [1];
$address = $result [2];
$a = $result [3];
$b 1= $result [16];
$b 2= $result [17];
$b 3= $result [18];
$b = "$b 1, $b 2, $b 3";
$c = "$sku, $name, $address, $a, $b";
Echo $c;
echo "
";
$sql = "INSERT into ' test '. ' Table ' (' $resulta ', ' name ', ' address ', ' a ', ' B ') VALUES (' $resulta ', ' $name ', ' $address ', ' $a ', ' $b ') ";
mysql_query ($sql);
}
$line + +;
Fclose ($file);
echo "Import succeeded";
?>
------Solution--------------------
SQL code
#字段最大值: select MAX (ID) from table;
------Solution--------------------
Explore
query maximum value resolves
$strSql = "Select M
AX (order_no) from ' 0_sales_orders ';
The
Table name Plus ' is OK, and I don't know why
and I want to please, I want to query 4 table ID maximum, how to write, write four code like that???
------Solution--------------------
discussion
How can I escape and give the code?
Thank you!
------Solution--------------------
SQL code
select Max (c.id), Max (i.id)//c.id <==> t1.idfrom T1 as C,//definition Table T1 abbreviated as ct2 as I; As above, the abbreviation for defining table T2 is I