Невалиден MySQL резултат?

SuCcEsS

Registered
Ето какво ми изписва:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\DemonWorld\class\class_world.php on line 31

Ето кода:
Код:
<?php
require_once ("data_class.php");



class World extends Data {

var $wx = 100; // max world width
var $wy = 100; // max world height

var $qx = 10; // quadrant X
var $qy = 10; // quadrant Y

var $radius = 10; // maybe we'll need this


	function ShowMap() {
		
		if (isset($_POST["q"]) && isset($_POST["Change"]) && $_POST["Change"] == 'Change' && !preg_match("/[^0-9]+/", $_POST["q"]) && $_POST["q"] != '') 
		{
			$q = mysql_real_escape_string($_POST["q"]);
		} 
		
		else {
			$q = 1;
			 }
		
		$sq = mysql_query("SELECT * FROM strongholds WHERE quadrant = $q");
		
		$r = 1;
		while ($r <= mysql_num_rows($sq)) {
			
			$d[$r] = mysql_fetch_assoc($sq); // as $d = data of that row

			$this->s[$d[$r][xcoo]][$d[$r][ycoo]][pid] = $d[$r][player_creatures_id];
			$this->s[$d[$r][xcoo]][$d[$r][ycoo]][name] = $d[$r][name];
			
			
			$r++;
		}
		//start of table layout and quadrant selection
		echo "<table width='410' cellpading='0' celspacing='0' align='center' border='0' style='margin-top:20px;'>
		<tr><td colspan='10'>
		<form action='?p=world' method='POST'>
		Регион: <input type='text' value='$q' style='width:30px' maxlength='2' name='q' /><input type='submit' value='Смени' name='Change' />
		</form>
		</td></tr>
		<tr>";
		
		$i = 1;
		$xi = 1;
		$yi = 1;
		while ($i <= 100) {
			
			//echo $this->s[$xi][$yi][pid];
			
		if ($this->s[$xi][$yi][pid] == $_SESSION["id"]) {

		echo "<td width='36' height='36' align='center' bgcolor='#339933' title='".$this->s[$xi][$yi][name]."'><img src='img/castle.gif' border='0'/></td>";	
			
		}

		if ($this->s[$xi][$yi][pid] != $_SESSION["id"] && $this->s[$xi][$yi][pid] != '') {

		echo "<td width='36' height='36' align='center' bgcolor='#339933' title='".$this->s[$xi][$yi][name]."'><img src='img/castle2.gif' border='0'/></td>";	
			
		}

		else if ($this->s[$xi][$yi][pid] == ''){
			
		echo "<td width='36' height='36' align='center' bgcolor='#339933' title='[ x:$xi, y:$yi ]'><font color='#000000'></font></td>";
		}
		
		
		if ($i % 10 == 0) {echo "</tr><tr>"; $yi = $yi + 1; $xi = $xi - 10;}
		
		$i++;
		$xi++;
		}
		// end of table layout
		echo "</tr></table>";
		
	}
	
	
	
	
}
?>
 
я пробвай така :

Код:
<?php
require_once ("data_class.php");



class World extends Data {

var $wx = 100; // max world width
var $wy = 100; // max world height

var $qx = 10; // quadrant X
var $qy = 10; // quadrant Y

var $radius = 10; // maybe we'll need this


   function ShowMap() {
      
      if (isset($_POST["q"]) && isset($_POST["Change"]) && $_POST["Change"] == 'Change' && !preg_match("/[^0-9]+/", $_POST["q"]) && $_POST["q"] != '')
      {
         $q = mysql_real_escape_string($_POST["q"]);
      }
      
      else {
         $q = 1;
          }
      
      $sq = mysql_query("SELECT * FROM strongholds WHERE quadrant = $q");
      
      $r = 1;
      while ($r = mysql_num_rows($sq)) {
         
         $d[$r] = mysql_fetch_assoc($sq); // as $d = data of that row

         $this->s[$d[$r][xcoo]][$d[$r][ycoo]][pid] = $d[$r][player_creatures_id];
         $this->s[$d[$r][xcoo]][$d[$r][ycoo]][name] = $d[$r][name];
         
         
         $r++;
      }
      //start of table layout and quadrant selection
      echo "<table width='410' cellpading='0' celspacing='0' align='center' border='0' style='margin-top:20px;'>
      <tr><td colspan='10'>
      <form action='?p=world' method='POST'>
      Регион: <input type='text' value='$q' style='width:30px' maxlength='2' name='q' /><input type='submit' value='Смени' name='Change' />
      </form>
      </td></tr>
      <tr>";
      
      $i = 1;
      $xi = 1;
      $yi = 1;
      while ($i <= 100) {
         
         //echo $this->s[$xi][$yi][pid];
         
      if ($this->s[$xi][$yi][pid] == $_SESSION["id"]) {

      echo "<td width='36' height='36' align='center' bgcolor='#339933' title='".$this->s[$xi][$yi][name]."'><img src='img/castle.gif' border='0'/></td>";   
         
      }

      if ($this->s[$xi][$yi][pid] != $_SESSION["id"] && $this->s[$xi][$yi][pid] != '') {

      echo "<td width='36' height='36' align='center' bgcolor='#339933' title='".$this->s[$xi][$yi][name]."'><img src='img/castle2.gif' border='0'/></td>";   
         
      }

      else if ($this->s[$xi][$yi][pid] == ''){
         
      echo "<td width='36' height='36' align='center' bgcolor='#339933' title='[ x:$xi, y:$yi ]'><font color='#000000'></font></td>";
      }
      
      
      if ($i % 10 == 0) {echo "</tr><tr>"; $yi = $yi + 1; $xi = $xi - 10;}
      
      $i++;
      $xi++;
      }
      // end of table layout
      echo "</tr></table>";
      
   }
   
   
   
   
}
?>
 
