Properties help!

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 559 Views - Last Post: 11 February 2011 - 02:32 PM Rate Topic: -----

#1 Guest_Hopeless*


Reputation:

Properties help!

Posted 09 February 2011 - 12:30 PM

I have a Arrow smith on my game and it should only be able to have one owner. heres my code.

<?

$result = mysql_query("SELECT * FROM Arrowsmithowner WHERE arrowsmith1 = '$name'") or die(mysql_error());
$rows = mysql_num_rows($result);

if($rows == 0)
{
     mysql_query("INSERT INTO Arrowsmithowner SET id='$id', name='$name', arrowsmith1='$name'")
or die(mysql_error());


		echo "You now own this property!";
}
else
{
    echo "This property allready belongs to some one else!";
}
?>



The issue is, when another account clicks the pick up property butten my database just creates another row and 2 people can own it.

Full Texts id name arrowsmith1 arrowsmith2 arrowsmith3 arrowsmith4
Edit Delete 3025 Darrken Darrken
Edit Delete 3023 Hopeless Hopeless

Is This A Good Question/Topic? 0

Replies To: Properties help!

#2 init.d.httpd  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 30
  • View blog
  • Posts: 132
  • Joined: 02-February 11

Re: Properties help!

Posted 09 February 2011 - 12:36 PM

Something is wrong with your first query, because it's never returning the owner and $rows is staying at 0.
Was This Post Helpful? 0
  • +
  • -

#3 Guest_Hopeless*


Reputation:

Re: Properties help!

Posted 09 February 2011 - 12:42 PM

Hmm in not sure how to fix it :/ all the names are right.
Was This Post Helpful? 0

#4 init.d.httpd  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 30
  • View blog
  • Posts: 132
  • Joined: 02-February 11

Re: Properties help!

Posted 09 February 2011 - 12:46 PM

What is $rows if it is not 0? print_r($rows) and see what it is.
Was This Post Helpful? 0
  • +
  • -

#5 Guest_Hopeless*


Reputation:

Re: Properties help!

Posted 09 February 2011 - 12:53 PM

Ok i did it with both accounts. both accounts got 0 and picked it up. but if i click the pick up prop when i already own it, it comes up as 1.
Was This Post Helpful? 0

#6 Guest_Hopeless*


Reputation:

Re: Properties help!

Posted 09 February 2011 - 01:00 PM

View PostHopeless, on 09 February 2011 - 12:53 PM, said:

Ok i did it with both accounts. both accounts got 0 and picked it up. but if i click the pick up prop when i already own it, it comes up as 1.


Let me clarify that a little bit. i did it with both accounts in a row and got 0, then i went back to the first account and tryed to pick it up again and got 1.
Was This Post Helpful? 0

#7 init.d.httpd  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 30
  • View blog
  • Posts: 132
  • Joined: 02-February 11

Re: Properties help!

Posted 09 February 2011 - 01:00 PM

It sounds like you are comparing the wrong variable, to the wrong table or vice versa. Something along those lines anyway.
Was This Post Helpful? 0
  • +
  • -

#8 Guest_Hopeless*


Reputation:

Re: Properties help!

Posted 09 February 2011 - 01:04 PM

View Postinit.d.httpd, on 09 February 2011 - 01:00 PM, said:

It sounds like you are comparing the wrong variable, to the wrong table or vice versa. Something along those lines anyway.


hmm well heres the table name

Arrowsmithowner

This is whats in the table.

id name arrowsmith1 arrowsmith2 arrowsmith3 arrowsmith4


This is what the table looks like with both the people owning it.
id name arrowsmith1 arrowsmith2 arrowsmith3 arrowsmith4
3025 Darrken Darrken
3023 Hopeless Hopeless
Was This Post Helpful? 0

#9 init.d.httpd  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 30
  • View blog
  • Posts: 132
  • Joined: 02-February 11

Re: Properties help!

Posted 09 February 2011 - 01:11 PM

Why dont you just check for the id? if the id is in that db then it has an owner. Why is there arrowsmith2 arrowsmith3 arrowsmith4 if there can only be one owner?

