widget Posted November 25, 2008 Share Posted November 25, 2008 Using PHP and mySQL Background - users collect pieces of a puzzle (9 pieces) As they find and hand in the pieces, they are entered into the database under rows ampiece1 ampiece2 etc etc I need to count those rows, only if not null If the count = 9 then the user will be able to continue. Seeing as the table has many many rows besides the 9 for the puzzle how can I go about selecting the ones I wish to count? TABLE id username password display_name display_prem points age_check rank hunger_level viewed_update referer game location post_count global_post_count active_pet premium plays items_submitted story bricks rings activate_code credits hair eyes lips clothes shoes bottoms top bg socks hat acc glasses earings necklace skin pet lhand rhand mask tattoo underwear ampiece1 ampiece2 ampiece3 ampiece4 ampiece5 ampiece6 ampiece7 ampiece8 ampiece9 EXAMPLE OF FILLED IN DATA ampiece1 ,ampiece2,ampiece3,ampiece4,ampiece5,ampiece6,ampiece7,ampiece8,ampiece9 33421 33422 33423 33424 33425 33427 33428 33429 Ive started off with $sql = mysql_query("SELECT * FROM members2 WHERE username = '$username' AND game = '$game'"); $result = mysql_query($sql); if ($result == 9) { but have no idea what my query should be Quote Link to comment Share on other sites More sharing options...
bluesoul Posted November 25, 2008 Share Posted November 25, 2008 You may want to SELECT all of them as the language is cumbersome and probably wouldn't get your desired result. Instead you can use a loop to check, say, the string length of each variable and if it's greater than 0 (non-null) add it to a count variable. Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 25, 2008 Share Posted November 25, 2008 This should return all the rows where all 9 fields have values SELECT * FROM members2 WHERE username = '$username' AND game = '$game' AND ampiece1 NOT NULL AND ampiece2 NOT NULL AND ampiece3 NOT NULL AND ampiece4 NOT NULL AND ampiece5 NOT NULL AND ampiece6 NOT NULL AND ampiece7 NOT NULL AND ampiece8 NOT NULL AND ampiece9 NOT NULL Quote Link to comment Share on other sites More sharing options...
widget Posted November 26, 2008 Author Share Posted November 26, 2008 That didnt work but this did $amulet = fetch("SELECT * FROM members2 WHERE username = '$username' AND game = '$game'"); if ($amulet[ampiece1] !="" AND $amulet[ampiece2] !="" AND $amulet[ampiece3] !="" AND $amulet[ampiece4] !="" AND $amulet[ampiece5] !="" AND $amulet[ampiece6] !="" AND $amulet[ampiece7] !="" AND $amulet[ampiece8] !="" AND $amulet[ampiece9] !="") { Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.