Jump to content

problem with mysql_fetch_assoc.. help anyone?


xiaoxin22

Recommended Posts

this is the sql query i did.. but i can't get the details for $print6['o_department'], it only retrieve the first detail..

i believe is my while ($print = mysql_fetch_assoc($result)); problem..

can someone help?

 

 

 

$result = mysql_query($query);

$print = mysql_fetch_assoc($result);

 

$query2 = sprintf("SELECT *  FROM (c_details INNER JOIN c_color ON c_details.cc_id = c_color.cc_id)  WHERE c_color.cc_id = '%s'",

mysql_real_escape_string($print['cc_id']));

$result2 = mysql_query($query2);

$print2 = mysql_fetch_assoc($result2);

 

$query3 = sprintf("SELECT *  FROM (c_details INNER JOIN c_package ON c_details.p_id = c_package.p_id) WHERE c_package.p_id = '%s'",

mysql_real_escape_string($print['p_id']));

$result3 = mysql_query($query3);

$print3 = mysql_fetch_assoc($result3);

 

$query4 = sprintf("SELECT *  FROM (c_details INNER JOIN c_projects ON c_details.pro_id = c_projects.pro_id) WHERE c_projects.pro_id = '%s'",

mysql_real_escape_string($print['pro_id']));

$result4 = mysql_query($query4);

$print4 = mysql_fetch_assoc($result4);

 

$query5 = sprintf("SELECT *  FROM (c_details INNER JOIN c_status ON c_details.s_id = c_status.s_id) WHERE c_status.s_id = '%s'",

mysql_real_escape_string($print['s_id']));

$result5 = mysql_query($query5);

$print5 = mysql_fetch_assoc($result5);

 

$query6 = sprintf("SELECT * FROM (c_status INNER JOIN c_operation ON c_status.o_id = c_operation.o_id) WHERE c_operation.o_id = '%s'",

mysql_real_escape_string($print5['o_id']));

$result6 = mysql_query($query6);

$print6 = mysql_fetch_assoc($result6);

 

 

 

 

 

echo '<a class=' .$icon . 'href="edit.php?d_id=' . $print['d_id'] . '">' . $print['c_cname'] . '<span><ul id=details>' . '<li>Company Name: ' . $print['c_cname'] .' '. $print3['p_package'] .'<li>Colour: '. $print2['cc_color'] .' ('. $print2['cc_remarks'] .')'. '</li>' . '<li>Domain Name: ' . $print['c_domain'] .'</li>'. '<li>Contact Person: ' . $print['d_addressee'] ." ". $print['d_name'] . '</li>' . '<li>Contact No: ' . $print['d_contact']. '</li>' . '<li>Email: ' . $print['d_email'] . '<li>' . 'Address: ' . $print['d_address'] . ' S(' . $print['d_postal'] . ')' .'</li>' . '<li>Project: ' . $print4['pro_projects'] . '</li>' .'<li>Status: ' . $print5['s_status'] .' ('.$print6['o_department'] .')'. '</li></ul></span>' . '</a>';

} while ($print = mysql_fetch_assoc($result));

You need to always do it within your code. At minimum a SELECT query should look something like....

 

<?php

$sql = "SELECT foo FROM bar";
if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
        // within here $result contains a valid result resource
        // which contains records.
        $row = mysql_fetch_assoc($result);
    } else {
        // no records found, handle error.
    }
} else {
    // query failed, handle error.
}

?>

so is it this way??

 

$sql = "SELECT * FROM (c_status INNER JOIN c_operation ON c_status.o_id = c_operation.o_id) WHERE c_operation.o_id = $print5['o_id']";

if ($read = mysql_query($sql)) {

if (mysql_num_rows($read)) {

echo '<a class=' .$icon . 'href="edit.php?d_id=' . $print['d_id'] . '">' . $print['c_cname'] . '<span><ul id=details>' . '<li>Company Name: ' . $print['c_cname'] .' '. $print3['p_package'] .'<li>Colour: '. $print2['cc_color'] .' ('. $print2['cc_remarks'] .')'. '</li>' . '<li>Domain Name: ' . $print['c_domain'] .'</li>'. '<li>Contact Person: ' . $print['d_addressee'] ." ". $print['d_name'] . '</li>' . '<li>Contact No: ' . $print['d_contact']. '</li>' . '<li>Email: ' . $print['d_email'] . '<li>' . 'Address: ' . $print['d_address'] . ' S(' . $print['d_postal'] . ')' .'</li>' . '<li>Project: ' . $print4['pro_projects'] . '</li>' .'<li>Status: ' . $row['s_id'] .' ('.$print6['o_department'] .')'. '</li></ul></span>' . '</a>';

$row = mysql_fetch_assoc($read);

} else {

echo 'error 1';

}

} else {

echo 'error 2';

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.