xiaoxin22 Posted July 8, 2010 Share Posted July 8, 2010 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)); Quote Link to comment https://forums.phpfreaks.com/topic/207112-problem-with-mysql_fetch_assoc-help-anyone/ Share on other sites More sharing options...
trq Posted July 8, 2010 Share Posted July 8, 2010 You have failed to check your query's actually succeed before passing there results to mysql_fetch_assoc. Quote Link to comment https://forums.phpfreaks.com/topic/207112-problem-with-mysql_fetch_assoc-help-anyone/#findComment-1082963 Share on other sites More sharing options...
xiaoxin22 Posted July 9, 2010 Author Share Posted July 9, 2010 if that is what you are asking.. yes, i did.. my query is working fine.. Quote Link to comment https://forums.phpfreaks.com/topic/207112-problem-with-mysql_fetch_assoc-help-anyone/#findComment-1083350 Share on other sites More sharing options...
trq Posted July 9, 2010 Share Posted July 9, 2010 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. } ?> Quote Link to comment https://forums.phpfreaks.com/topic/207112-problem-with-mysql_fetch_assoc-help-anyone/#findComment-1083357 Share on other sites More sharing options...
xiaoxin22 Posted July 9, 2010 Author Share Posted July 9, 2010 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'; } Quote Link to comment https://forums.phpfreaks.com/topic/207112-problem-with-mysql_fetch_assoc-help-anyone/#findComment-1083370 Share on other sites More sharing options...
xiaoxin22 Posted July 12, 2010 Author Share Posted July 12, 2010 thanks everyone.. i found the solution.. haha. quite dumb actually.. i just cut and put the whole query into the do while loop.. Quote Link to comment https://forums.phpfreaks.com/topic/207112-problem-with-mysql_fetch_assoc-help-anyone/#findComment-1084667 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.