Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts

    Angry please help me with pulling out the relivant info from a tb table!

    Hi All,

    i have which a db table which stores class information
    here is a dump of the test info in it
    Code:
    -- Table structure for table `clubs`
    --
    
    CREATE TABLE IF NOT EXISTS `clubs` (
      `clubID` int(2) NOT NULL AUTO_INCREMENT,
      `area` varchar(50) NOT NULL,
      `location` varchar(50) NOT NULL,
      `instructor` varchar(30) NOT NULL,
      `instructor_phone` varchar(15) NOT NULL,
      `instructor_email` varchar(40) NOT NULL DEFAULT '',
      `trainingNight` varchar(10) NOT NULL,
      `junior_lesson` varchar(30) NOT NULL,
      `senior_lesson` varchar(20) NOT NULL,
      PRIMARY KEY (`clubID`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
    
    --
    -- Dumping data for table `clubs`
    --
    
    INSERT INTO `clubs` (`clubID`, `area`, `location`, `instructor`, `instructor_phone`, `instructor_email`, `trainingNight`, `junior_lesson`, `senior_lesson`) VALUES
    (1, 'Cornwall', 'Community Center', 'teacher A', '01245866', '', 'Friday', '7 - 8pm', '8 - 9.30pm'),
    (2, 'Cornwall', 'west end', 'wesley', 'n/a', '', 'Monday', '5pm - 9pm', '10pm - 6am'),
    (3, 'Cornwall', 'Community Center', 'teacherB', '098775656', '', 'Tuesday', '1pm - 3pm', '6pm - 9pm');
    i am trying to pull out all the classes from each of the areas from each of the locations? make sence?

    well the good news is that i have magaed to pullout the class info and intstructor info for a location but it doesnt seem to pull the classes for each location

    for example the locations are
    1/community center
    2/west end

    but im only recieving the class info from community center? but i dont know why?

    here is my code
    PHP Code:
    <?php
    //SETTING UP AN ARRAY FOR EACH OF THE DIFFERENT AREAS
    $area_array = array();

    $clubs "SELECT area FROM clubs";
    $sql mysql_query($clubs);

    //FOR EACH ROW FOUND ADD IT INTO THE ARRAY
    while($row mysql_fetch_array($sql))
    {
    $area_array[] = $row['area'];
    }
    //SETUP ANOTHER ARRAY WHICH ONLY STORES THE UNIQUE VALUES FROM $area_array SO WE DONT GET ANY DUPLICATE ENTRYS
    $areas array_unique($area_array);

    //NOW WE SET UP THE INFORMATION FOR EACH AREA
    foreach($areas as $area)
    {
    ?>
        <div class="clubsContainer">
        <div class="clubHeaders"><?php print $area;?> </div>
        <?php
        $clubInfo 
    "SELECT * FROM clubs WHERE area = '$area'";
        
    $sql mysql_query($clubInfo);
        while(
    $info mysql_fetch_array($sql))
        {
    ?>
            <div class="clubInfo"><?php print "<p>".$info['location'];?><br />
            <?php
            
            
    //GET THE CLASS INFORMATION FROM EACH OF THE LOCATIONS IN THE AREA
            
    $classesList "SELECT * FROM clubs WHERE area = '$area' AND location = '".$info['location']."' ORDER BY trainingNight DESC";
            
    $sql mysql_query($classesList);
                <
    div class="clubInfo"><?php print "<p>".$info['location'];?><br />
                <?php
                
                
    //GET THE CLASS INFORMATION FROM EACH OF THE LOCATIONS IN THE AREA
                
    $classesList "SELECT * FROM clubs WHERE area = '$area' AND location = '".$info['location']."' ORDER BY trainingNight DESC";
                
    $sql mysql_query($classesList);
                while(
    $classes mysql_fetch_array($sql))
                {
                    print 
    "<p>";
                    print 
    $classes['trainingNight'];
                    print 
    "<br />";
                    print 
    "Juniors: ".$classes['junior_lesson'];
                    print 
    "<br />";
                    print 
    "Seniors: ".$classes['senior_lesson'];
                    print 
    "<br />";
                    print 
    "Instructor: ".$classes['instructor'];
                    print 
    "<br />";
                    print 
    "Contact ".$classes['instructor']." On: ".$classes['instructor_phone'];
                    print 
    "<br />";
                    print 
    "Or By Email: ".$classes['instructor_email'];
                    print 
    "<br />";
                    print 
    "</p></p>";
                }
    ?>         
                </div>

    <?php }?>
        </div><?php
    ?>
    any help would be greatly appreciated

    thanks
    Luke
    Last edited by LJackson; 10-13-2009 at 01:26 AM.

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts
    strange thing is when i add all the locations into an array like so
    PHP Code:
        $clubInfo "SELECT location FROM clubs WHERE area = '$area'";
        
    $sql mysql_query($clubInfo);
        
    $locations_array = array();
        
    $info mysql_fetch_array($sql);
        foreach(
    $info as $club)
        {
        
    $locations_array[] = $club;
        }
        
    print_r($locations_array); 
    i get this back
    Code:
    Array ( [0] => Sennen Community Center [1] => Sennen Community Center )
    
    west end
    west end is there but not in the array? any ideas why!

    thanks
    Luke

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts
    sweet!!! after a few hours ive managed to solve it

    really need some sleep now 1-30am lol
    cheers


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •