jbsimon000 Posted April 26, 2008 Share Posted April 26, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/102994-php-mysql-and-html-tables/ Share on other sites More sharing options...
Daniel0 Posted April 26, 2008 Share Posted April 26, 2008 You could use window.open to open a new window leading to a page where you'd get that info. person_details?id=684 for instance. Quote Link to comment https://forums.phpfreaks.com/topic/102994-php-mysql-and-html-tables/#findComment-527606 Share on other sites More sharing options...
jonsjava Posted April 26, 2008 Share Posted April 26, 2008 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/102994-php-mysql-and-html-tables/#findComment-527607 Share on other sites More sharing options...
jbsimon000 Posted April 26, 2008 Author Share Posted April 26, 2008 Thanks Daniel and Jon, I will give these a try. Quote Link to comment https://forums.phpfreaks.com/topic/102994-php-mysql-and-html-tables/#findComment-527620 Share on other sites More sharing options...
jbsimon000 Posted April 26, 2008 Author Share Posted April 26, 2008 Follow up: Thanks Jon, That Works perfectly. Next question. Do I need to re-connect to the database on each page, or can I pass the connection info from first (main) page to subsequent pages ? Thanks Again ! Joe Quote Link to comment https://forums.phpfreaks.com/topic/102994-php-mysql-and-html-tables/#findComment-527624 Share on other sites More sharing options...
Daniel0 Posted April 26, 2008 Share Posted April 26, 2008 Next question. Do I need to re-connect to the database on each page, or can I pass the connection info from first (main) page to subsequent pages ? You need to connect again. Quote Link to comment https://forums.phpfreaks.com/topic/102994-php-mysql-and-html-tables/#findComment-527628 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.