Jump to content

Recommended Posts

Hi,

New to PHP and webby things in general. I am attempting to put together a play application to learn how this stuff is done. Please be gentle.

 

What I want to be able to to.

 

Perform an SQL query (I can do this) Say the query returns client names.

Display results in a table (I can do this into an HTML table)

make the table rows click able, such that double clicking on a row opens a new page with detailed info on that person.

 

Now I can sort of do this...

 

<?
$i=0 ;
While ($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
 print "<tr ondblclick='showPerson (" . $row{'id'} . ")' >" ;

 print("<td width=\"25%\"><center>" . $row{'id'}  . "</td>");
 print("<td width=\"25%\"><left>" . $row{'last_name'}  . "</td>");
 print("<td width=\"25%\"><left>" . $row{'first_name'} . "</td>");
 print("<td width=\"25%\"><center>" . $row{'birthdate'} . "</td>");

 print"</tr>" ;
 $i++ ;
}

?>

 

Works just like I want. The table is shown, the values are correct. If I click on a row, the Javascript showPerson runs and (for now) just displays the ID, so things are working as expected.

 

The question. How to get a new php page open (person_details.php ?) that now goes and gets client info (address, phone #s, etc) and displays it (based on the ID selected)

OR

Is this not how I should be attempting this. Remember, new to all things webby...

(I do understand the client/server side differences of javascript vs PHP,

but do not know how to structure this type of application to do what i want)

 

Thanks in advance,

Joe

 

 

Link to comment
https://forums.phpfreaks.com/topic/102994-php-mysql-and-html-tables/
Share on other sites

Your origional page

<?php
$i=0 ;
While ($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
  print "<tr ondblclick='showPerson (" . $row{'id'} . ")' >" ;

  print("<td width=\"25%\"><center><a href='person_details.php?id=".$row{'id'}."'>".$row['id']."</a></td>");
  print("<td width=\"25%\"><left>".$row{'last_name'}."</td>");
  print("<td width=\"25%\"><left>".$row{'first_name'}."</td>");
  print("<td width=\"25%\"><center>".$row{'birthdate'}."</td>");

  print"</tr>" ;
  $i++ ;
}

?>

person_details.php

<?php
$id = addslashes($_GET['id']); /* keeps them from injecting anything to the mysql query */
$sql = "SELECT * FROM `table_name` WHERE `id` = '{$id}' LIMIT 1;";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)){
//output your data from the db
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.