how to reuse the result array ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bhrmalik
    New Member
    • Jan 2011
    • 1

    #1

    how to reuse the result array ?

    Hello,

    I need some help in retrieve and display data from MySQL table where, I had a table name “employees ”
    contents :
    ---------------------------------------------------------
    id|emp_name|rep ort_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|TLI D|TeamLeader|Em pID|Employees
    ---------------------------------------------------------
    01|Scott|02}Joh n|04|Smith
    01|Scott|02|Joh n|06|Henry
    01|Scott|03|Mar tin|--|------

    If I want to see the "02" the display should be.
    ---------------------------------------------------------
    TLID|TeamLeader |EmpID|Employee s
    ---------------------------------------------------------
    02|John|04|Smit h
    02|John|06|Henr y
    ---------------------------------------------------------

    I am using this code in php :
    Code:
    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

    Any help will be appreciated.

    Thanks in advance
  • HaLo2FrEeEk
    Contributor
    • Feb 2007
    • 404

    #2
    Could you reword your question, I really don't understand it. It looks like you want the report_to value for Scott and Sam to be null. For all intents and purposes, 0 is null. You can interpret 0 however you want. I assume that Scott and Sam are high-ups who report to no one, and other people report to them, right? So Henry and Smith report to John, and John and Martin report to Scott, but Scott doesn't report to anyone because he's the boss. In that case when you query the database just order the results by report_to and it'll to 0, 1, 2, or Scott, John, Henry (etc.)

    As far as displaying leading 0's just use str_pad().

    As for the last question, I really don't know what you're trying to ask. Sorry.

    Comment

    Working...