Jump to content

Issue


Gniew

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/241152-issue/
Share on other sites

<?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.

Link to comment
https://forums.phpfreaks.com/topic/241152-issue/#findComment-1238738
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.