www.webdeveloper.com
Results 1 to 2 of 2

Thread: Extracting Data from more than one table into one page

  1. #1
    Join Date
    Oct 2012
    Location
    Pretoria, South Africa
    Posts
    1

    Extracting Data from more than one table into one page

    Good Afternoon,

    I am a newbie at php coding and sql, and I have started a site at work where the users can enter everything that they have done at work for the day including times and dates.
    I managed to get the information pulled through to my local DB (Wamp Server)
    Now I want the head of the department to be able to get reports and results from those pages using php. I am using check boxes for the head to choose what she wants to see..i.e:

    HTML Code:
    <tr>  
    <td class="grey"><p><span class="grey">  
       <input name="username" type="checkbox" class="User" id="username" value="48"/>  
       User Name  
       </span>  
       </p>  
       <p>  
             <input name="requestedby" type="checkbox" id="requestedby" value="49"/>  
             Requested By  
       </p>  
       <p>  
             <input name="type" type="checkbox" id="type" value="50"/>  
             Type  
       </p>  
       <p>  
             <input name="memberno" type="checkbox" id="memberno" value="51"/>  
             Member No  
       </p>  
       <p>  
             <input name="scheme" type="checkbox" id="scheme" value="52"/>  
             Scheme  
       </p>  
       <p>  
             <input name="fromtime" type="checkbox" id="fromtime" value="53"/>  
             From Time  
       </p>  
       <p>  
             <input name="fromdate" type="checkbox" id="fromdate" value="54"/>  
             From Date  
       </p>  
       <p>  
             <input name="totime" type="checkbox" id="totime" value="55"/>  
             To Time  
       </p>  
       <p>  
             <input name="todate" type="checkbox" id="todate" value="56"/>  
             To Date  
       </p>  
       <p>  
             <input name="comments" type="checkbox" id="comments" value="57"/>  
             Comments  
             </p>  
    <p>  
                                                              <input type="submit" value="Send">  
                                                              <input name="Reset" type="reset" value="Clear">
    This looks good, but i need the code to assist with (for example) the head of the department selects 3x tick boxes.i.e comments, username and fromtime, the information should then be taken from existing db's like..'stats' or systemletters' and then be complied in one page all together so that we can place that on a report? I hope this make sense. My wording is sometimes less understandable
    Please help.. I can send more info aswell if needed. If this is not possible can you please help me with other appreaches then..

    Thanking you in advance.

  2. #2
    Join Date
    May 2003
    Posts
    599
    You would need to know the table structure to get an idea of how to write the script...the cool thing about checkboxes is that you could pass those values in a key => value array where the key would be the table name and the value would be the column ...for example:

    HTML Code:
    <p>  
             <input name="db_tables[members_table][memberno]" type="checkbox" id="memberno" value="51"/>  
             Member No  
    </p>
    In this approach you could loop through "$_POST[db_tables][members_table]" to gather all the fields which criteria should match...but some might have problems with the approach in regard to security since you give away your table structure in the source, but the code would look like...

    PHP Code:
    $select_fields '';
    foreach(
    $_POST['db_tables'] as $tbl => $cols_array){
    $x=0;
         foreach(
    $cols_array as $col){
              
    $select_fields .= $tbl '.' $col;
              
    $x++;
         }
         
    $select_fields .= ($x sizeof($cols_array)) ? ',' '';
    }


    $qry "SELECT $select_fields FROM ..."


    Another approach would be to simply loop the checkboxes and append your query of one is set. But this is just a shot in the dark to give you an idea to start thinking, There is probably a better way but would need some pretty detailed info.
    We do precision guesswork

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles