Jump to content


Photo

Unit Heiarchy Issue


  • Please log in to reply
3 replies to this topic

#1 High_-_Tek

High_-_Tek
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 30 June 2006 - 12:08 PM

Time for a tucker!

Well Im building a sort of catagory heirachry system for units.  The way it works is:  There are top units which have the unit_heiarchy id (in mysql) of 0.  The units that fall under that have a catagory heircharchy of 1 (the 1 signifies the unit ID (Primary key) of the top unit).  That repeats basically

So when I run this query in phpMyAdmin I get all the units I want:
(Remember the $id var here is the ID of the top unit you clicked on)

$sql = $db->sql_query("SELECT unit_banner, unit_name, designation, unit_heirarchy, id FROM atfcs_units WHERE unit_heirarchy = $id ORDER BY id ASC");

But when I run that in PHP, I only get the top set. with this code:

while ($row = $db->sql_fetchrow($sql)){
 
    echo "<img src='" . $row['unit_banner'] . "' />" . '<br />';
  echo "<b><a href='modules.php?name=" . $module_name . "&op=roster&id=" . $row['id'] . "'>" . $row['unit_name'] . '</a></b>  -  <i>' . $row['designation'] . '</i><br />';

Am I missing something herea about the code repitition in the while()?

On using a print_r on $row I only get 1 unit instead of all of them

Thanks for the great work here:)

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 30 June 2006 - 01:09 PM

Except for the closing } missing (typo?) the loop looks OK. Have you checked that $id contains the value you expect?
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 High_-_Tek

High_-_Tek
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 30 June 2006 - 01:12 PM

Im going through a few tests right now, will report on results

@Barand: I didnt post the whole loop

#4 High_-_Tek

High_-_Tek
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 30 June 2006 - 01:16 PM

Ok after some testing I have assured that the $id var passed in the URL is correct

But yet still, only 1 unit displays out of all of them




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users