Jump to content

Error: Resource id #33


monkeypaw201

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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