/    Sign up×
Community /Pin to ProfileBookmark

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:

[code=html]<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”>[/code]

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.

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@hastxOct 05.2012 — 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:

[code=html]
<p>

<input name="db_tables[members_table][memberno]" type="checkbox" id="memberno" value="51"/>

Member No

</p>
[/code]


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...

[code=php]
$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 ...";
[/code]




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.
×

Success!

Help @Lorinda spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...