#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    2
    Rep Power
    0
    Situation:
    I have a table with fields called id (my primary key), title, body, and salutation.

    Conditions:
    There are multiple records in the table with the same value for the title field. Ex. 1, titleA, body1, salutation1, 2, titleA, body2,
    salutation2...

    Problem:
    Generate a listing of all the records within an HTML box who’s header tag is of that title.

    Solution thus far:
    Create a static header and then query from inside that box (where title = 'title of box').

    Restrictions caused by this solution:
    I must know how many unique titles exist and what their values are.

    Wish:
    Dynamically generate a box (with a header) for each unique title.

    Any ideas on this?
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    just populate the unique title records into a combobox first and then query based on that..

    get the unique static header issuing following sql command.

    "select distinct title from tablename";

    i hope i'm giving answer in right direction..


    ------------------
    SR -
    webshiju.com

    "The fear of the LORD is the beginning of knowledge..."
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    2
    Rep Power
    0
    Thanks for you quick response! I've taken a your approach and applied it a little different situation as well. In case you care:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>

    function myfunction($mytype, $mytable, $myfield)

    /* Builds a select input with $mytype selected out of a list
    of all of the distinct occurrences of $myfield from $mytable.

    Arguments (3):
    $mytype = which occurrence of $myfiled that we want to match
    $mytable = name of table to match FROM
    $myfield = name of field in $mytable to match FROM */

    {
    print ("<select name="$myfield">n");

    include("http://x201.bus.indiana.edu/scripts/db_connect.inc");

    $myquery = "SELECT distinct $myfield
    FROM $mytable"
    or die ("myquery Failed");

    $mymysql_result = mysql_query ($myquery, $mysql_link)
    or die ("I failed to match any records in the database, probably due to an ErRoR.");

    while ($row = mysql_fetch_row($mymysql_result))
    {
    $all_type = $row[0];

    if($all_type == "$mytype")
    {
    print ("<option value="$all_type" selected>$all_type</option>n");
    }
    else
    {
    print ("<option value="$all_type">$all_typen");
    }
    }
    print ("</select>n");
    }
    [/code]
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Seaside, CA
    Posts
    84
    Rep Power
    14
    Got some help on this myself a few weeks back. Here's the end result, minus all the text formatting stuff:

    <?
    $db = mysql_connect("username", "password");
    mysql_select_db("yourdatabasename",$db);
    $result = mysql_query("SELECT * FROM physicians ORDER BY specialty,last",$db);
    if ($myrow = mysql_fetch_array($result)) {
    printf("<TABLE WIDTH=495 >n");
    printf("<TR><TD WIDTH=210>Specialty</TD>
    <TD WIDTH=210>Physician</TD>
    <TD WIDTH=75>Telephone</TD></TR>n");
    do {
    if ($myrow["specialty"] != $old_specialty)
    {
    printf ("<TR><TD>%s</TD><TD>%s %s, %s</TD><TD>%s</TD></tr>", $myrow["specialty"], $myrow["first"], $myrow["last"], $myrow["degree"], $myrow["phone"]);
    }
    else {
    printf ("<TR><TD></TD><TD>%s %s, %s</TD><TD>%s</TD></tr>", $myrow["first"], $myrow["last"], $myrow["degree"], $myrow["phone"]);
    }
    $old_specialty = $myrow["specialty"];
    } while ($myrow = mysql_fetch_array($result));
    echo "</table><br><br>n";
    } else {
    echo "Sorry, no physicians were found!"
    }
    mysql_free_result($result);
    mysql_close($db);
    ?>

    Haven't gotten the hang of formatting things on these message boards yet, so my apologies if it's messy. In the mysql_connect statement, you might also need a server name there, depending on how you're running things.

    You can see the results of this at: http://www.wathosp.org/physicians/ph...directory.php3

    ------------------
    From the day we're born, we're running out of time.

Similar Threads

  1. Replies: 4
    Last Post: February 22nd, 2004, 05:09 PM
  2. grouping query results into tree structure
    By jamieB in forum PHP Development
    Replies: 1
    Last Post: January 7th, 2004, 04:16 AM

IMN logo majestic logo threadwatch logo seochat tools logo