Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Well, I have my array of parent and

Status
Not open for further replies.

flugh

Technical User
Joined
Aug 23, 2002
Messages
655
Location
US
Well, I have my array of parent and children clients using the mysql query and php code mentioned in thread434-705775 . I feed that into a <select> nicely, but am now thinking of having the select options grouped/nested. HTML and all aside, could someone point me in the right direction on manipulating and sorting the result of a mysql_query()? I _could_ GROUP BY 'MID' (the Master ID), but that doesn't get the 'masters' first. Surely this is reinventing the wheel, can someone point me to the assembly line? :-)

Did some more searching before hitting the 'Submit' button. Still no luck. Any help would be appreciated!

----
JBR
 
I did some horrifying stuff with my text editor. PHP shows it's serious lack of good judgement by actually running this code. I'm considering filing this as a bug report to the PHP developers.

Ok, this is really bad code, but it's doing what I need it to, for the most part. Just posting it as a follow-up.
Code:
function doSelect($theID, $level) {

    # Standard connection code. To be moved into a seperate function or
    # include file soon

    $conn = mysql_connect(&quot;localhost&quot;, &quot;x&quot;, &quot;x&quot;) or die (&quot;Couldn't connect: &quot; . mysql_error());
    mysql_select_db(&quot;x&quot;) or die(&quot;Couldn't select database: &quot; . mysql_error());

    # MID is the 'master ID', or the person/location owning the truck.
    # 'disname' is the displayed name for internal purposes. There is a
    # longer proper name in each record that is used to pretty up invoices we
    # generate. 'active' is an ENUM indicating current clients (old ones we
    # don't use anymore are set to 'no')

    $sql = &quot;SELECT * FROM dat_clients WHERE (MID = '$theID' AND active = 'yes') ORDER BY 'disname'&quot;;
    $result = mysql_query(&quot;$sql&quot;) or die (&quot;Couldn't query: &quot; . mysql_error());

    # this string is used to indent options in the select box. I think
    # building it via loop here is expensive. Don't know how to do it like
    # perl's &quot;A&quot; x <integer> method?

    $pushin = &quot;&quot;;
    $x = 0;
    while ($x < $level) {
        $pushin = $pushin . &quot;     &quot;;
        $x = $x + 1;
    }

    # Found a parent, so do a recursion to get children-parents. Could be
    # prettier. Would like to indicate a style or something to bold a
    # 'parent', but this will do for now

    while ($row = mysql_fetch_assoc($result)) {
        $levelstring = $levelstring . &quot; &quot;;
        echo &quot;<OPTION CLASS=\&quot;master\&quot; VALUE=\&quot;&quot; . $row['ID'] . &quot;\&quot;>&quot; . $pushin . $row['disname'] . &quot;\n&quot;;
        doSelect($row['ID'], $level+1);
    }
}
The dat_clients table holds a record for each client/person, client/location, and client/truck. There's about 22 records in there now. Not a huge table, so the recursion isn't too painful on the Athlon 550/256Mb box serving these pages.

Any criticism taken well and much appreciated :-)

----
JBR
 
I'm trying to utilize the OPTGROUP, but not really seeing how (getting the optgroup label, retaining the value of it, yadda) to use it like it should be. I think it boils down to a bad combination of query structure and code logic (that's a fancy way of saying 'I dont know what Im doing!!' ;-) ). It would be optimal to be able to tell if the current ID is a master who's children have no further children (a parent, but not a grandparent). That way I could seperate out the options in an optgroup.

Thanks for your input sleipnir214. Any further tips would be happily accepted!

----
JBR
 
My intention is to be able to easily get a recordset holding all the basic stuff I need for any client 'family' (children, grandchildren, etc) with a 'doSelect(<ID of the top level client>)'. It would seem to be a pretty clunky method I reckon, since I can't get the hang of manipulating the recordset afterwards.

Kind of looking at keeping the linux box running mysql on the backend, and keeping the XP boxen on the desktop and linking the tables up to an Access front end. It breaks my 'Linux on all the computers' goal (mainly for the freeness aspect of it), but I have to be realistic with my development abilities :-)

Followed a link to website from a Slashdot story yesterday. That looks pretty promising too.

----
JBR
 
Just to follow up a little. is a killer app. I think with a bit more R'ing TFM, I can make a useable frontend to my database with it. It will make those 'running Linux today' sessions a breeze (I'm a 'prefer Linux, but have a professional reality to face' kind of guy).

As for my frontend. I think I may just stick to phpMyAdmin (a 5 star app if you ask me,
Thanks for your input slep!

----
JBR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top