Author |
Message |
plankton
New Member


Joined: Jan 22, 2007
Posts: 20
|
Posted:
Fri Feb 16, 2007 7:43 pm |
|
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.....
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.  |
|
|
|
 |
Guardian2003
Site Admin

Joined: Aug 28, 2003
Posts: 6799
Location: Ha Noi, Viet Nam
|
Posted:
Fri Feb 16, 2007 8:49 pm |
|
The first thing to check is that $result has a value after the first query. |
|
|
|
 |
kguske
Site Admin

Joined: Jun 04, 2004
Posts: 6437
|
Posted:
Fri Feb 16, 2007 10:00 pm |
|
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! |
|
|
 |
plankton

|
Posted:
Sat Feb 17, 2007 4:54 am |
|
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
|
Posted:
Sat Feb 17, 2007 4:33 pm |
|
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? |
|
|
|
 |
plankton

|
Posted:
Sat Feb 17, 2007 8:03 pm |
|
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.  |
|
|
|
 |
fkelly

|
Posted:
Sun Feb 18, 2007 12:14 am |
|
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


Joined: Feb 17, 2007
Posts: 2
Location: Italy
|
Posted:
Sun Feb 18, 2007 5:33 am |
|
if ($result < $myvar) { ... } // he hasn't completed the num of downloads yet
else { ... } // $result is greater-then over equal to $myvar |
|
|
|
 |
plankton

|
Posted:
Fri Feb 23, 2007 11:55 am |
|
Right... I finaly got back to it,
thanks nanocaiordo
I changed 'If ($result == $myvar){...}' to 'If ($result >= $myvar){...}
and that works great.
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
Thanks to all for the help |
|
|
|
 |
|