Gniew Posted July 5, 2011 Share Posted July 5, 2011 Okay, so the problem is simple. The database has one row where X = 1 and Y = 0. I want the code to print out the ImageFail if the row (0,0) doesn't exist, then continue on and print the number.jpg if the row (1,0) exists, and to continue in that fashion when more rows are added. URL = index.php?x=0&y=0 Then...I have a problem. How do I get ".$result2->Number." to work if say there was a (0,0) since that table cell contains the variable $result, and not $result2. Thanks <? $conn = mysql_connect("localhost","XXX","XXX"); $db = mysql_select_db("XXX"); class Map { function ImageWork() { echo("<a style='cursor:pointer' id='opener2'><img src=\"Pictures/".$result2->Number.".jpg\"/>");} function ImageFail() { echo("<a style='cursor:pointer' id='opener2'><img src='Pictures/base/3.jpg'/>");} } ?> <table width="75%" border="0"> <tr> <td><? @$worked = mysql_query("SELECT * FROM `map` WHERE `x`=('".$_GET['x']."' + 0) AND `y`=('".$_GET['y']."' + 0)"); @$result = mysql_fetch_object($worked); if($result->x != ""){Map::ImageFail();} else {Map::ImageWork();}?></td> <td><? @$worked2 = mysql_query("SELECT * FROM `map` WHERE `x`=('".$_GET['x']."' + 1) AND `y`=('".$_GET['y']."' + 0)"); @$result2 = mysql_fetch_object($worked2); if($result2->x != ""){Map::ImageFail();} else {Map::ImageWork();}?></td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/241152-issue/ Share on other sites More sharing options...
btherl Posted July 5, 2011 Share Posted July 5, 2011 You should be passing $result as an argument to ImageWork() and ImageFail(). Or you can pass $result->Number if you prefer. Quote Link to comment https://forums.phpfreaks.com/topic/241152-issue/#findComment-1238721 Share on other sites More sharing options...
Gniew Posted July 5, 2011 Author Share Posted July 5, 2011 Okay, now sorry to maybe be an idiot, but how do I pass it as an argument? Quote Link to comment https://forums.phpfreaks.com/topic/241152-issue/#findComment-1238726 Share on other sites More sharing options...
btherl Posted July 5, 2011 Share Posted July 5, 2011 <?php $conn = mysql_connect("localhost","XXX","XXX"); $db = mysql_select_db("XXX"); class Map { function ImageWork($ImageNumber) { echo("<a style='cursor:pointer' id='opener2'><img src=\"Pictures/$ImageNumber.jpg\"/>");} function ImageFail() { echo("<a style='cursor:pointer' id='opener2'><img src='Pictures/base/3.jpg'/>");} } ?> <table width="75%" border="0"> <tr> <td><?php @$worked = mysql_query("SELECT * FROM `map` WHERE `x`=('".$_GET['x']."' + 0) AND `y`=('".$_GET['y']."' + 0)"); @$result = mysql_fetch_object($worked); if($result->x != ""){Map::ImageFail();} else {Map::ImageWork($result->Number);}?></td> <td><?php @$worked2 = mysql_query("SELECT * FROM `map` WHERE `x`=('".$_GET['x']."' + 1) AND `y`=('".$_GET['y']."' + 0)"); @$result2 = mysql_fetch_object($worked2); if($result2->x != ""){Map::ImageFail();} else {Map::ImageWork($result2->Number);}?></td> </tr> </table> So what's happening is that Map::ImageWork() now takes a number as an argument, and it substitutes that number into the HTML. You can then choose which number to give it when you call it. Quote Link to comment https://forums.phpfreaks.com/topic/241152-issue/#findComment-1238738 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.