Printing part of a form with links to further info

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Printing part of a form with links to further info

Post by mohson »

Hi,

Currently I print all records out from my database to create one large table with all database details.

It occurred to me that this is bad design as users dont need all the information all the time.

I want to print my records so that only a number of colums are printed and then you can click on a certain a [more info field] field to get more information on that particular person/record.

Can anyone provide me with any tips pointers and tutorials to help me do this pease.

Thank you

Below is print part of my code if this helps.

Code: Select all

"<table width=\"50%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">

    <tr>
		<td><b><small>RecNo</small></b></td>
		<td><b><small></small></b></td>
		<td><b><small>Title</small></b></td>
		<td><a href=\"orderfirstname.html\"><b><small>First Name</small></b></a></td>
		<td><a href=\"ordersurname.html\"><b><small>Surname</small></b></a></td>
		<td><a href=\"orderorgdesc.html\"><b><small>Organisation</small></b></a></td>
		<td><b><center><small>Role</small></center></b></td>
		<td><b><small>Address(1)</small></b></td>
		<td><b><small>Address(2)</small></b></td>
		<td><b><small>City</small></b></td>
		<td><b><small>Post Code</small></b></td>
		<td><b><small>Telephone</small></b></td>
		<td><b><small>Mobile</small></b></td>
		<td><b><small>Fax</small></b></td>
		<td><b><small>Last Contact</small></b></td>
		<td><b><small>Contact Again</small></b></td>
		<td><b><small>Consultation Panel</small></b></td>
		<td><b><small>Primary Contact</small></b></td>
		<td><b><small>Graduate Jobs</small></b></td>
		<td><b><small>MSC Projects</small></b></td>
		<td><b><small>UG Projects</small></b></td>
		<td><b><small>Professional Dev</small></b></td>
		<td><b><small>BCS Mem.</small></b></td>
		<td><b><small>BCS PDS</small></b></td>
		<td><b><small>Teaching</small></b></td>
		<td><b><small>Academic Consultancy</small></b></td>";



while ($row = mysql_fetch_object($sql)) 






{($color==$color2)? $color = $color1 : $color = $color2;


echo "<tr bgcolor=\"$color\"><td>".$count . '</td>

<td>'.'<a href="editpeople.html?person_id='.$row->person_id. '">edit</a></td>
<td>'.$row->salutation .'</td>
<td>'.'<a href=mailto:'.$row->email.'>'.$row->firstname .'</a></td>
<td>'.'<a href=mailto:'.$row->email.'>'.$row->surname .'</a></td>
<td>'.'<a href=http://'.$row->web_url.'>'.$row->organisation . '</a></td>
<td>'.$row->role.'</td>
<td>'.$row->address1 .'</td>
<td>'.$row->address2 .'</td>
<td>'.$row->city .'</td>
<td>'.$row->postcode .'</td>
<td>'.$row->telephone .'</td>
<td>'.$row->mobile .'</td>
<td>'.$row->fax .'</td>
<td>'.$row->dateoflastcontact.'</td>
<td>'.$row->datecontactagain.'</td>
<td>'.$row->consultation_panel_member.'</td>
<td>'.'<a href=mailto:'.$row->primarycontactemail.'>'.$row->primary_contact.'</td>
<td>'.$row->advertising_grad_jobs.'</td>
<td>'.$row->offer_mscproject .'</td>
<td>'.$row->offer_ugproject.'</td>
<td>'.$row->professional_devactivitites .'</td>
<td>'.$row->bcs_membership .'</td>
<td>'.$row->bcs_pds .'</td>
<td>'.$row->teaching_courses .'</td>
<td>'.$row->academic_consultancy .'<td>';

$count += 1;
}

echo "</table>";
User avatar
ed209
Forum Contributor
Posts: 153
Joined: Thu May 12, 2005 5:06 am
Location: UK

Post by ed209 »

I'm not sure if you mean you want all rows in the database but not all fields for each row OR if you want some rows from the database with all fields.

The latter is easier so I'll tackle that! It can be done just by altering your SQL. So if you want all surnames beginning with 'A' you could

Code: Select all

<?php

// any character you want to search by. 
$char = 'a';

//OR
//you could also create an alphabet stub A B C ... and send a variable in the URL like url.php?char=a
$char = $_GET['char'];



$sql = "SELECT * FROM your_table WHERE SUBSTRING(surname, 1, 1) = '".$char."'";

?>

then just use the code you posted. This will return all fields for the selected rows.
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

Thanks for your reply - Sorry I didnt make myself clear enough.

I want to be able to be able to select the fields I print.

Example, I want to be able to print all the data for the first 8 fields but If the user chooses he should be able to view the rest of the data.

i.e

Users always get to see

