hi everyone i have this code(dont think its a code spam ..its a trick)
which display the date(only):

<a href="index.php" STYLE="TEXT-DECORATION: NONE">&laquo;Back•</a>
<br>
<br>
<hr width="200" align="left">
<br>


<?php
$conn=odbc_connect('datasourcegaby','','');

$search=mysql_escape_string($_POST['SEARCH']);

if (!$conn)
  {exit("Connection Failed: " . $conn);}
  
if($search==null){

header("location:index.php");

}else{

$sql="SELECT * from generators WHERE  convert(datetime,convert(char(10),TIMESTOMPX,101))= '$search'";

};

$rs=odbc_exec($conn,$sql);
if (!$rs)
  {exit("Error in SQL");}
echo "<div class=\"resultx\"><font size=\"4\">Result for:</font>&nbsp;&nbsp;<font color=\"red\"> $search </font></div><br><hr width=\"200\" align=\"left\"><br><div class=\"rightdv\"><div class=\"topg\"><FONT SIZE=\"5\" color=\"#FFFFFF\">•• TOTAL ••</FONT></div><table border=\"1\" style=\"table-layout:fixed\" class=\"totalinsidet\"><tr class=\"topbth\">";
echo "<th>TOTALMW</th>";
echo "<th>TOTALMVAR</th></tr>";

while (odbc_fetch_row($rs))
  {
  $genmw=odbc_result($rs,"TOTALMW");
   $genvar=odbc_result($rs,"TOTALMVAR");


  
  echo "<tr>";
    echo "<td style=\"white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word\">$genmw</td>";
	  echo "<td style=\"white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word\">$genvar</td></tr>";

	  
  }

echo "</table></div>";







?>
<?php
$conn=odbc_connect('datasourcegaby','','');

$search=mysql_escape_string($_POST['SEARCH']);



if (!$conn)
  {exit("Connection Failed: " . $conn);}
$sql="SELECT GEN1MW,GEN1PF,GEN1MVAR FROM generators WHERE convert(datetime,convert(char(10),TIMESTOMPX,101)) = '$search'";

$rs=odbc_exec($conn,$sql);
if (!$rs)
  {exit("Error in SQL");}
echo "<div class=\"leftdv\"><div class=\"topb\"><FONT SIZE=\"5\">GENERATOR 1</FONT></div><table border=\"1\" style=\"table-layout:fixed\" class=\"totalinsidet\"><tr class=\"topbth\">";
echo "<th>GEN1MW</th>";
echo "<th>GEN1PF</th>";

echo "<th>GEN1MVAR</th></tr>";

while (odbc_fetch_row($rs))
  {
    
  $gen1mw=odbc_result($rs,"GEN1MW");
  $gen1pf=odbc_result($rs,"GEN1PF");
    $gen1mvar=odbc_result($rs,"GEN1MVAR");
	
  
  echo "<tr><td style=\"white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word\">$gen1mw</td>";
   echo "<td style=\"white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word\">$gen1pf</td>";
  
	  echo "<td style=\"white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word\">$gen1mvar</td></tr></div>";


  }

echo "</table>";




?>

<br>
<br>


<?php
$conn=odbc_connect('datasourcegaby','','');

$search=mysql_escape_string($_POST['SEARCH']);

if (!$conn)
  {exit("Connection Failed: " . $conn);}
$sql="SELECT GEN2MW,GEN2PF,GEN2MVAR FROM generators WHERE convert(datetime,convert(char(10),TIMESTOMPX,101)) = '$search'";
$rs=odbc_exec($conn,$sql);
if (!$rs)
  {exit("Error in SQL");}
echo "<div class=\"topc\"><FONT SIZE=\"5\">GENERATOR 2</FONT></div><table border=\"1\" style=\"table-layout:fixed\" class=\"totalinsidet\"><tr class=\"topbth\">";
echo "<th>GEN2MW</th>";

echo "<th>GEN2PF</th>";

echo "<th>GEN2MVAR</th></tr>";

while (odbc_fetch_row($rs))
  {
    
  $gen2mw=odbc_result($rs,"GEN2MW");
  $gen2pf=odbc_result($rs,"GEN2PF");
    $gen2mvar=odbc_result($rs,"GEN2MVAR");
  
  echo "<tr><td style=\"white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word\">$gen2mw</td>";
   echo "<td style=\"white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word\">$gen2pf</td>";

	  echo "<td style=\"white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word\">$gen2mvar</td></tr>";

	  
  }

