Jump to content

Resourse ID #35 Error?


anks

Recommended Posts

Folks,

 

I have defined a tables in MYSQL, now trying to fetch the content in PHP using this:

 

 

$query="SELECT site_name FROM mtr_control_panel WHERE site_url='".$this->site->url."'";

    $result=mysql_query($query);

echo $result

 

Output is Resource id #35

 

NOt sure what it means, any help, please?

 

 

Link to comment
https://forums.phpfreaks.com/topic/244437-resourse-id-35-error/
Share on other sites

That is basically a php pointer to your result so php can tell mysql what resource to use.

 

Example:

$query1="SELECT site_name FROM mtr_control_panel WHERE site_url='".$this->site->url."'";
$query2="SELECT site_name FROM mtr_control_panel";
$result1=mysql_query($query1);
$result2=mysql_query($query2);

 

With that you will have two resources to choose from, by passing that resource to one of the mysql functions php/mysql knows what query you want to work with. Now you can work with 1+ queries, it is similar to the file functions if your familiar with any of those.

You're missing the next step, which is actually extracting the result set.  You need to use something like - mysql_fetch_assoc - there are examples in the link.

 

Maq,

As i understood, mysql_fetch_assoc is used to parse fetched Associative Array.

In my Query, i am just extracting the value of a Single Row (Site_name) using a Where filter. So there is no Associative array involved.

Did i get it right?

 

Any correction?

That is basically a php pointer to your result so php can tell mysql what resource to use.

 

Example:

$query1="SELECT site_name FROM mtr_control_panel WHERE site_url='".$this->site->url."'";
$query2="SELECT site_name FROM mtr_control_panel";
$result1=mysql_query($query1);
$result2=mysql_query($query2);

 

With that you will have two resources to choose from, by passing that resource to one of the mysql functions php/mysql knows what query you want to work with. Now you can work with 1+ queries, it is similar to the file functions if your familiar with any of those.

 

Many thanks for reply LittleGuy. Just that i did not quite get on how to use that to solve my problem?

 

Apolozies, i am not quite a techie but a User.

 

I jsut want to echo the vaue of a Column where the Filter Condition is true. What am i doing wrong there?

In my Query, i am just extracting the value of a Single Row (Site_name) using a Where filter. So there is no Associative array involved.

Did i get it right?

No.  mysql_query() returns the Resource ID, that's why you're seeing that as your output.  Like I said, you need to extract the data using something like mysql_fetch_assoc.  If there are multiple columns you're trying to output, try something like:

$query="SELECT site_name FROM mtr_control_panel WHERE site_url='".$this->site->url."'";
$result=mysql_query($query) or die(mysql_error()); //outputs error message if query failed.  take out when done
while($row = mysql_fetch_assoc($result))
{
   echo $row['site_name'];
}

In my Query, i am just extracting the value of a Single Row (Site_name) using a Where filter. So there is no Associative array involved.

Did i get it right?

No.  mysql_query() returns the Resource ID, that's why you're seeing that as your output.  Like I said, you need to extract the data using something like mysql_fetch_assoc.  If there are multiple columns you're trying to output, try something like:

$query="SELECT site_name FROM mtr_control_panel WHERE site_url='".$this->site->url."'";
$result=mysql_query($query) or die(mysql_error()); //outputs error message if query failed.  take out when done
while($row = mysql_fetch_assoc($result))
{
   echo $row['site_name'];
}

 

 

Great, Your solution worked like Charm.

 

Here is how my Code looks now;

 

  
    $result=mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
    $this->site->name = $row['site_name'];
    $this->header->title = $row['site_title'];
    $this->header->description = $row['site_desc'];
    $this->header->keywords  = $row['site_kws'];
    $sticky_kw = $row['sticky_kw'];
    $ebaycatf = $row['amazon_cat'];
    $amazonasso = $row['amazon_asso_uk'];
    

}

 

THANK YOU!

 

NOw, what i want is to pass the value of $sticky_kw in a Function Sticky().

 

But its now working. Here is my Code:

 


Note: constraint is we can not pass the Value as a Parameter like   function sticky($sticky_kw) so what i a m doing is:

  function sticky()
    {

    $result=mysql_query($query);
    while($row = mysql_fetch_assoc($result))
  {
  $sticky_kw = $row['sticky_kw'];

   }

     

    return $sticky_kw;
    }

Even i have tried this:

  function sticky()
    {
     $sticky_kw = $sticky_kw;

    return $sticky_kw;
    }

 

 

But when i want to Echo the Vlaue of sticky(), i see no output.

 

echo sticky();

 

Any Solution Please?

But when i want to Echo the Vlaue of sticky(), i see no output.

Probably because your query is failing?  You need to learn the concept of variable scope.  I have some questions:

- Why can't you pass in $sticky_kw as a parameter to the sticky() method?

- Where is $query coming from?

- How do you know your query is NOT failing?

- If not, how do you know there are matches?

Probably because your query is failing?

Query is generating the output.

 

 - Why can't you pass in $sticky_kw as a parameter to the sticky() method?

Because i can just use the Variable Value by calling the Variable in other Scripts.

 

 - Where is $query coming from?

$query="SELECT * FROM mtr_control_panel WHERE site_url='".$this->site->url."'";

 

- How do you know your query is NOT failing?

I can echo $sticky_kw outside the Function.

 

 

 

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.