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!
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.
<?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.
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
<?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>"
?>