Page 1 of 1
once a function
Posted: Sun Aug 25, 2002 12:54 am
by cheatboy00
I'm having a problem with a function I created
i'm outputting all the items a character has... and i use a while loop to do it... wel.. heres what it looks like
Code: Select all
echo "<table>";
echo "<tr><td colspan="2">";
echo "TITLE";
echo "</td></tr>";
if ($this != 'that'){
$qry = mysql_query("SELECT * FROM characters WHERE pname != '$pname'"};
while ($sen = mysql_fetch_assoc($qry)){
echo "<tr><td>";
$name = $senї'pname'];
echo "$name";
echo "</td>";
echo "<td>";
$e = $senї'equip'];
$ep = explode(",", $e);
$it = $senї'items'];
$itm = explode(",", $it);
items($ep,$itm);
echo "</td></tr>";
}
} else {
echo "<tr><td colspan="2">";
echo "sorry not allowed to view";
echo "</td></tr>";
}
echo "</table>";
thats what it basicly looks like... the problem is is that it'll print out all the names. but it will only print out the items for the first character... and not the rest... if you need to see the fucntion just ask k.
Few changes
Posted: Sun Aug 25, 2002 1:22 am
by Takuma
What does function "items()" do as it does not exist in PHP. And also $this variable is reserved so you cannot use that variable (It's like $_SESSION etc).
Re: Few changes
Posted: Sun Aug 25, 2002 1:58 am
by hob_goblin
Takuma wrote:And also $this variable is reserved so you cannot use that variable (It's like $_SESSION etc).
echoed foo... so don't give me 'you cannot use that'
also, cheatboy - post the items() function you showed me
Posted: Sun Aug 25, 2002 2:02 am
by Takuma
ok, you can use them but you shouldn't use them.
Posted: Mon Aug 26, 2002 9:26 am
by BDKR
I agree with you Takuma. You would be inviting confusion and slop.
Now check out the below code.
Code: Select all
<?php
class tester
{ var $this; }
$tester = new tester;
$tester->this = foo;
echo $tester->this; echo "\n";
?>
Now the ridiculous thing about this is that it echoes "foo". Now I figured it would be reserved within the context of the object, but obviously it's not. That's crazy! I feel the language should enforce certain practices and this is one of them.
Stupid!
Later on,
BDKR
Posted: Mon Aug 26, 2002 2:42 pm
by Takuma
I think PHP should not allow to use variable "this". It can be confusing.
Posted: Mon Aug 26, 2002 3:10 pm
by cheatboy00
k.. heres the function items()
Code: Select all
function items($equip, $items) {
$x = 0;
while($equipї$x] != ""){
$ei = $equipї$x];
echo "$ei(e), ";
$x++;
}
$i = 0;
while($itemsї$i] != ""){
if ($itemsї$i] == 'Capsule Case') {
echo "Capsule Case ("";
$i++;
$m = $i;
while ($itemsї$i] <= ($m+5)){
$cap = $itemsї$i];
if ($itemsї$i] == ($m+5)) {
echo "$cap"), ";
} else {
echo "$cap, ";
$i++;
}
}
} else {
$it = $itemsї$i];
echo "$it, ";
}
$i++;
}
}
please note that this function is in a totally other file... that gets included before loading the output...
also that first thing was an example and there really isnt a variable called $this in my code. see teh actual code looks like that its just had more tr's and td's, and all that is needed for you helping is those 2 columns
Posted: Mon Aug 26, 2002 6:51 pm
by cheatboy00
I'm bumping thios up cause i really need help on this... and i cant finish my site without it...
Posted: Mon Aug 26, 2002 7:09 pm
by hob_goblin
Code: Select all
function items($equip, $items) {
foreach($items as $ei);
echo $ei."(e), ";
}
for($i = 0; $i < count($items); $i++){
if ($itemsї$i] == 'Capsule Case') {
echo "Capsule Case ("";
$m = $i;
$n = 0;
while($n <= ($m+5)){
$cap = $itemsї$n];
if ($n == ($m+5)) {
echo $cap.""), ";
$n++;
} else {
echo $cap.", ";
$n++;
}
}
} else {
$it = $itemsї$i];
echo $it.", ";
}
}
}
Posted: Mon Aug 26, 2002 8:27 pm
by cheatboy00
nope... that didnt work......
but i did find out what was wrong....
see in this table their are certian stats that your not allowed to view unless you have something ... well what i did is i put
Code: Select all
if ($itm = 'y'){
echo "<td>";
$e = $senї'equiped'];
$ep = explode(", ", $e);
$it = $senї'items'];
$itm = explode(", ", $it);
items($ep,$itm);
echo "</td>";
}
see $itm was set above it. item would be set to 'y' if the character met its conditions... well do you see the problem... since i reset $itm to the value of whatevers in the db... it doest equal 'y' anymore so no more out putting items after the first go around...
well teh answer is obivous change the var.. i did to $it2