И така не стана
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\DemonWorld\class\class_world.php on line 31
 
<?php
require_once ("data_class.php");



class World extends Data {

var $wx = 100; // max world width
var $wy = 100; // max world height

var $qx = 10; // quadrant X
var $qy = 10; // quadrant Y

var $radius = 10; // maybe we'll need this


function ShowMap() {

if (isset($_POST["q"]) && isset($_POST["Change"]) && $_POST["Change"] == 'Change' && !preg_match("/[^0-9]+/", $_POST["q"]) && $_POST["q"] != '')
{
$q = mysql_real_escape_string($_POST["q"]);
}

else {
$q = 1;
}

$sq = mysql_query("SELECT * FROM strongholds WHERE quadrant = '$q'") or die(mysql_error());

$r = 1;
while ($r <= mysql_num_rows($sq)) {

$d[$r] = mysql_fetch_assoc($sq); // as $d = data of that row

$this->s[$d[$r][xcoo]][$d[$r][ycoo]][pid] = $d[$r][player_creatures_id];
$this->s[$d[$r][xcoo]][$d[$r][ycoo]][name] = $d[$r][name];


$r++;
}
//start of table layout and quadrant selection
echo "<table width='410' cellpading='0' celspacing='0' align='center' border='0' style='margin-top:20px;'>
<tr><td colspan='10'>
<form action='?p=world' method='POST'>
Регион: <input type='text' value='$q' style='width:30px' maxlength='2' name='q' /><input type='submit' value='Смени' name='Change' />
</form>
</td></tr>
<tr>";

$i = 1;
$xi = 1;
$yi = 1;
while ($i <= 100) {

//echo $this->s[$xi][$yi][pid];

if ($this->s[$xi][$yi][pid] == $_SESSION["id"]) {

echo "<td width='36' height='36' align='center' bgcolor='#339933' title='".$this->s[$xi][$yi][name]."'><img src='img/castle.gif' border='0'/></td>";

}

if ($this->s[$xi][$yi][pid] != $_SESSION["id"] && $this->s[$xi][$yi][pid] != '') {

echo "<td width='36' height='36' align='center' bgcolor='#339933' title='".$this->s[$xi][$yi][name]."'><img src='img/castle2.gif' border='0'/></td>";

}

else if ($this->s[$xi][$yi][pid] == ''){

echo "<td width='36' height='36' align='center' bgcolor='#339933' title='[ x:$xi, y:$yi ]'><font color='#000000'></font></td>";
}


if ($i % 10 == 0) {echo "</tr><tr>"; $yi = $yi + 1; $xi = $xi - 10;}

$i++;
$xi++;
}
// end of table layout
echo "</tr></table>";

}




}
?>
Така дава ли ти нещо?
 
Table 'demonworld.strongholds' doesn't exist

а до преди това си ми изкарваше картата някаква идея как ще създам тази таблица strongholds???
 
SuCcEsS каза:
Table 'demonworld.strongholds' doesn't exist

а до преди това си ми изкарваше картата някаква идея как ще създам тази таблица strongholds???
Е как ше извличаш данни от несъществуваща таблица??
Да не бъркаш нещо?
 
Да не ти липсва конекцията към самата база данни ,пробвай най-отгоре да се конектнеш и кажи резултата
mysql_connect();
mysql_select_db();
 
Не не забелязах, че таблицата липсва някои ако може да направи SQL код по кода който съм дал ще съм му много благодарен!
 

Горе