php - Show only the last result from mysql row -


i have table

id | field1 | field2 | ... | field[x-1] | field[x] 1  | val1   | val2   | ... | val[x-1]   | val[x] 

and i'm doing search

for($i = 1; $i <= $x; $i++){    $getvalue = mysql_query("select * table id='1' , field".$i." 'some_value%'")or die(mysql_error());    while($row = mysql_fetch_array($getvalue)){       $j=$i+1;       $val = $row['field'.$j.''];    } } 

some values in table (val[1-x]) same need last value. limit 1 doesn't seem work.

update. unfortunately david suggested, can't change database. has is. have text file (a settings dump sensor) insert line line db , check see if there errors. check run ok have few lines in need choose last 1 check. have 10 lines this

d? string r? string ... d? string r? string 

i'm interested in last string after r?. use explode () , each value checked in limits.

using order id desc limit 1:

to last row (with highest=last=newest id), should use this:

select * table order id desc limit 1; 

your updated code (with mysqli_ extension) last row:

$query= mysqli_query("select * table order id desc limit 1") or die (mysqli_error()); }  $lastrow = mysqli_fetch_row($query);  echo $lastrow['id']; //get last id 

using max():

you can using sql max() function:

select * table id=(select max(id) table) 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -