Jump to content

retrive from mysql by searching on date and another column


anujphp

Recommended Posts

<?php
$query1 = "SELECT distinct('category') as cat FROM profile"; // should get unique category names

$result = mysql_query($query1);
while($row = mysql_fetch_object)
{
  $cat = $row->cat;
  $query = "SELECT * FROM profile WHERE category = '$cat' ORDER BY date LIMIT 1";
   $result = mysql_query($query);
   while($row2 = mysql_fetch_object($result))
   {
      // do what you want with the data received here...
      $name = $row2->name;
      $address = $row2->address;
      $category = $row2->category;
      $date = $row2->date;
   }
}
?>

 

I think that should work. I am sure there is a better way ,but it is 3 am and my brain is tired... so thats the best I got right now.

 

Nate

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.