Jump to content

PHP, mysql and HTML Tables


jbsimon000

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
}
?>

Archived

This topic is now archived and is closed to further replies.

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