Page 1 of 1

um... cant think of a title

Posted: Thu Aug 29, 2002 4:28 pm
by cheatboy00
is there a function or something in php which will allow you to guess at something...

like what i mean is in my items colum in the db looks something like this...

sword, cape, giant ship[b,ht,s], hat, bag[seed1,seed2]

now i exploded that into $iii (dont ask about the name), now i'm looping through the items in $iii with a while statement... and i want to see if they have a ship... but the problem is is that if i just go if ($iii[$x] == 'giant ship[b,ht,s]') it will only get all people that have that specifications.. (the stuff in the square brakets).

but what i want is it to just guess kinda.. like get the closes to giant ship or ship... without the [b,s,ht] stuff .. see all i want to do is check that it exists not that it has any specifications....

if you understnad that GREAT!!! :-) if not :-( damn

Posted: Thu Aug 29, 2002 4:36 pm
by gotDNS
I'm probably WAY off:

If I understand you, you want to only extract content from the DB where the user is logged in (begins to think im MORE WAY OFF)....

Code: Select all

select * from products where user='$user';
:: Sigh ::

I have no clue what ur talking about...

later on, -Brian

Posted: Thu Aug 29, 2002 4:53 pm
by cheatboy00
ya heres my second explaination....

you, the user is logged in...

this is the code...

Code: Select all

$ii = $personї'items'];
$iii = explode(", ", $ii);
$xp = 0;
while ($itemsї$xp] != ""){
   if ($itemsї$xp] == "Space pod") {
      // code, actually nothing right now but soo will be something
   } else if ($itemsї$xp] == "Giant Space Ship") {
      // referr to the comment above
   } else if  ($itemsї$xp] == "Royal Ship"){
      // referr to the comment above
   }
}
this is whats in the var $person['items'].. (note: example)

Code: Select all

id      name    thing     items
1       jack      nothing Giant Space Shipїht,e,d], Space Pod, Royal Shipїb]
as you can see if i explode it, and the separator being ", ", the feild items it would look like this

Code: Select all

$iiiї0] = Giant Space Shipїht,e,d]
$iiiї1] = Space Pod
$iiiї2] = Royal Shipїb ] // had to put the space becasue its bbcode
now i create the while loop becas ei wanted to loop through the $iii array... to find certian items... now all i need to know is if the item exists.. not what are in the [].

so back to my question is there a function or something that allows just to search for Giant Space Ship, and not have to worry about the rest, in the [].

like there are more than one users with Giant Space Ships, and there are different combinations of prefrences (the stuff in the []). so all i want to do is cut that part out, when i'm searchign through the array.

because if i try and do it with just if's, there's going to be a hell of alot of if's in the program. 'Cause there's ton's of different combinations, of prefrences, that one can have.

erg.. i hope someone gets it this time.

Posted: Thu Aug 29, 2002 4:56 pm
by jason
Yup, look at the preg_match() function. That will do a search for you. =)

Posted: Thu Aug 29, 2002 5:06 pm
by cheatboy00
um.. i dont quite get how to use it but here goes....

Code: Select all

//note this is in the while loop(like above)
$l = $itemsї$xp] 
if (preg_match ("Giant Space Ship", "$l")) {
    //do code
}
i just noticed in the php manual it uses real expression i believe tis called.. i duno how to use that yet... but would that above statement still be true?

Posted: Thu Aug 29, 2002 7:13 pm
by hob_goblin
regular expressions, and try

strpos("Giant Space Ship", $1)

first, it's faster

Posted: Thu Aug 29, 2002 7:56 pm
by cheatboy00
so your saying this will work?

Code: Select all

$l = $iiiї$xp];
if (strpos("Giant Space Ship", $l)){
   //do stuff
}

Posted: Thu Aug 29, 2002 8:00 pm
by hob_goblin

Code: Select all

$l = $iiiї$xp]; 
if (strpos("Giant Space Ship", $l) !== FALSE){ 
   //do stuff 
}
should work

Posted: Thu Aug 29, 2002 8:03 pm
by cheatboy00
... wicked thanks..