I'm having trouble with a script for my site. I'm trying to pull a user's dragons from their scroll on the dragcave.net website. But I want to specifically display either just the eggs or just the hatchlings. Let me know if I need to provide more info. Here is my script: <?php $scrollname = $_POST['scrollname']; if (isset($_POST['submit'])) { } $string = file_get_contents('http://dragcave.net/user/' . $scrollname); // Path builders for the regular expression and the HTML that follows $path = '/image/'; $ext = '.gif'; $pattern = "#$path(.*?)$ext(.*?)#"; preg_match_all($pattern, $string, $matches); $list = $matches[1]; $limit = count($list); for ($i = 0; $i < $limit; $i++) { echo "<img src=\"http://dragcave.net/image/$list[$i].gif\"><br />"; echo 'Code: ' . $list[$i] . '<br>'; } ?> Code (markup): here is my scroll if you need to check the source code of the page -http://dragcave.net/user/dragonsmistress Please Please help me ): I've been trying to figure this out for months now!!
did you mean like this <?php $scrollname = $_POST['scrollname']; if (isset($_POST['submit'])) { $string = file_get_contents('http://dragcave.net/user/' . $scrollname); // Path builders for the regular expression and the HTML that follows $path = '/image/'; $ext = '.gif'; $pattern = "#$path(.*?)$ext(.*?)#"; preg_match_all($pattern, $string, $matches); $list = $matches[1]; $limit = count($list); for ($i = 0; $i < $limit; $i++) { echo "<img src=\"http://dragcave.net/image/$list[$i].gif\"><br />"; echo 'Code: ' . $list[$i] . '<br>'; } } ?> PHP:
Simple fix for ya. All you have to do is add another thing to your $pattern string. Try this $pattern = "#$path(.*?)$ext(.*?)(Egg|Hatchling|Adult)#"; Then, the string "Egg" or "Hatchling" or "Adult" will be inside the 3rd key of your $matches array ($matches[3]) so you could do like <?php $scrollname = $_POST['scrollname']; if (isset($_POST['submit'])) { } $string = file_get_contents('http://dragcave.net/user/' . $scrollname); // Path builders for the regular expression and the HTML that follows $path = '/image/'; $ext = '.gif'; $pattern = "#$path(.*?)$ext(.*?)(Egg|Hatchling|Adult)#"; preg_match_all($pattern, $string, $matches); $list = $matches[1]; $type = $matches[3]; $limit = count($list); for ($i = 0; $i < $limit; $i++) { echo "<img src=\"http://dragcave.net/image/$list[$i].gif\"><br />"; echo 'Code: ' . $list[$i] . '<br>'; echo 'Type: ' . $type[$i] . '<br>'; //This is the new line I added showing how to handle the type } ?> PHP: EDIT: @misbah: Nah, their script already appears to run fine (though I didn't do it through a post submission so I don't know if that's messing them up at all) but what they wanted was to be able to see the Type of the thing (Egg or Hatchling) then later on only show them based on that Type.
It still seems to be pulling up all the dragons... ):I removed the Adult part and it is still pulling all the dragons up.
No no no. I didn't put in any checks for only showing whatever. I figured you'd know to do that much lol. What you'd have to do is put an IF in your for loop like if($type[$i] == "Hatchling") { //print it out here } which will only print out the code for Hatchlings. Example. <?php $scrollname = $_POST['scrollname']; if (isset($_POST['submit'])) { } $string = file_get_contents('http://dragcave.net/user/' . $scrollname); // Path builders for the regular expression and the HTML that follows $path = '/image/'; $ext = '.gif'; $pattern = "#$path(.*?)$ext(.*?)(Egg|Hatchling|Adult)#"; preg_match_all($pattern, $string, $matches); $list = $matches[1]; $type = $matches[3]; $limit = count($list); for ($i = 0; $i < $limit; $i++) { if($type[$i] == "Hatchling") { echo "<img src=\"http://dragcave.net/image/$list[$i].gif\"><br />"; echo 'Code: ' . $list[$i] . '<br>'; } } ?> PHP:
WOW!!!! You do not understand how appreciative I am for this *BIG GRIN* That works like a charm!! I didn't know how to do the if statement!! LOL I'm a newbie at php so I wasn't sure!!! Gosh... thank you SO much! I must give you credit on my site!! Thank you Thank You Thank YOU!!!!!
One more thing.... not sure if you can help me with this part and if not I don't even care (I'm so happy) But... the users can "freeze" their hatchlings making them no longer need to be posted on the site. Would you know how to keep from showing the frozen hatchlings? Like I said... if not no biggie at all!! *still grinning*
You'd have to freeze one of your eggs for me so I can see how it's displayed on your profile page. I'd need an example.
I have several frozen hatchlings (you can't freeze eggs) here is the url for a frozen hatchling: http://dragcave.net/viewdragon/n/Mistress%27s%20Mortuus
Nope, sorry. There doesn't seem to be any indication in the profile view's HTML that says whether or not it's frozen. The most you can do is have it open the viewdragon page for every hatchling and look for the text that describes it as frozen but you really don't want to do that because that's a lot of external file opening and can really slow your script down.
I was wondering if you, zerxer, or anyone can help with my next phase Is it possible to allow users to update their data in the database without having to re add ALL the codes. Like say: A user has x amount of dragons and submits those into the db Then.... the next day gets another egg/hatchling and wants to add that to the site. Is it possible for them to add this egg/hatchling without re adding the dragons from the day before? Thanks This is the best forum I've found yet!!