genzedu777 Posted January 20, 2011 Share Posted January 20, 2011 Hi, I will really need some help here. I have posted this similar topic quite a number of times, however no one could actually give me a solution. Currently when I execute the code, it seems like "mysqli_num_rows($data3) !== 1", therefore my {else} command was executed instead. "else {echo '<p class="error">There was a problem accessing your profile.</p>';}" I have no idea what went wrong, and if you look at my attachment.jpg, there are 3 columns 1) overall_level_subject_id 2) tutor_id 3) subject_level_id The thing is that, there are similar tutor_id appearing in this table and it may not be in sequence, take for example... overall_level_subject_id: 10 tutor_id: T532uu subject_level_id: 11 overall_level_subject_id: 51 tutor_id: T532uu subject_level_id: 12 I'm not too sure if you guys understand what I am explaining. But I really need help in this area! Please advice! <?php /*************************Teaching Subjects*************************/ $query3 = "SELECT subject_level_id FROM tutor_overall_level_subject WHERE tutor_id = '" . $_GET['tutor_id'] . "'"; $data3 = mysqli_query($dbc, $query3) or die(mysqli_error($dbc)); if (mysqli_num_rows($data3) == 1) { echo '<div id="panel4">'; echo'<table><tr>'; $count = 0; // Start your counter while($row3 = mysqli_fetch_array($data3)) { if ($count % 5 == 0) { echo "</tr><tr>"; $count = 0; } echo '<td class="label">' . $row3['subject_level_id'] . '</td><td>' . $row3['subject_level_id'] . '</td>'; $count++; } echo '</tr></table><br/>'; echo '</div>'; //End of panel 4 } //End of IF for $query and $data (Teaching Subjects) else { echo '<p class="error">There was a problem accessing your profile.</p>'; } ?> [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/225084-not-able-to-call-out-any-values-from-database-using-php-codes/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 20, 2011 Share Posted January 20, 2011 Start by echoing or use var_dump() on mysqli_num_rows($data3) so that you know exactly what it is. If it is zero, find out exactly what value is in $_GET['tutor_id'] (use var_dump()) and find out why that doesn't match an entry in your table. If it is greater-than 1, find out why you have duplicate data in your table. Quote Link to comment https://forums.phpfreaks.com/topic/225084-not-able-to-call-out-any-values-from-database-using-php-codes/#findComment-1162528 Share on other sites More sharing options...
genzedu777 Posted January 20, 2011 Author Share Posted January 20, 2011 Hi PFMaBiSmAd, Thanks for your reply, I have tried var_dump in "$data3 = var_dump(mysqli_query($dbc, $query3))". It has returned me with this value...object(mysqli_result)#5 (0) { } Which I don't quite understand what it means. Suffice to say, why I have duplicated tutor_id in my table, it's because, each tutor_id carries different subject_level_id. Therefore there can be many similar tutor_id tagged to only one unique subject_level_id. Below is the example. Could you kindly advice what is the next step to solve the problem? 1) overall_level_subject_id 2) tutor_id 3) subject_level_id overall_level_subject_id: 10 tutor_id: T532uu subject_level_id: 11 (Represent 'English') overall_level_subject_id: 51 tutor_id: T532uu subject_level_id: 12 (Represent 'Math') Quote Link to comment https://forums.phpfreaks.com/topic/225084-not-able-to-call-out-any-values-from-database-using-php-codes/#findComment-1162532 Share on other sites More sharing options...
hoogie Posted January 20, 2011 Share Posted January 20, 2011 Try: echo mysqli_num_rows($data3); This will show you the number of rows being returned. My guess is that you are getting the error message because your query is returning more than one row with the same tutor_id. Right now your code will only execute if your query returns one row and one row only. Looking at your code, I think that maybe instead of this: if (mysqli_num_rows($data3) == 1) { you might want this: if (mysqli_num_rows($data3) > 0) { But maybe I'm not understanding what you're trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/225084-not-able-to-call-out-any-values-from-database-using-php-codes/#findComment-1162541 Share on other sites More sharing options...
mikosiko Posted January 20, 2011 Share Posted January 20, 2011 same answer that was given to him here http://www.phpfreaks.com/forums/mysql-help/you-have-an-error-in-your-sql-syntax-321480/msg1514672/#msg1514672 Quote Link to comment https://forums.phpfreaks.com/topic/225084-not-able-to-call-out-any-values-from-database-using-php-codes/#findComment-1162564 Share on other sites More sharing options...
genzedu777 Posted January 21, 2011 Author Share Posted January 21, 2011 Hi mikosiko, I understand you have given me an answer, but it's not completely helpful as it was just stating the fact not a solution. Hi hoogie & PFMaBiSmAd, Correct me if I am wrong. I always think that if (mysqli_num_rows($data3) == 1), what does this mean? Does it mean "mysqli_num_rows($data3)" will search through the sql table, and if tutor_id == 1, then they will pull out the results? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/225084-not-able-to-call-out-any-values-from-database-using-php-codes/#findComment-1162799 Share on other sites More sharing options...
PFMaBiSmAd Posted January 21, 2011 Share Posted January 21, 2011 The php manual contains a description of all the php functions - http://www.php.net/manual/en/mysqli-result.num-rows.php There's no reason why you need to guess what any function does. Quote Link to comment https://forums.phpfreaks.com/topic/225084-not-able-to-call-out-any-values-from-database-using-php-codes/#findComment-1162807 Share on other sites More sharing options...
mikosiko Posted January 21, 2011 Share Posted January 21, 2011 The php manual contains a description of all the php functions - http://www.php.net/manual/en/mysqli-result.num-rows.php There's no reason why you need to guess what any function does. wow PFM,,, but that is fact no completely helpful... not a solution Quote Link to comment https://forums.phpfreaks.com/topic/225084-not-able-to-call-out-any-values-from-database-using-php-codes/#findComment-1162830 Share on other sites More sharing options...
mikosiko Posted January 21, 2011 Share Posted January 21, 2011 Hi mikosiko, I understand you have given me an answer, but it's not completely helpful as it was just stating the fact not a solution. genzedu... read my signature.... what do you want... the fish or learn how to fishing? .... part of be a programmer (and sometime the most important) is learn how to debug your own code... specially when you are getting help and clues from others... if you are not capable or you don't know how to do it... just say so and ask Quote Link to comment https://forums.phpfreaks.com/topic/225084-not-able-to-call-out-any-values-from-database-using-php-codes/#findComment-1162831 Share on other sites More sharing options...
hoogie Posted January 21, 2011 Share Posted January 21, 2011 Correct me if I am wrong. I always think that if (mysqli_num_rows($data3) == 1), what does this mean? Does it mean "mysqli_num_rows($data3)" will search through the sql table, and if tutor_id == 1, then they will pull out the results? It means that IF there is exactly one row in the variable $data3 THEN it will execute the rest of the code in the IF block. If $data3 has less or more than 1 row, it will not execute the code and will go instead to the ELSE block. I think the others are right, though - it sounds like you may need to do a little more research to understand how these things work. If you need a good place to start learning, I really like this guide: http://www.tuxradar.com/practicalphp It's easy to read and will give you a good idea of why things work the way they do. Quote Link to comment https://forums.phpfreaks.com/topic/225084-not-able-to-call-out-any-values-from-database-using-php-codes/#findComment-1162837 Share on other sites More sharing options...
genzedu777 Posted January 22, 2011 Author Share Posted January 22, 2011 Hi everyone, Thanks for the advice. Appreciate it! Quote Link to comment https://forums.phpfreaks.com/topic/225084-not-able-to-call-out-any-values-from-database-using-php-codes/#findComment-1163399 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.