Forum Moderators: coopster
I got some code below.
The database consists of about 100 rows.
How do i do it so i only output the values of the last row in the database i.e only the 100th line
Hope you can help
Thanks in advance
$con = pg_connect("host=dbteach port=5 dbname=u user=u password=p");
$sql = "select * from userDetails";
$r = pg_exec($con, $sql);
$nrowss = pg_numrows($r);
if($nrowss!= 0)
{
for($j=0; $j<$nrowss; $j++)
{
$row = pg_fetch_array ($r);
echo 'Please keep the following for reference <br>';
echo "Your reference Number <INPUT TYPE=\"text\" NAME=\"uid\" VALUE=\"" .$row["userid"]. "\"> <br>";
echo "Your Email address is <br><INPUT TYPE=\"text\" NAME=\"uemail\" VALUE=\"" .$row["useremail"]. "\"> <br>";
}
}
Also if you are only pulling one row, you won`t need a for loop.
if($nrowss!= 0)
{
$row = pg_fetch_array ($r);
echo 'Please keep the following for reference <br>';
echo "Your reference Number <INPUT TYPE=\"text\" NAME=\"uid\" VALUE=\"" .$row["userid"]. "\"> <br>";
echo "Your Email address is <br><INPUT TYPE=\"text\" NAME=\"uemail\" VALUE=\"" .$row["useremail"]. "\"> <br>";}