Retrieving data from 4 tables in MYSQL

Discussion in 'PHP' started by greatthings, Nov 30, 2011.

  1. #1
    hmmmmmmmmmmmmmmmmm what seems to be the problem in here??
    it has no output but i think my query is ok, can someone help??

    plzzzzzzzzzzzzzzzzzzzzzzz :(


    $query=" SELECT ta.Last_Name, ta.First_Name, co.CoMaker_Last_Name, co.CoMaker_First_Name, ta.Position, tc.type, ta.Salary, tc.Allowance, tc.Total_Deductions, tc.Net_Take_Home_Pay, tc.Total_Leave, c.Years_in_Service, tc.Remaining_Years_in_Service

    FROM tbl_certification tc, tbl_client c, tbl_loanform lf, tbl_comaker co, tbl_agency ta

    where ta.Employee_ID_NO = c.Employee_ID_NO
    AND c.client_num = lf.client_num
    AND co.CoMaker_ID_Number = ta.Employee_ID_NO
    AND c.client_num = co.client_num
    AND tc.form_num = lf.form_num
    AND lf.form_num = '$formnum' order by tc.type asc";


    $result=mysql_query($query);
    echo mysql_error();
    echo "<form name=\"myform\" method=\"post\" action=\"gate_viewcertificate.php\">";

    //////////////// Now we will display the returned records in side the rows of the table/////////
    while($noticia = mysql_fetch_array($result))
    {
    if($bgcolor=='#f1f1f1'){$bgcolor='#ffffff';}
    else{$bgcolor='#f1f1f1';}
    $lname=$noticia['Last_Name'];
    $fname=$noticia['First_Name'];
    $colname=$noticia['CoMaker_Last_Name'];
    $cofname=$noticia['CoMaker_First_Name'];
    $Position=$noticia['Position'];
    $Salary=$noticia['Salary'];
    $Allowance=$noticia['Allowance'];
    $Total_Deductions=$noticia['Total_Deductions'];
    $Net_Take_Home_Pay=$noticia['Net_Take_Home_Pay'];
    $Total_Leave=$noticia['Total_Leave'];
    $Years_in_Service=$noticia['Years_in_Service'];
    $Remaining_Years_in_Service=$noticia['Remaining_Years_in_Service'];
    $type=$noticia['Type'];
    $co_pos=$noticia['CoMaker_Position'];
    if ($type==1){
    $last=$lname;
    $first=$fname;
    $pos=$Position;}
    else{$last=$colname;
    $first=$cofname;
    $pos=$co_pos;}
    echo "<tr >";
    echo "<td align='left' bgcolor=$bgcolor id='title'>&nbsp;<font face='Verdana' size='2'>".ucwords($last)."&nbsp;".ucwords($first)."&nbsp;</font></td>";
    echo "<td align='center' bgcolor=$bgcolor id='title'>&nbsp;<font face='Verdana' size='2'>".ucwords($pos)."</font></td>";

    echo "<td align='center' bgcolor=$bgcolor id='title'>&nbsp;<font face='Verdana' size='2'>".number_format($Salary)."</font></td>";
    echo "<td align='center' bgcolor=$bgcolor id='title'>&nbsp;<font face='Verdana' size='2'>".number_format($Allowance)."</font></td>";
    echo "<td align='center' bgcolor=$bgcolor id='title'>&nbsp;<font face='Verdana' size='2'>".number_format($Total_Deductions)."</font></td>";
    echo "<td align='center' bgcolor=$bgcolor id='title'>&nbsp;<font face='Verdana' size='2'>".number_format($Net_Take_Home_Pay)."</font></td>";
    echo "<td align='center' bgcolor=$bgcolor id='title'>&nbsp;<font face='Verdana' size='2'>".number_format($Total_Leave)."</font></td>";
    echo "<td align='center' bgcolor=$bgcolor id='title'>&nbsp;<font face='Verdana' size='2'>".number_format($Years_in_Service)."</font></td>";
    echo "<td align='center' bgcolor=$bgcolor id='title'>&nbsp;<font face='Verdana' size='2'>".number_format($Remaining_Years_in_Service)."</font></td>";

    echo "</tr>";
    }
    echo "</table><p>&nbsp;</p>";
     
    Solved! View solution.
    greatthings, Nov 30, 2011 IP
  2. mfscripts

    mfscripts Banned

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    8
    Trophy Points:
    90
    Digital Goods:
    3
    #2
    When you say no output, do you mean do data is being displayed or the script is failing?

    Have you run your sql query directly in your sql client?
     
    mfscripts, Nov 30, 2011 IP
  3. greatthings

    greatthings Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    no data outputted but there is no error in my query.
    yes i run it directly on my mysql client

    hmmmmmm im using 5 tables maybe it cant handle that much table,
     
    greatthings, Nov 30, 2011 IP
  4. #4
    It'll handle them fine in PHP. Try seeing whether there's any data coming back from the query by echoing the number of rows:

    $result=mysql_query($query);
    echo mysql_num_rows($result);
     
    mfscripts, Nov 30, 2011 IP
  5. mfscripts

    mfscripts Banned

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    8
    Trophy Points:
    90
    Digital Goods:
    3
    #5
    mfscripts, Nov 30, 2011 IP
  6. Javed iqbal

    Javed iqbal Well-Known Member

    Messages:
    445
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #6
    i canhelp you quick if you give me access to db and php file
     
    Javed iqbal, Nov 30, 2011 IP
  7. greatthings

    greatthings Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    got the solution! anyways thnx guys!! :) thnx for the support all the time
     
    greatthings, Dec 1, 2011 IP