Jump to content

[SOLVED] How to count some rows from a table that arent Null!! - Help Please


widget

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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] !="")
{

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.