Code: Select all

tr> 
        <td><b><small>RecNo</small></b></td> 
        <td><b><small></small></b></td> 
        <td><b><small>Title</small></b></td> 
        <td><a href=\"orderfirstname.html\"><b><small>First Name</small></b></a></td> 
        <td><a href=\"ordersurname.html\"><b><small>Surname</small></b></a></td> 
        <td><a href=\"orderorgdesc.html\"><b><small>Organisation</small></b></a></td> 
        <td><b><center><small>Role</small></center></b></td> 
        <td><b><small>Address(1)</small></b></td> 
        <td><b><small>Address(2)</small></b></td> 
        <td><b><small>City</small></b></td> 
        <td><b><small>Post Code</small></b></td> 
        <td><b><small>Telephone</small></b></td> 
        <td><b><small>Mobile</small></b></td> 
        <td><b><small>Fax</small></b></td> 
        <td><b><small>Last Contact</small></b></td>
But I have an additional field on the end of this perhaps

Code: Select all

<td>More Info</td>
When you click on this it produces the rest of the data from this table. i.e

Code: Select all

<td><b><small>Last Contact</small></b></td> 
        <td><b><small>Contact Again</small></b></td> 
        <td><b><small>Consultation Panel</small></b></td> 
        <td><b><small>Primary Contact</small></b></td> 
        <td><b><small>Graduate Jobs</small></b></td> 
        <td><b><small>MSC Projects</small></b></td> 
        <td><b><small>UG Projects</small></b></td> 
        <td><b><small>Professional Dev</small></b></td> 
        <td><b><small>BCS Mem.</small></b></td> 
        <td><b><small>BCS PDS</small></b></td> 
        <td><b><small>Teaching</small></b></td> 
        <td><b><small>Academic Consultancy</small></b></td>";
Any ideas on how this is done or tutorials or tips please
User avatar
ed209
Forum Contributor
Posts: 153
Joined: Thu May 12, 2005 5:06 am
Location: UK

Post by ed209 »

I haven't tested this but basically, you just cut out the <td>s you don't want with an IF statement. There are better ways, but this seems the quickest considering your current code. The SQL would remain the same so it may mean you pull stuff from the database you don't use but this can be fixed in a similar fashion by have 2 SQL statements and choosing one according to whether they want a full table or not.

The main problem I can see if that if the table is a result of a search (i.e. specific SQL) then you will also have to save that somewhere when clicking on the more info link

Code: Select all

<?php

// here we decide whether we want a full table or not - do this by sending a get variable or other means
$output_full_table = (isset($_GET['full_table'])) ? $_GET['full_table'] : 0;

while ($row = mysql_fetch_object($sql))
{

($color==$color2)? $color = $color1 : $color = $color2; 


$table_row .= "<tr bgcolor=\"$color\"><td>".$count . '</td> 

<td>'.'<a href="editpeople.html?person_id='.$row->person_id. '">edit</a></td> 
<td>'.$row->salutation .'</td> 
<td>'.'<a href=mailto:'.$row->email.'>'.$row->firstname .'</a></td> 
<td>'.'<a href=mailto:'.$row->email.'>'.$row->surname .'</a></td> 
<td>'.'<a href=http://'.$row->web_url.'>'.$row->organisation . '</a></td> 
<td>'.$row->role.'</td> 
<td>'.$row->address1 .'</td> 
<td>'.$row->address2 .'</td> 
<td>'.$row->city .'</td> 
<td>'.$row->postcode .'</td> 
<td>'.$row->telephone .'</td> 
<td>'.$row->mobile .'</td> 
<td>'.$row->fax .'</td> 
<td>'.$row->dateoflastcontact.'</td>';

// if we decided we do want a full table then this will happen
if($output_full_table){

	$table_row .= '<td>'.$row->datecontactagain.'</td> 
	<td>'.$row->consultation_panel_member.'</td> 
	<td>'.'<a href=mailto:'.$row->primarycontactemail.'>'.$row->primary_contact.'</td> 
	<td>'.$row->advertising_grad_jobs.'</td> 
	<td>'.$row->offer_mscproject .'</td> 
	<td>'.$row->offer_ugproject.'</td> 
	<td>'.$row->professional_devactivitites .'</td> 
	<td>'.$row->bcs_membership .'</td> 
	<td>'.$row->bcs_pds .'</td> 
	<td>'.$row->teaching_courses .'</td> 
	<td>'.$row->academic_consultancy .'<td></tr>'; 
	
}else{ // else we make a more info link

	$table_row .= '<td colspan="11"><a href="this_url.php?full_table=1">More Info</a></td></tr>';
	
}

	$count += 1; 
} 

echo $table_row;
echo "</table>"

?>
Post Reply