Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
opblaaskrokodil
Oct 26, 2004

Your morals are my morals. Your wishes are my code.
Well, I have no idea what VPet is like.

LastCaress posted:

I want it to only return 20 results and the others would have a "next page" "previous page" link. This is my code (and don't laugh at me I have no idea what I'm doing!)

php:
<?
$getEnemies = mysql_query("SELECT * FROM user_pets2 WHERE 1 > '0' AND game = '$game' 
ORDER BY two_p_wins DESC, two_p_loses ASC");
?>
Why are you using a condition of 1 > '0' here?
For what it's worth, you could combine your select in the loop with the original query by joining the members2 table on user_pets2.owner = members2.id.

You can achieve a limited range of return results with LIMIT $a, $b at the end of the statement
where $a is the lower limit, and $b is how many you want.
So taking your original query of
code:
SELECT * FROM user_pets2 WHERE 1 > '0' AND game = '$game' 
ORDER BY two_p_wins DESC, two_p_loses ASC
You could add in a LIMIT clause to get some portion of them (just modifying original query)

code:
SELECT * FROM user_pets2 WHERE 1 > '0' AND game = '$game' 
ORDER BY two_p_wins DESC, two_p_loses ASC LIMIT 20, 20
would retrieve the second page of results (assuming 20 per page).



-----------------------------------------------


I just started working with CakePHP (and the whole MVC thing), and I was wondering how to access a model from within a component.

MVC Class Access Within Components talks about how to get access to the controller, but if I'm using the component from some other controller it also doesn't necessarily have access to the model I want. Am I going about this in the wrong way, or is there some way to solve this?
(apart from the hackish / bad
php:
<?
include_once("../../cake/libs/model/model.php");
include_once("../app_model.php");
include_once("../models/modelIWant.php");
?>
sort of thing)

opblaaskrokodil fucked around with this message at 08:04 on Apr 20, 2008

Adbot
ADBOT LOVES YOU

opblaaskrokodil
Oct 26, 2004

Your morals are my morals. Your wishes are my code.
Sorry, double posted it.

opblaaskrokodil
Oct 26, 2004

Your morals are my morals. Your wishes are my code.

LastCaress posted:

Well the 1<0 condition was probably when I just started and was removing other code so I guess that was left behind... The limit thing worked, thanks!

EDIT : Damnit, now I realized a part of the code doesn't work with PHP5, I'm going to have to convert it to php5 and have no idea how. I just hope it's not that different :\

Which part doesn't work? PHP5 is generally pretty similar to PHP4 (in that most PHP4 stuff should work fine in PHP5).


(also I got my question answered @ the cakePHP google group, so I guess I don't need an answer for that anymore)

opblaaskrokodil
Oct 26, 2004

Your morals are my morals. Your wishes are my code.

LastCaress posted:

Oh, I did substitute that as well, but I got the error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/virtual/site19/fst/var/www/html/rpg/club_join.pro.php on line 30

Sorry, should've made it clear.

EDIT : Ah, and I've corrected the way it updates member numbers, that was wrong as well.
Just to be clear, is line 30
php:
<?
header(error("club.php?game=$game&clubid=$clubid","Thank you for joining $getclub[name]."));?>
?

There are a couple of ways to fix it. You can either use string concatenation, so you would have
php:
<?
header(error("club.php?game=$game&clubid=$clubid","Thank you for joining " . $getclub['name'] . "."));?>
as your string. ( a dot between two strings concatenates them). Alternatively, you can wrap the variable in { }.
php:
<?
header(error("club.php?game=$game&clubid=$clubid","Thank you for joining {$getclub['name']}."));?>
Edit: Why is that an error call within a header call anyway? I'm not familiar with VPet, but it seems like a weird thing to be doing

opblaaskrokodil fucked around with this message at 20:06 on Apr 21, 2008

opblaaskrokodil
Oct 26, 2004

Your morals are my morals. Your wishes are my code.

LOL AND OATES posted:

It probably returns a Location: header.

I guess it could be urlencoding the second param of error and appending that to the redirect URL or something then printing it out @ that page. Otherwise I don't know what the second param is for, since you can't print it out on the current page without loving up sending headers?

opblaaskrokodil
Oct 26, 2004

Your morals are my morals. Your wishes are my code.

Zorilla posted:

As far as I know, PHP won't send the HTTP header until it reaches the first HTML templated area or echo statement (or printf or whatever), so he's fine as long as it's not being set after one of these conditions gets met. Still, there's no need to set the header more than once, so the code should probably use elseif statements instead to make sure no more than one of these conditions gets evaluated as true at the same time:

php:
<?
if ($getclub['private'] == 1) {
    die(header(error("club.php?game=$game&clubid=$clubid","You can't join a private club.")));
} elseif ($clubrank > 0) {
    die(header(error("club.php?game=$game&clubid=$clubid","You are already a member of this club.")));
} elseif ($getmemberdata4['id']) {
    die(header(error("club.php?game=$game&clubid=$clubid","You are already a member of a club.")));
}
?>

That seems kind of unnecessary to me, since die will stop the execution if any of them evaluate as true anyway (maybe a bit clearer from the point of reading, I guess).
What I was wondering about was where it was going to display to the user, for example, 'You are already a member of this club'.

---

Jimix posted:

So we have a trouble ticket system at my work that is written in PHP, and they want me to add some fields to the form. They want something like:

php:
<? echo "is this a new instance? <INPUT TYPE=CHECKBOX NAME=instance>"; //HOW THE gently caress DO YOU DO THIS PART if (instance == checked) { echo "more input fields"; ... } echo "<input type=submit name=submit>"; ?>



for the life of me I cannot figure out how to have the code dynamically check and see if that first checkbox is clicked and then shoot out some more HTML if so, or hide the new fields if the checkbox becomes unclicked. or maybe even if(checkbox), display one set of fields, else display another set.
If I understand you correctly, you want it to display the fields if someone checks the checkbox, without going to a different page / submitting the form? If so, you want something more like Javascript to do this. PHP processes the page server-side, and then sends the output to the browser. If you want to check the value of a checkbox via PHP, then you need to have the user submit the form (whereupon it will not be set if unchecked, or set to 'on' if it's checked), but unless you have them submit the page, PHP alone is not going to achieve what you want.

Something like this
Nevermind, the one below is a lot cleaner looking.

opblaaskrokodil fucked around with this message at 20:53 on Apr 21, 2008

Adbot
ADBOT LOVES YOU

opblaaskrokodil
Oct 26, 2004

Your morals are my morals. Your wishes are my code.

LastCaress posted:

EDIT 2:

I tried putting the $getclub = mysql_query("SELECT * FROM clubs2 WHERE id = '$clubid' AND game = '$game'"); inside the club_join.pro.php but didn't work. So instead of mysql_query i put "fetch" . Don't ask my why, I had seen it in other parts of the code. It worked! So I put it in the club_inc and it didn't work. I don't get this at all :|

Oh, you are misinterpreting a bit what mysql_query returns. It returns a mysql resource object, which is not an associative array like you're using (or it returns false if there's an error in your query). To do what you wanted with using mysql_query, you'd have to do
php:
<?
$resource = mysql_query("SELECT * FROM clubs2 WHERE id = '$clubid' AND game = '$game'"); 
$getclub = mysql_fetch_array($resource);
?>
It looks like fetch (which isn't a standard PHP function to my knowledge) is basically doing the above (returning the first row of the result of calling your query).

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply