Hi Does Anyone know how to display a table based on user selected fields?
In my search box, once the user searches lets say all the female students, all the female students will show with all the fields of that particular table. then if need to print a report i want the user to be able to select the fields they want printed, that is how do i customize the table?

please help

Maybe this will work for your situation and point you in the right direction.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=encoding">
<title>Print Selected Rows</title>
</head>
<body>
<?php 	if(!isset($_POST["submit"])) { ?>
<form action="" method="post">
	<table><thead>
		<tr>
			<th>select</th>
			<th>Name</th>
			<th>Phone</th>
		</tr>
		</thead>
		<tbody>
		<tr>
			<td><input type="checkbox" name="keys[]" value="1" /></td>
			<td><input type="hidden" name="contact[1][name]" value="name1" />name1</td>
			<td><input type="hidden" name="contact[1][phone]" value="phone1" />phone1</td>
		</tr>
		<tr>
			<td><input type="checkbox" name="keys[]" value="2" /></td>
			<td><input type="hidden" name="contact[2][name]" value="name2" />name2</td>
			<td><input type="hidden" name="contact[2][phone]" value="phone2" />phone2</td>
		</tr>
		<tr>
			<td><input type="checkbox" name="keys[]" value="3" /></td>
			<td><input type="hidden" name="contact[3][name]" value="name3" />name3</td>
			<td><input type="hidden" name="contact[3][phone]" value="phone3" />phone3</td>
		</tr>
		<tr>
			<td><input type="checkbox" name="keys[]" value="4" /></td>
			<td><input type="hidden" name="contact[4][name]" value="name4" />name4</td>
			<td><input type="hidden" name="contact[4][phone]" value="phone4" />phone4</td>
		</tr>
		</tbody>
	</table>
  <input type="submit" name="submit" value="Print Version" />
</form>
<?php } else { ?>
	<table><thead>
		<tr>
			<th>Name</th>
			<th>Phone</th>
		</tr>
		</thead>
		<tbody>
<?php
foreach($keys as $index => $key)
{ ?>
		<!-- FOR $key = <?php echo $key; ?> -->
		<tr>
			<td><?php echo $contact[$key]['name']; ?></td>
			<td><?php echo $contact[$key]['phone']; ?></td>
		</tr>
<?php } ?>
		</tbody>
	</table>
	<input type="button" value="Print" onClick="window.print();" >
<?php
}
?>
</body>
</html>
Member Avatar for diafol

Could you post any code that you already have? See the announcements for an explanation.

hi is it possible to have one of ur skype ids or gmail ads? so can show the code then. thanks!

Member Avatar for diafol

This is an open forum - no ids. Show the code to get help. Professional coders show their code on here. Why can't you?

errrrr i know that... i asked becuase i can show it to one paticular person n there onwards work.. i said wat works for me.. if u do not want to help please dont, and do not jump to conclusions and accuse.

@lethargiccoder
i did it in a certain way but it doesnt seem to work the html and php is separate.

<form action="http://localhost/drupal/pdf.php" method="post" style="background-color:#F2F2F2; border:1px solid; border-color:#084B8A;
width:98%; padding:10px;" >
<table>
<tr>
<td><strong>Title of Your Report:</strong></td>
<td>
<input type="text" name="title" value="" size="60" id="title" />
</td>
</tr>
<tr>
<td>
<input type="radio" name="name" value="name" checked/> Name
</td>
</tr>
<tr><td><strong>Tick Fields Required:</strong></td>
</tr>
<tr>
<td>
<input type="checkbox" name="selectfields[]" value="address" /> Address
<input type="checkbox" name="selectfields[]" value="contactnumber" /> Contact Number
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="selectfields[]" value="gender" /> Gender
<input type="checkbox" name="selectfields[]" value="age" /> Age
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="selectfields[]" value="email" /> E-Mail
<input type="checkbox" name="selectfields[]" value="maritalstatus" /> Marital Status
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="selectfields[]" value="university" /> University
<input type="checkbox" name="selectfields[]" value="facdept" /> Faculty/Department
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="selectfields[]" value="course" /> Course
<input type="checkbox" name="selectfields[]" value="cd" /> Course Date
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="selectfields[]" value="rd" /> Registration Date
<input type="checkbox" name="selectfields[]" value="completion" /> Completion
</td>
</tr>
<tr><td> </td>
<td>
<input type="submit" value="CUSTOMIZE & PRINT" style="float:right;" class="up"onmouseover="this.className='over'"onmouseout="this.className='up'" />
</td>
</tr>
</table>