echo "</table>";




?>

<br>
<br>

<?php
$conn=odbc_connect('datasourcegaby','','');

$search=mysql_escape_string($_POST['SEARCH']);

if (!$conn)
  {exit("Connection Failed: " . $conn);}
$sql="SELECT GEN3MW,GEN3PF,GEN3MVAR FROM generators WHERE convert(datetime,convert(char(10),TIMESTOMPX,101)) = '$search'";
$rs=odbc_exec($conn,$sql);
if (!$rs)
  {exit("Error in SQL");}
echo "<div class=\"topd\"><FONT SIZE=\"5\">GENERATOR 3</FONT></div><table border=\"1\" style=\"table-layout:fixed\" class=\"totalinsidet\"><tr class=\"topbth\">";
echo "<th>GEN3MW</th>";

echo "<th>GEN3PF</th>";

echo "<th>GEN3MVAR</th></tr>";

while (odbc_fetch_row($rs))
  {
  $gen3mw=odbc_result($rs,"GEN3MW");
  $gen3pf=odbc_result($rs,"GEN3PF");
    $gen3mvar=odbc_result($rs,"GEN3MVAR");
  
  echo "<tr><td style=\"white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word\">$gen3mw</td>";
   echo "<td style=\"white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word\">$gen3pf</td>";
	  echo "<td style=\"white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word\">$gen3mvar</td></tr>";

	  
  }

echo "</table>";
?>
<br>
<br>

<?php
$conn=odbc_connect('datasourcegaby','','');

$search=mysql_escape_string($_POST['SEARCH']);

if (!$conn)
  {exit("Connection Failed: " . $conn);}
$sql="SELECT GEN4MW,GEN4PF,GEN4MVAR FROM generators WHERE convert(datetime,convert(char(10),TIMESTOMPX,101))  = '$search'";


$rs=odbc_exec($conn,$sql);
if (!$rs)
  {exit("Error in SQL");}
echo "<div class=\"tope\"><FONT SIZE=\"5\">GENERATOR 4</FONT></div><table border=\"1\" style=\"table-layout:fixed\" class=\"totalinsidet\"><tr class=\"topbth\">";
echo "<th>GEN4MW</th>";
echo "<th>GEN4PF</th>";
echo "<th>GEN4MVAR</th></tr>";

while (odbc_fetch_row($rs))
  {
  $gen4mw=odbc_result($rs,"GEN4MW");
  $gen4pf=odbc_result($rs,"GEN4PF");
    $gen4mvar=odbc_result($rs,"GEN4MVAR");
  
  echo "<tr><td style=\"white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word\">$gen4mw</td>";
   echo "<td style=\"white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word\">$gen4pf</td>";
	  echo "<td style=\"white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word\">$gen4mvar</td></tr>";

	  
  }

echo "</table>";




?>
<br>
<br>



<?php
$conn=odbc_connect('datasourcegaby','','');

$search=mysql_escape_string($_POST['SEARCH']);

if (!$conn)
  {exit("Connection Failed: " . $conn);}
$sql="SELECT GEN5MW,GEN5PF,GEN5MVAR FROM generators WHERE convert(datetime,convert(char(10),TIMESTOMPX,101))= '$search'";

$rs=odbc_exec($conn,$sql);
if (!$rs)
  {exit("Error in SQL");}
echo "<div class=\"topf\"><FONT SIZE=\"5\">GENERATOR 5</FONT></div><table border=\"1\" style=\"table-layout:fixed\" class=\"totalinsidet\"><tr class=\"topbth\">";
echo "<th>GEN5MW</th>";
echo "<th>GEN5PF</th>";
echo "<th>GEN5MVAR</th></tr>";

while (odbc_fetch_row($rs))
  {
  $gen5mw=odbc_result($rs,"GEN5MW");
  $gen5pf=odbc_result($rs,"GEN5PF");
    $gen5mvar=odbc_result($rs,"GEN5MVAR");
  
  echo "<tr><td style=\"white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word\">$gen5mw</td>";
   echo "<td style=\"white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word\">$gen5pf</td>";
	  echo "<td style=\"white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word\">$gen5mvar</td></tr></div>";

	  
  }

