Jump to content

how to reuse mysql result array in php ?


bhrmalik

Recommended Posts

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.