mcfmullen Posted February 18, 2010 Share Posted February 18, 2010 This may seem very basic to you, but I'm having a hard time figuring out how to do this since I don't even know what the proper term for it is: Background info: Animals Table - animalid, name, photo, achievementname, price, resale, levelid, description Achievement Table - achievementid, achievementname, photo, xprequired, rewardname, description Levels Table - levelsid, name, xprequired, description Rewards Table - rewardid, rewardname, desciption What I want to do is have my animals.php page pull up the MySQL Animals Table (already done) and have all the animal's achievementsid values link to a new page detailing that specific achievement (achievement.php). In turn, that achievement page would show the rewardid value that would link to a page detailing that specific reward (reward.php) Example: Animals.php shows a table with: 1-Horse--horse.png-Yee Haw!-1,000$-250$-1-A horse is a horse of course! I want Yee Haw! to display as a link that would open up a php page that would show information relating to that specific achievement, ignoring all other achievements. This would work in the same vein as this website: http://farmville.aweblog.net/almanac/animals/all-animals I assume in being correct that I would have to call the result of that value into a variable that would be passed on as a cookie to another php file but I have not idea where or how to start on that. My loop looks like this (shortened due to repetition): while($row = mysql_fetch_array($result)){ echo "<tr>"; echo "<td>" .$row['idAnimal']. "</td>"; echo "<td><img src='".$url.$row['photoAnimal']."' height='50px' width='50px'></td>"; echo "<td>" .$row['nameAnimal']. "</td>"; echo "<td>" .$row['nameCategory']. "</td>"; echo "</tr>"; } Assuming I wanted each animal name to link to a detailed animal page, what would I do? Can anyone give me some pointers or point me to a good resource for this kind of information? Googling is pointless as I don't know what terms I should be using... Thanks! Link to comment https://forums.phpfreaks.com/topic/192462-turning-data-into-urls/ Share on other sites More sharing options...
trq Posted February 18, 2010 Share Posted February 18, 2010 take a look at this example I wrote some time ago. Its the same concept. Link to comment https://forums.phpfreaks.com/topic/192462-turning-data-into-urls/#findComment-1014109 Share on other sites More sharing options...
mcfmullen Posted February 18, 2010 Author Share Posted February 18, 2010 Amazing! Thanks! Link to comment https://forums.phpfreaks.com/topic/192462-turning-data-into-urls/#findComment-1014114 Share on other sites More sharing options...
mcfmullen Posted February 18, 2010 Author Share Posted February 18, 2010 One caveat: my syntax doesn't seem to work, nor does the one in your example: echo "<td><a href='"animalspec.php?animal={.$row['nameAnimal'].}"'>{.$row['nameAnimal'].}</a></td>"; Any pointers? Link to comment https://forums.phpfreaks.com/topic/192462-turning-data-into-urls/#findComment-1014125 Share on other sites More sharing options...
trq Posted February 18, 2010 Share Posted February 18, 2010 echo "<td><a href='animalspec.php?animal={$row['nameAnimal']}'>{$row['nameAnimal']}</a></td>"; Link to comment https://forums.phpfreaks.com/topic/192462-turning-data-into-urls/#findComment-1014148 Share on other sites More sharing options...
mcfmullen Posted February 19, 2010 Author Share Posted February 19, 2010 Many thanks! Link to comment https://forums.phpfreaks.com/topic/192462-turning-data-into-urls/#findComment-1014579 Share on other sites More sharing options...
mcfmullen Posted February 19, 2010 Author Share Posted February 19, 2010 I am still having syntax errors... unexpected ')' on line 16 and then it pulls a fit on unexpected $end and unexpected "}" if I remove the ")"... <?php if (isset($_GET['animal'])) { $con = DATABASE CONNECTION SETTINGS $sql = "SELECT Animals.photoAnimal, Animals.nameAnimal, Animals.nameCategory, Animals.introDateAnimal, Animals.endDateAnimal, Animals.sizeAnimal, Animals.XPplacedAnimal, Animals.timeAnimal, Animals.harvestAnimal, Animals.costAnimal, Animals.sellAnimal, Animals.idLevel, Animals.descriptionAnimal, Animals.commentAnimal, animalMethods.nameMethod, animalThemes.nameTheme FROM (Animals LEFT JOIN animalThemes ON Animals.nameAnimal = animalThemes.nameAnimal) LEFT JOIN animalMethods ON Animals.nameAnimal = animalMethods.nameAnimal WHERE Animals.nameAnimal = '{$_GET['animal']}'"; $result = mysql_query($sql); if ($result) { if (mysql_num_rows($result) > 0) { $row = mysql_fetch_assoc($result)); echo "You've selected {$row['nameAnimal']}."; } else { echo "No animal found by that name"; } else { echo "Query failed ".mysql_error(); } } else { echo "No animal selected"; } ?> Link to comment https://forums.phpfreaks.com/topic/192462-turning-data-into-urls/#findComment-1014629 Share on other sites More sharing options...
trq Posted February 19, 2010 Share Posted February 19, 2010 Your missing a } after.... echo "No animal found by that name"; Link to comment https://forums.phpfreaks.com/topic/192462-turning-data-into-urls/#findComment-1014639 Share on other sites More sharing options...
mcfmullen Posted February 19, 2010 Author Share Posted February 19, 2010 I now get unexpected '{' on line 18: <?php if (isset($_GET['animal'])) { DATABASE STUFF { die('Could not connect: ' . mysql_error()); } MORE DATABASE STUFF $url='http://www.domain.com'; $sql = "SELECT Animals.photoAnimal, Animals.nameAnimal, Animals.nameCategory, Animals.introDateAnimal, Animals.endDateAnimal, Animals.sizeAnimal, Animals.XPplacedAnimal, Animals.timeAnimal, Animals.harvestAnimal, Animals.costAnimal, Animals.sellAnimal, Animals.idLevel, Animals.descriptionAnimal, Animals.commentAnimal, animalMethods.nameMethod, animalThemes.nameTheme FROM (Animals LEFT JOIN animalThemes ON Animals.nameAnimal = animalThemes.nameAnimal) LEFT JOIN animalMethods ON Animals.nameAnimal = animalMethods.nameAnimal WHERE Animals.nameAnimal = '{$_GET['animal']}'"; $result = mysql_query($sql); if ($result) { if (mysql_num_rows($result) > 0) { $row = mysql_fetch_assoc($result); echo "You've selected {$row['nameAnimal']}."; } else { echo "No animal found by that name";} } else { echo "Query failed ".mysql_error(); } } else { echo "No animal selected"; } ?> Link to comment https://forums.phpfreaks.com/topic/192462-turning-data-into-urls/#findComment-1014644 Share on other sites More sharing options...
trq Posted February 19, 2010 Share Posted February 19, 2010 Your still missing the } I showed you in my last post. Syntax errors should really be tracked down and fixed yourself. You are removing pieces of code from your posts making the line numbers mean nothing to us. Do you have a decent text editor with syntax highlighting? If not, get one ( I would recommend netbeans) . These errors will just right out. Link to comment https://forums.phpfreaks.com/topic/192462-turning-data-into-urls/#findComment-1014652 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.