echo "</table>";




?>
<br>
<br>


<br>

<h4><a href="index.php" STYLE="TEXT-DECORATION: NONE">&laquo;Back</a></h4>

and i like to DISPLAY THE LAST DATA THAT HAS BEEN ENTERED IN THE DATABASE(MSSQL) in a specific date:

example: let say i want to display the last data entered in the database of september 1 ... like that how can i do that with my code? ..

Recommended Answers

All 13 Replies

Ohhh... you have same code 6 times..Is this code by you?
for debugging echo sql query and run it directly in database and check if you are getting desired result.

echo $sql="SELECT * from generators WHERE  convert(datetime,convert(char(10),TIMESTOMPX,101))= '$search'";
exit;

Ohhh... you have same code 6 times..Is this code by you?
for debugging echo sql query and run it directly in database and check if you are getting desired result.

echo $sql="SELECT * from generators WHERE  convert(datetime,convert(char(10),TIMESTOMPX,101))= '$search'";
exit;

yeah its mine ...i know its kinda messy but i think its a good trick... no one cares on how do i code anyway.....


my code is fine...i dont need to debug it.. i just want to retrieve the last data entered in the mssql database and i dont know how to do it..

Ohhh... you have same code 6 times..Is this code by you?
for debugging echo sql query and run it directly in database and check if you are getting desired result.

echo $sql="SELECT * from generators WHERE  convert(datetime,convert(char(10),TIMESTOMPX,101))= '$search'";
exit;

hey i found one but not this one.. it displays the last row of table... but i want to "display the last data entered in a specific date"

heres the code btw:
$sql="SELECT TOTALMW,TOTALMVAR,ID FROM generators WHERE ID=(select max(ID) from generators)";

What about this:

$sql="SELECT TOTALMW,TOTALMVAR,ID FROM generators 
WHERE date='2011-08-11' // search with date
ORDER BY ID desc limit 0,1";

Minor correction, uselessninja says he's using mssql (which does not support limit)

$sql="SELECT TOP 1 TOTALMW, TOTALMVAR, ID 
      FROM generators 
      WHERE date='2011-08-11'
      ORDER BY ID DESC";

What about this:

$sql="SELECT TOTALMW,TOTALMVAR,ID FROM generators 
WHERE date='2011-08-11' // search with date
ORDER BY ID desc limit 0,1";

OPSS ... "LIMIT in query is not available in MSSQL" :)

Minor correction, uselessninja says he's using mssql (which does not support limit)

$sql="SELECT TOP 1 TOTALMW, TOTALMVAR, ID 
      FROM generators 
      WHERE date='2011-08-11'
      ORDER BY ID DESC";

ill try this..i hope it works

Minor correction, uselessninja says he's using mssql (which does not support limit)

$sql="SELECT TOP 1 TOTALMW, TOTALMVAR, ID 
      FROM generators 
      WHERE date='2011-08-11'
      ORDER BY ID DESC";

uhmm..little bit confuse about ur code.. it only display the first row of table right? .. if does so i think its not the right one...


btw ... i was wrong about this code..

$sql="SELECT TOTALMW,TOTALMVAR,ID FROM generators WHERE ID=(select max(ID) from generators)";

> It displays the BIGGEST number of the row NOT the last row of the table .......I think it is not always the biggest number will be on the last row coz i change the position of 15 and 14 (the 14 is now on the last row) but it displays the 15! so i think this code is not appropriate.. can u give the appropriate one?

Use ORDER BY so the largest one will be first, then use TOP 1 to get only that row.

Use ORDER BY so the largest one will be first, then use TOP 1 to get only that row.

yeah thats what i said ... the biggest row is not always the last row ..... i want to display the last data entered in a specific day... lets say i want to display the last data entered as of 9/27/2011 ...

Hope ID is auto increamented and primary field.
When you insert new record then its id is greater than prev.
thus if you search all results with one date and see MAX(ID), it returns last inserted row for that date.

Use ORDER BY so the largest one will be first, then use TOP 1 to get only that row.

i know this is not the appropriate one BUT i use this one now in my form hehe ...thankzz sir..i appreciate ur help.. :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.