Hi,
The problem is that a Uni I am creating a PHP/MySQL based game.
I have got it working for multi user movement and picking up objects but the trouble im having is implementing the puzzles into it.
I have the user table which has my puzzles as:

puzz_1, puzz_2, puzz_3, puzz_4, puzz_5, puzz_6

this is where im saving whether the user has completed it yet or not and my puzzles are saved in another table with all their information, key words, item required etc.

I would be able to complete this section but I am having trouble selecting the puzzle from the MySQL database in the user table.

I need to be able to select from the different fields and haveing googled saw no way to do it.

Basically what i need is:

SELECT * from user_info WHERE id = ' . $_SESSION['userid'] . ' AND ' .  puzz_whatever . ' = ' . $dbroomno . '

If anyone has any ides this would be amazing as it would save me having to write an if statement for each puzzle.

Daryll

Recommended Answers

All 4 Replies

If anyone has any ides this would be amazing as it would save me having to write an if statement for each puzzle.

Daryll

Since there are multiple puzzles, a switch statement would probably be a better option (It's a bit less than an if, but I guess you could use If/Else if you really had your heart set on it).

As for your MySQL, I'm not quite sure what you want. You talked about puzzle tables, yet your SQL has another table in it. What's $dbroomno ? What's Puzz_whatever ?

Sorry for not clarifying fully.
In the MySQL table "user_info" there are 6 fields "puzz_1 - puzz_6"

When the user enters a certain word into the input I want to select the corresponding field.
I do not know how i would do this other than an if statement for each word.

$dbroomno is the variable taken from a table that stores the room number the player is in.
$puzz_whatever was just me trying to show you, i wanted to select puzz_1 - 6 depending on the input.

This is all because the game was originally a single player game, using multiple tables to store the players progression, but as I am changing it to a multiplayer it is not possible to do this without reproducing the data for each player, that is not an option for me.

I hope this clears things up a bit.

Daryll.

Oh ok, I get it now! What you need to do is just use the $dbroomno variable after the puzz_ like this:

if($puzzleNum<7 && $puzzleNum>0) { 
  mysql_query("SELECT * FROM user_info WHERE id = '".$_SESSION['userid']."' AND puzz_".$puzzleNum." = '". $dbroomno);
}

I see what you mean,
thankyou, I shall play around with this for a while and hopefully get it working, i shall mark the thread as solved for now :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.