bhrmalik Posted January 2, 2011 Share Posted January 2, 2011 Hello, I need some help in retrieve and display data from MySQL table where, I had a table name “employees” contents : --------------------------------------------------------- id|emp_name|report_to --------------------------------------------------------- 01|Scott|00 02|John|01 03|Martin|01 04|Smith|02 05|Sam|00 06|Henry|02 --------------------------------------------------------- "00" report_to should be report direct/null. One more thing is it possible to display the ID with leading zero. If I want to see the "01" the display should be. --------------------------------------------------------- MID|Manager|TLID|TeamLeader|EmpID|Employees --------------------------------------------------------- 01|Scott|02|John|04|Smith 01|Scott|02|John|06|Henry 01|Scott|03|Martin|--|------ If I want to see the "02" the display should be. --------------------------------------------------------- TLID|TeamLeader|EmpID|Employees --------------------------------------------------------- 02|John|04|Smith 02|John|06|Henry --------------------------------------------------------- I am using the this code in php : PHP CODE : $sql="select t1.id, t1.emp_name from employees as t1 where report_to='$_POST[text]' "; $data=mysql_query($sql) or die(mysql_error()); echo "<table border='2'>"; while ($rec=mysql_fetch_row($data)) echo "<tr><td>$rec[0]</td><td>$rec[1]</td></tr>"; echo " </table>"; ?> <br /> <form method="post" action=""> Username:<input type="text" name="text" /> <input type="submit" value="Submit" /> </form> --------------------------------------- Hope to meet some expert here Who will guide me to the right direction. Any help will be appreciated. Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/223208-how-to-reuse-mysql-result-array-in-php/ Share on other sites More sharing options...
BLaZuRE Posted January 2, 2011 Share Posted January 2, 2011 "00" report_to should be report direct/null. Okay, so make sure that column allows NULL values and make it NULL. One more thing is it possible to display the ID with leading zero. If I want to see the "01" the display should be. Well, check the id. If it's less than 10, echo out a leading 0. Also, your form action leads nowhere. I think you're trying to send to the same page, so put your page in there. What happens if you don't submit an ID and what happens if that's the first time you visit that page? Is that elsewhere in your code? Quote Link to comment https://forums.phpfreaks.com/topic/223208-how-to-reuse-mysql-result-array-in-php/#findComment-1153948 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.