Please help... I may pull out my hair....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
dragonsmistress
Forum Commoner
Posts: 44
Joined: Thu Dec 18, 2008 2:03 pm

Please help... I may pull out my hair....

Post by dragonsmistress »

I have been trying to get this to work for months ): If someone could please show me how to get the images for each user I would LOVE you forever. This is what I'm working with... it may be all wrong but I tried :oops:

By filling out your Dragon Cave username below, you can add your eggs and hatchlings to the hatchery, the daycare, and the emergency room all at once.
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
<div style='margin: 0px auto; text-align: center;'> Username: <input name="username"/> <input type="submit" value="Add"/></div>
</form>
<?
if(!isset($_POST['username']) && isset($_GET['username']) && !empty($_GET['username'])) $_POST['username'] = $_GET['username'];
$data = unserialize(file_get_contents("http://dragcave.net/api/serialize/user/ ... sername'])));
foreach($data['errors'] as $error) {
if($error[0] == 5) {echo "Sorry, we were unable to find an account with that username."; return;}
elseif($error[0] == 6) {echo "Sorry, your account has no dragons."; return;}
}
$eggs ="<td><img src=\"http://dragcave.net/image/(.*).gif\" alt=\'x\'></td><td></td><td>Egg</td>";
foreach($eggs['dragons'] as $ids) {

$ids = array(1=>array(),2=>array(),3=>array());
}
echo "<tr><td><img src='http://dragcave.net/image/".implode("/1.gif'/><img src='http://dragcave.net/image/",$ids[1])."/1.gif'/></td></tr>";

echo "<tr><td><img src='http://dragcave.net/image/".implode("/1.gif'/><img src='http://dragcave.net/image/",$ids[2])."/1.gif'/></td></tr>";

echo "<tr><td><img src='http://dragcave.net/image/".implode("/1.gif'/><img src='http://dragcave.net/image/",$ids[3])."/1.gif'/></td></tr>";

?>
ryanday
Forum Newbie
Posts: 4
Joined: Wed Dec 17, 2008 9:34 pm

Re: Please help... I may pull out my hair....

Post by ryanday »

ooo, forever? Is this a cut/paste or did you re-type it in?

Look at the following:

action="<?=$_SERVER['PHP_SELF'];?>"
should read action="<? echo $_SERVER['PHP_SELF'];?>"

Code: Select all

foreach($eggs['dragons'] as $ids) {
$ids = array(1=>array(),2=>array(),3=>array());
}
echo "<tr><td><img src='http://dragcave.net/image/".implode("/1.gif'/><img src='http://dragcave.net/image/",$ids[1])."/1.gif'/></td></tr>";
 
The $ids array will always be empty, so the later reference to $ids[1] will always be null.
Could you give a little more info about the problem you are having as well?
User avatar
dragonsmistress
Forum Commoner
Posts: 44
Joined: Thu Dec 18, 2008 2:03 pm

Re: Please help... I may pull out my hair....

Post by dragonsmistress »

I just can't seem to figure out how to get the info back from the site that I want ): I'm pretty sure it's all wrong... so basically I just keep trying to change things... in turn messing it up even more!! Yes (: Forever!! lol
User avatar
dragonsmistress
Forum Commoner
Posts: 44
Joined: Thu Dec 18, 2008 2:03 pm

Re: Please help... I may pull out my hair....

Post by dragonsmistress »

what i'm trying to do is this......
I run a website kinda like a click exchange. People go to dragcave.net, get some dragons, and then they have to post them somewhere to get clicks for them ie: my site. So what I want is for them to be able to enter their username and then have the dragons on their scroll listed on the page for them to choose which they would like to display on the page. Does that help at all?
ryanday
Forum Newbie
Posts: 4
Joined: Wed Dec 17, 2008 9:34 pm

Re: Please help... I may pull out my hair....

Post by ryanday »

You will probably want to go back to the original designer of the site. There are a few things that in this small snippet that are trying to do things they aren't able to do.

Code: Select all

$eggs ="<td><img src=\"http://dragcave.net/image/(.*).gif\" alt=\'x\'></td><td></td><td>Egg</td>";
foreach($eggs['dragons'] as $ids) {
It almost looks as if you want a regular expression to match every file in that directory with a .GIF extension, and store that in the $eggs array.

Code: Select all

foreach($eggs['dragons'] as $ids) {
$ids = array(1=>array(),2=>array(),3=>array());
}
echo "<tr><td><img src='http://dragcave.net/image/".implode("/1.gif'/><img src='http://dragcave.net/image/",$ids[1])."/1.gif'/></td></tr>";
I'm guessing each of those GIF files is the dragon picture, but you can't access it like this. Also this doesn't really look like the way you would want to solve the problem I think you are having here. Can you email the original designer?
User avatar
dragonsmistress
Forum Commoner
Posts: 44
Joined: Thu Dec 18, 2008 2:03 pm

Re: Please help... I may pull out my hair....

Post by dragonsmistress »

I tried to but apparently he's busy... he sent me this script but it auto adds all the dragons. I want the users to be able to choose.... here is what he has


By filling out your Dragon Cave username below, you can add your eggs and hatchlings to the hatchery, the daycare, and the emergency room all at once.
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
<div style='margin: 0px auto; text-align: center;'> Username: <input name="username"/> <input type="submit" value="Add"/></div>
</form>
<?
} else {
if(!isset($_POST['username']) && isset($_GET['username']) && !empty($_GET['username'])) $_POST['username'] = $_GET['username'];
$q = $db->prepare("REPLACE INTO `hatchery` (`id`,`owner`,`stage`,`emergency`,`lastupdate`) VALUES(:id,:owner,:stage,:emergency,UNIX_TIMESTAMP())");

$data = unserialize(file_get_contents("http://dragcave.net/api/serialize/user/ ... sername'])));
foreach($data['errors'] as $error) {
if($error[0] == 5) {echo "Sorry, we were unable to find an account with that username."; return;}
elseif($error[0] == 6) {echo "Sorry, your account has no dragons."; return;}
}
$added = array(1=>0,2=>0,'e'=>0);
$ids = array(1=>array(),2=>array(),'e'=>array());
foreach($data['dragons'] as $d) {
if($d['daysleft'] >= 0) {
$data = array(
'id' => $d['id'],
'owner' => $d['owner'],
'stage' => ($d['hatch']=='0'?1:2),
'emergency' => ($d['daysleft'] <= 3.0?1:0)
);
$q->execute($data);
if($q->rowCount() > 0) {
$added[$data['stage']]++;
$ids[$data['stage']][] = $d['id'];
if($data['emergency']) {
$added['e']++;
$ids['e'][] = $d['id'];
}
}
}
}
echo "Added {$added[1]} egg".($added[1]!=1?'s':'')." and {$added[2]} hatchling".($added[2]!=1?'s':'')." ({$added['e']} emergenc".($added[2]!=1?'ies':'y').")<br/>";
if(array_sum($added)) {
echo "<table>";
if($added[1]) {
echo "<tr><th>Egg".($added[1]!=1?'s':'')."</th></tr>";
echo "<tr><td><img src='http://dragcave.net/image/".implode("/1.gif'/><img src='http://dragcave.net/image/",$ids[1])."/1.gif'/></td></tr>";
}
if($added[2]) {
echo "<tr><th>Hatchling".($added[2]!=1?'s':'')."</th></tr>";
echo "<tr><td><img src='http://dragcave.net/image/".implode("/1.gif'/><img src='http://dragcave.net/image/",$ids[2])."/1.gif'/></td></tr>";
}
if($added['e']) {
echo "<tr><th>Emergenc".($added['e']!=1?'ies':'y')."</th></tr>";
echo "<tr><td><img src='http://dragcave.net/image/".implode("/1.gif'/><img src='http://dragcave.net/image/",$ids['e'])."/1.gif'/></td></tr>";
}
echo "</table>";
}
}
?>
User avatar
dragonsmistress
Forum Commoner
Posts: 44
Joined: Thu Dec 18, 2008 2:03 pm

Re: Please help... I may pull out my hair....

Post by dragonsmistress »

:banghead: I know it can be done... another person has the same sort of site up and she came up with her own script. of course she's not in the sharing mood.
User avatar
dragonsmistress
Forum Commoner
Posts: 44
Joined: Thu Dec 18, 2008 2:03 pm

Re: Please help... I may pull out my hair....

Post by dragonsmistress »

lol.... here is what she had been trying to help me with. then she told me to join a forum and ask (:

<?
$scroll = $_POST[scrollname];
if (isset($_POST['submit'])) {
$url = "http://dragcave.net/$scroll";
$input = file_get_contents($url) or die('Could not access scroll: $url');
$eggs ="<td><img src=\"http://dragcave.net/image/(.*).gif\" alt=\'x\'></td><td></td><td>Egg</td>";
if(preg_match_all("$eggs", $input, $matches, PREG_SET_ORDER)) {
foreach($matches as $egg) {
echo "$egg[1]";
echo "$egg[2]";
echo "$egg[3]";
echo "$egg[4]";
echo "$egg[5]";
}
}
}
?>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Please help... I may pull out my hair....

Post by RobertGonzalez »

Can we start using PHP tags please. Reading that code as plain old posting style text is really difficult.

Onto the subject at hand, could you explain what you are trying to do in plain English so we can see if there is a design element that we can offer to help you with? Please don't post any code in response to this question. Just post the steps you want you code to take.
ryanday
Forum Newbie
Posts: 4
Joined: Wed Dec 17, 2008 9:34 pm

Re: Please help... I may pull out my hair....

Post by ryanday »

Since there is an external file that being read from it would be pretty hard to figure out over the board. You're best bet is probably to wait for the designer. Sorry though!
User avatar
dragonsmistress
Forum Commoner
Posts: 44
Joined: Thu Dec 18, 2008 2:03 pm

Re: Please help... I may pull out my hair....

Post by dragonsmistress »

oh ok sorry :oops:

I'd like for the user to enter their scrollname.
Then I would like their scrolls to be pulled up but only have eggs and hatchlings from the site listed for them to check off which they want added. Then once those are checked have them added to the database and displayed on my site.

Let me know if you need more info.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Please help... I may pull out my hair....

Post by RobertGonzalez »

dragonsmistress wrote:I'd like for the user to enter their scrollname.
So we know we are talking about taking form input. Or is this going to be a session value established behind a log in? Or perhaps some other input like a query string?
dragonsmistress wrote:Then I would like their scrolls to be pulled up but only have eggs and hatchlings from the site listed for them to check off which they want added.
So now we are talking about a database call? Or perhaps a filesystem search? Where is the scroll data kept? How are eggs and hatchlings related to the scrolls and the sites listed for the user?
dragonsmistress wrote:Then once those are checked have them added to the database and displayed on my site.
This is just a matter of capturing the posted checkboxes, looping an array perhaps (if it is set up right it should be looping an array :) ) and building the necessary query to update the database.

Based on my responses can you point me in the direction further of how this process will work?
User avatar
dragonsmistress
Forum Commoner
Posts: 44
Joined: Thu Dec 18, 2008 2:03 pm

Re: Please help... I may pull out my hair....

Post by dragonsmistress »

When the user enters their scrollname I want to get the file contents from an external site (dragcave.net). The eggs and hatchlings are listed on the users scroll. I can get the rest of it I just can't figure out how to get the dragon images to pull up. This probably isn't great explanation but I'm not a php pro (: I doknow my basics though... I think (:
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Please help... I may pull out my hair....

Post by RobertGonzalez »

Does the external site offer an API or are you just trying to scrape information from the site? How are you going about getting the scroll from that external site?
User avatar
dragonsmistress
Forum Commoner
Posts: 44
Joined: Thu Dec 18, 2008 2:03 pm

Re: Please help... I may pull out my hair....

Post by dragonsmistress »

not sure what API is but I'm trying to use the f-g-c to get the scroll info. That's how I was told to get it.
Post Reply