Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> MySQL
Author Message
plankton
New Member
New Member



Joined: Jan 22, 2007
Posts: 20

PostPosted: Fri Feb 16, 2007 7:43 pm Reply with quote

I hope this the is right place?

Ok... so I'm stuck on this, I need the second of these 'If' statements to work...



$result = $db->sql_numrows($db->sql_query("SELECT * FROM my_table WHERE username='$username'"));
$result2 = $db->sql_fetchrow($db->sql_query("SELECT `gid` FROM ".$prefix."_nsngr_users WHERE uname='$username'"));
$user_gid = $result2['gid'];
$result3 = $db->sql_fetchrow($db->sql_query("SELECT `my_int`, `gname` FROM ".$prefix."_nsngr_groups WHERE gid='$user_gid'"));
$myvar = $result3['my_int'];

Now this works fine..... Very Happy

if ($result > 1){
@include("header.php");
OpenTable();
echo "<center>You are in group ($user_gid) $gname</center><br>\n";
echo "<center>The maximum monthly Downloadeds for '$gname' group is: $myvar </center><br>\n";
echo "<center>You have Downloaded $result files this month</center><br>\n";
echo "<center>"._GOBACK."</center>\n";
CloseTable();
@include("footer.php");
}

But my problem is, if I change it to this...

if ($result == $myvar){
Bla Bla - As Above -
}

Why won't this work?

Yes! I'm trying to limit the # of downloads (for bandwidth reasons) a group are allowed per 'given' period.

This coding lark is quite new to me so please forgive me if the answer obvious. I just can't seem to see whats wrong myself. Crying or Very sad
 
View user's profile Send private message
Guardian2003
Site Admin



Joined: Aug 28, 2003
Posts: 6799
Location: Ha Noi, Viet Nam

PostPosted: Fri Feb 16, 2007 8:49 pm Reply with quote

The first thing to check is that $result has a value after the first query.
 
View user's profile Send private message Send e-mail
kguske
Site Admin



Joined: Jun 04, 2004
Posts: 6437

PostPosted: Fri Feb 16, 2007 10:00 pm Reply with quote

What isn't working? Is the condition not true? Are both $result and $myvar integers?

_________________
I search, therefore I exist...
Only registered users can see links on this board! Get registered or login!
 
View user's profile Send private message
plankton







PostPosted: Sat Feb 17, 2007 4:54 am Reply with quote

Hi, thanks for the quick responce...

Guardian2003... Yes, $result returns a value depending on how many downloads a user has completed... (for test purposes 4).

kguske... Yes, both $result and $myvar are integers.

When I use 'if ($result > 1){...' the condition is true and the page is displayed.

But if I change it to 'if ($result == $myvar){...' the condition starts false but Will be true when the user has completed '$myvar' number of downloads.

The idea is that once the user has completed '$myvar' number of downloads, on attempting another the page is displayed instead of the download dialog therefore blocking any further downloads.

Well thats the plan anyway!!!
 
fkelly
Former Moderator in Good Standing



Joined: Aug 30, 2005
Posts: 3312
Location: near Albany NY

PostPosted: Sat Feb 17, 2007 4:33 pm Reply with quote

You can easily do your own diagnostics when you are having a problem like this. Just before the if test echo out the values of the variables, something like:

Code:
echo 'result: ' . $result . ' myvar: ' . $myvar . '<br />'


would give you an indication of what is going on.

Second ... I don't have the field definitions for nsngr_groups in front of me but I don't recall any my_int field. Did you add one? Are you updating it thru some separate process?
 
View user's profile Send private message Visit poster's website
plankton







PostPosted: Sat Feb 17, 2007 8:03 pm Reply with quote

Hi fkelly,

that's a nice little tip, I'll give that a go.

Yes! to both your questions, I've add 'my_int' to the groups table which is set/updated through a modded groups admin. Smile
 
fkelly







PostPosted: Sun Feb 18, 2007 12:14 am Reply with quote

oh my gosh, don't forget the semi colon after the '<br />'

I was on a strange computer when I typed that. I don't make syntactical errors like that, LOL.
 
nanocaiordo
New Member
New Member



Joined: Feb 17, 2007
Posts: 2
Location: Italy

PostPosted: Sun Feb 18, 2007 5:33 am Reply with quote

if ($result < $myvar) { ... } // he hasn't completed the num of downloads yet
else { ... } // $result is greater-then over equal to $myvar
 
View user's profile Send private message
plankton







PostPosted: Fri Feb 23, 2007 11:55 am Reply with quote

Right... I finaly got back to it,

thanks nanocaiordo

I changed 'If ($result == $myvar){...}' to 'If ($result >= $myvar){...}

and that works great. Very Happy

I find that a bit strange though because if I set a limit ($myvar) then query to see how many DL's user has completed ($result) and block any further DL's, once $result = $myvar they can't download anymore.... so $result can never be > than $myvar...

But... like I said 'it works' so thats great Very Happy

Thanks to all for the help
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> MySQL

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©