Jump to content

Link two tables but limit results


adzie

Recommended Posts

Hello all,

 

Appreciate your advice as i've hit a wall now

 

Table 1 - user_awards

award_id

award_title

 

Table 2 - awards

user_id

(a column for each award_id) 0 = no, 1 = yes

 

 

I'd like to ideally create a result where it then displays all the records where the column in table 2 is 1 but I want to limit it to say 5 where the user_awards table = 1, however at present it counts five including entries where its 0.  This is where i'm getting unstuck so appreciate any advice.  Code snippet below.

 

 

 

  $awardCodes = mysql_query("SELECT * FROM `user_awards` WHERE `user_id` = 1"); 
  $awardsres = mysql_fetch_assoc($awardCodes);
  $awards = mysql_query("SELECT * FROM `awards` ORDER BY 'award_id' ASC LIMIT 4");  

  // Loop through award codes
  while ($ac2 = mysql_fetch_assoc($awards)) {  
  $ac22 = db_entry_check($awardsres[$ac2[award_id]])? 1 : 0; 
   
  if ($ac22 != $actual && $ac22 == 1) {
  
echo "$ac22[award_title]";

   }
   
   }

 

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.