this is on the same page as the search box it appears below the search results.
i used this in the search.php for thse checkboxes

echo "<input type='hidden' name='selectfields' value='$sf'/>";

can u see whats wrong?

I'm new to PHP myself so I'm not necessarily the the best resource. That's a great reason to post for everyone to see! It would also be helpful if you post your entire source (highlight a section of concern if need be).

In this case, the form you provided works by itself but is a bit messy. You're missing </form>, I assume you just didn't copy that part but more importantly 2 of your <tr></tr> contain 2 <td></td> but the rest only have 1. Not sure what the purpose of the single radiobutton field for name is.

Please preview your post before submitting, you might have caught that you place your code inside the code-tag. I personally think that the submit button shouldn't even be seen on forums unless you are on a preview screen.

Here is what I ran for the form. Slightly cleaned up but not pristine. To find errors though, you will have to post the PHP that you are posting to.

<form action="http://localhost/drupal/pdf.php" method="post" style="background-color:#F2F2F2; border:1px solid; border-color:#084B8A;
width:98%; padding:10px;" >
    <table>
        <tr>
            <td><strong>Title of Your Report:</strong></td>
            <td>
                <input type="text" name="title" value="" size="60" id="title" />
            </td>
        </tr>
        <tr>
            <td>
                <input type="radio" name="name" value="name" checked/> Name
            </td>
            <td></td>
        </tr>
        <tr>
            <td><strong>Tick Fields Required:</strong></td>
            <td></td>
        </tr>
        <tr>
            <td>
                <input type="checkbox" name="selectfields[]" value="address" /> Address
            </td><td>
                <input type="checkbox" name="selectfields[]" value="contactnumber" /> Contact Number
            </td>
        </tr>
        <tr>
            <td>
                <input type="checkbox" name="selectfields[]" value="gender" /> Gender
            </td><td>
                <input type="checkbox" name="selectfields[]" value="age" /> Age
            </td>
        </tr>
        <tr>
            <td>
                <input type="checkbox" name="selectfields[]" value="email" /> E-Mail
            </td><td>
                <input type="checkbox" name="selectfields[]" value="maritalstatus" /> Marital Status
            </td>
        </tr>
        <tr>
            <td>
                <input type="checkbox" name="selectfields[]" value="university" /> University
            </td><td>
                <input type="checkbox" name="selectfields[]" value="facdept" /> Faculty/Department
            </td>
        </tr>
        <tr>
            <td>
                <input type="checkbox" name="selectfields[]" value="course" /> Course
            </td><td>
                <input type="checkbox" name="selectfields[]" value="cd" /> Course Date
            </td>
        </tr>
        <tr>
            <td>
                <input type="checkbox" name="selectfields[]" value="rd" /> Registration Date
            </td><td>
                <input type="checkbox" name="selectfields[]" value="completion" /> Completion
            </td>
        </tr>
        <tr>
            <td> </td>
            <td>
                <input type="submit" value="CUSTOMIZE & PRINT" style="float:right;" class="up"onmouseover="this.className='over'"onmouseout="this.className='up'" />
            </td>
        </tr>
    </table>
</form>

ok thanks but this is the form right? my problem is with the php code i think... have u anythng to sy abt how i have coded the checkboxes in the php code?

I don't understand your question. My last post has a modified version of your HTML form. The only PHP is the little I included on my first post, therefore I have no idea how you've coded any of your PHP.

If what you are referring to is the code that generated the above HTML form, then it looks like that will work for you with the clean up of the resultant HTML. But as far as processing the posted form goes, you haven't shown us anything.

Member Avatar for diafol

errrrr i know that... i asked becuase i can show it to one paticular person n there onwards work.. i said wat works for me.. if u do not want to help please dont, and do not jump to conclusions and accuse.

I don't want to get into an argument. I certainly didn't accuse you of anything. Just pointing out that this is a forum, which means you post your code for everybody to see. The guidelines state that you should post your code or show some effort yourself before asking for help.

As for helping you now, no I most definitely won't. Good luck.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.