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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.