Jump to content

Recommended Posts

-------------------------

price  name

---------------------------

  aa           one

  bb           two

  cc              one

  dd           two

  ee              two

  ff                two

----------------------------

 

I want out put as

 

---------

sample

----------

  one

  aa

  cc

  two

  bb

  dd

  ee

  ff

--------

 

Any one guess it with

 

Link to comment
https://forums.phpfreaks.com/topic/74969-mysql-query-doubt-very-intresting/
Share on other sites

<?php

$query = "SELECT name, price FROM table ORDER BY name, price";
$result = mysql_query($query) or die (mysql_error());

$current_name = "";

while ($record = mysql_fetch_assoc($result)) {

    if ($record['name'] != $current_name) {
        $record['name'] = $current_name;
        echo "$current_name<br>\n";
    }
    echo "$record['price']<br>\n";
}

?>

Guest
This topic is now 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.