This is kind of confusing with out knowing all of the pieces to the puzzle
Was This Post Helpful? 0
  • +
  • -

#10 Guest_Hopeless*


Reputation:

Re: Properties help!

Posted 09 February 2011 - 01:21 PM

View Postinit.d.httpd, on 09 February 2011 - 01:11 PM, said:

Why dont you just check for the id? if the id is in that db then it has an owner. Why is there arrowsmith2 arrowsmith3 arrowsmith4 if there can only be one owner?

This is kind of confusing with out knowing all of the pieces to the puzzle


So instead of using $name i should use $id?


theres going to be 4 arrow smiths in the game, and only 1 person needs to be able to own each one.
Was This Post Helpful? 0

#11 init.d.httpd  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 30
  • View blog
  • Posts: 132
  • Joined: 02-February 11

Re: Properties help!

Posted 09 February 2011 - 01:26 PM

View PostHopeless, on 09 February 2011 - 01:21 PM, said:

View Postinit.d.httpd, on 09 February 2011 - 01:11 PM, said:

Why dont you just check for the id? if the id is in that db then it has an owner. Why is there arrowsmith2 arrowsmith3 arrowsmith4 if there can only be one owner?

This is kind of confusing with out knowing all of the pieces to the puzzle


So instead of using $name i should use $id?


Not if any user can have more than one with the same id. I would see if your variable $name is correct before the select query. something about that query is killing the mysql_num_rows request.
Was This Post Helpful? 1
  • +
  • -

#12 Guest_Hopeless*


Reputation:

Re: Properties help!

Posted 09 February 2011 - 07:22 PM

View Postinit.d.httpd, on 09 February 2011 - 01:26 PM, said:

View PostHopeless, on 09 February 2011 - 01:21 PM, said:

View Postinit.d.httpd, on 09 February 2011 - 01:11 PM, said:

Why dont you just check for the id? if the id is in that db then it has an owner. Why is there arrowsmith2 arrowsmith3 arrowsmith4 if there can only be one owner?

This is kind of confusing with out knowing all of the pieces to the puzzle


So instead of using $name i should use $id?


Not if any user can have more than one with the same id. I would see if your variable $name is correct before the select query. something about that query is killing the mysql_num_rows request.



I dont think theres anything wrong with the num_Rows.

it just thinks each user can make a row :/ it comes up as 0 if you haven't picked it up yet. then once you pick it up and you click again, it says "1" this prop allready has an owner.
Was This Post Helpful? 0

#13 Guest_Hopeless*


Reputation:

Re: Properties help!

Posted 10 February 2011 - 01:37 AM

I found out that its my sessions that are makeing it not work. any advice?
Was This Post Helpful? 0

#14 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 514
  • View blog
  • Posts: 1,604
  • Joined: 08-November 08

Re: Properties help!

Posted 10 February 2011 - 01:52 AM

Honestly, as a suggestion that might make more sense in terms of what you appear to be trying to accomplish, I'd like to respectfully submit that the flaw is in your table design. What you should probably be doing is making a table for arrowsmiths, with a row for each. Each arrowsmith will have an ID, and a name (if you're doing it that way), and an owner column, which will default to empty (or 0 if you're tying it to users by ID instead of name), but when owned will contain a user's name or ID.

You'd fetch that arrowsmith by ID or name or whatever, and if the owner column is empty (or 0 if you're going by ID), it would be available for purchase.

Does that make better sense?
Was This Post Helpful? 1
  • +
  • -

#15 Jstall  Icon User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: Properties help!

Posted 10 February 2011 - 09:05 AM

Hi,

In what was are your sessions making it not work?

It looks to me like you are not getting any records from your first query even though you are expecting to, that suggests $name is not what you think it is. Are you getting this from a session variable?

I agree with Valek in that your database schema is a bit wonky, you should consider making the modifications he suggested.

This is just a guess here but do
$name = trim($name);



Before you do your first query, sometimes whitespace can mess things like that up.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2