monkeypaw201 Posted May 24, 2008 Share Posted May 24, 2008 I have some code.... <?php mysql_select_db($database_vamsys, $vamsys); $query_rank = sprintf("SELECT * FROM vamsys_ranks"); $rank = mysql_query($query_rank, $vamsys) or die(mysql_error()); $row_rank = mysql_fetch_assoc($rank); $totalRows_rank = mysql_num_rows($rank); if($row_hour_count['hour_count'] > $row_rank['hours']) { $rank = $row_rank['title']; } ?> and when i try to display $rank with <?php echo $rank; ?> i get the following displayed: Resource id #33 I have no clue what that means... any help? Link to comment https://forums.phpfreaks.com/topic/107091-error-resource-id-33/ Share on other sites More sharing options...
jonsjava Posted May 24, 2008 Share Posted May 24, 2008 Try this: <?php print_r($rank); ?> Link to comment https://forums.phpfreaks.com/topic/107091-error-resource-id-33/#findComment-549012 Share on other sites More sharing options...
monkeypaw201 Posted May 24, 2008 Author Share Posted May 24, 2008 Try this: <?php print_r($rank); ?> outputs.. Resource id #331 Link to comment https://forums.phpfreaks.com/topic/107091-error-resource-id-33/#findComment-549017 Share on other sites More sharing options...
jonsjava Posted May 24, 2008 Share Posted May 24, 2008 ah, I see. then try this: <?php mysql_select_db($database_vamsys, $vamsys); $query_rank = sprintf("SELECT * FROM vamsys_ranks"); $rank = mysql_query($query_rank, $vamsys) or die(mysql_error()); $row_rank = mysql_fetch_assoc($rank); $totalRows_rank = mysql_num_rows($rank); if($row_hour_count['hour_count'] > $row_rank['hours']) { $rank1 = $row_rank['title']; print $rank1; } else{ print "Row Hour count is not greater than row_rank(Hours)"; //this will tell you if you're not meeting the requirements. } ?> Link to comment https://forums.phpfreaks.com/topic/107091-error-resource-id-33/#findComment-549019 Share on other sites More sharing options...
.josh Posted May 24, 2008 Share Posted May 24, 2008 The resource id#331 means that you made a query to the db and it returned a result (as opposed to failing for whatever reason and returning false). The good news is that that means your query is okay. From there, first thing I would check is to make sure that 'title' is actually a column name (spelled right, etc..) in your vamsys_ranks table. Link to comment https://forums.phpfreaks.com/topic/107091-error-resource-id-33/#findComment-549022 Share on other sites More sharing options...
monkeypaw201 Posted May 24, 2008 Author Share Posted May 24, 2008 ah, I see. then try this: <?php mysql_select_db($database_vamsys, $vamsys); $query_rank = sprintf("SELECT * FROM vamsys_ranks"); $rank = mysql_query($query_rank, $vamsys) or die(mysql_error()); $row_rank = mysql_fetch_assoc($rank); $totalRows_rank = mysql_num_rows($rank); if($row_hour_count['hour_count'] > $row_rank['hours']) { $rank1 = $row_rank['title']; print $rank1; } else{ print "Row Hour count is not greater than row_rank(Hours)"; //this will tell you if you're not meeting the requirements. } ?> output... Row Hour count is not greater than row_rank(Hours) so now i have a slight dilemma.. i need to select the rank of a user based on how many hours they have and then display that, but i tried looking it with a do..while loop which caused a lot of errors... im not sure how i can get it to do what i want... do you have any recommendations? Link to comment https://forums.phpfreaks.com/topic/107091-error-resource-id-33/#findComment-549023 Share on other sites More sharing options...
jonsjava Posted May 24, 2008 Share Posted May 24, 2008 the problem was that he was failing the if statement. If he had passed the if statement, he wouldn't have gotten the resource id. He reused $rank (which was originally the query), so when he failed the if statement, $rank became the query, instead of a result element. Link to comment https://forums.phpfreaks.com/topic/107091-error-resource-id-33/#findComment-549024 Share on other sites More sharing options...
jonsjava Posted May 24, 2008 Share Posted May 24, 2008 if($row_hour_count['hour_count'] > $row_rank['hours']) where are you setting $row_hour_count ? Link to comment https://forums.phpfreaks.com/topic/107091-error-resource-id-33/#findComment-549026 Share on other sites More sharing options...
monkeypaw201 Posted May 24, 2008 Author Share Posted May 24, 2008 farther up the page: <?php $colname_hour_count = $_SESSION['pilot_id']; if (isset($_GET['pilot_id'])) { $colname_hour_count = $_GET['pilot_id']; } mysql_select_db($database_vamsys, $vamsys); $query_hour_count = sprintf("SELECT SUM(time_enroute) AS hourcount FROM vamsys_pireps WHERE pilot_id = %s AND status = 'Approved'", GetSQLValueString($colname_hour_count, "text")); $hour_count = mysql_query($query_hour_count, $vamsys) or die(mysql_error()); $row_hour_count = mysql_fetch_assoc($hour_count); $totalRows_hour_count = mysql_num_rows($hour_count); ?> Link to comment https://forums.phpfreaks.com/topic/107091-error-resource-id-33/#findComment-549028 Share on other sites More sharing options...
jonsjava Posted May 24, 2008 Share Posted May 24, 2008 have you tried doing a different query, something like (I'm just using examples, mind you) SELECT `user`, `hours` FROM `vamsys_pireps` ORDER BY `hours` DESC; This would give you all your users, from most hours to least hours. You could then add them into 2 arrays (or a multi dimensional array), and update their rank from there. Link to comment https://forums.phpfreaks.com/topic/107091-error-resource-id-33/#findComment-549033 Share on other sites More sharing options...
monkeypaw201 Posted May 24, 2008 Author Share Posted May 24, 2008 have you tried doing a different query, something like (I'm just using examples, mind you) SELECT `user`, `hours` FROM `vamsys_pireps` ORDER BY `hours` DESC; This would give you all your users, from most hours to least hours. You could then add them into 2 arrays (or a multi dimensional array), and update their rank from there. Well they each have their own "WHERE" statements and i don't think you can mix them, can you? Link to comment https://forums.phpfreaks.com/topic/107091-error-resource-id-33/#findComment-549035 Share on other sites More sharing options...
jonsjava Posted May 24, 2008 Share Posted May 24, 2008 Well, I'm going to stop helping for a while (wife wants me to go do stuff) can someone else take over this one for me? Link to comment https://forums.phpfreaks.com/topic/107091-error-resource-id-33/#findComment-549036 Share on other sites More sharing options...
monkeypaw201 Posted May 24, 2008 Author Share Posted May 24, 2008 Now... i am looking at using something like this: <?php if($row_hour_count['hour_count'] > $row_rank['hours']) { $rank1 = $row_rank['title']; } elseif($row_hour_count['hour_count'] > $row_rank['hours']) { $rank1 = $row_rank['title']; } ?> but i need the IF statement to have the first result, and the ELSEIF have the second, with the ELSEIF looping to check all results Link to comment https://forums.phpfreaks.com/topic/107091-error-resource-id-33/#findComment-549038 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.