1

I'm looking for some help to automate this process.

Here's my full page of code. http://www.privatepaste.com/65bbd73d3b Sorry I used privatepaste, but it was too much code for me to format nicely by putting 4 lines infront of each (if there's a fast way to do this, let me know for my next SO question!)

Basically, if you look at line 53, I have this.

$checkdonors = mysql_query("SELECT userid FROM user WHERE membergroupids LIKE '%33'");

I'm trying to make it so it checks if the userid's membergroupids field contains 33, which it checks fine. However, I want to add it to an if condition, shown on line 77.

<td <?php if ($tuserid==$checkdonors) { ?> style="background-color:#D0F2CD;" <?php } elseif ($tids=='1' AND $toonid==$tid) { ?> style="background-color:#FFD2F9; <?php } ?>">

Because, on the next td, I have..

<td <?php if ($tuserid=='602' || $tuserid=='232' || $tuserid=='200' || $tuserid=='563' || $tuserid=='532') { ?>

Those 5 userid's (602,232,200,563,532) are the users I have in membergroupids 33, but I had to do it manually.

I'd like to automate the process, so I don't have to add a new $tuserid=='userid' every time a member is added to membergroupids '33'.

How can I do this?

Thank you so much.

8
  • what is the reason why you are explicitly checking those IDs? and why are they hardcoded? Commented Oct 7, 2014 at 0:35
  • Hi @Ghost The users who are in those userid's are VIPs (staff, to be specific). I want there td-cell background color to be different from the others. It's working fine hardcoded, and as new ones are added, I can just keep adding more id's to it. However, I'd like to automate it, and I think arrays are used, but if you can tell by the old coding methods I use in my privatepaste, I don't know how to use arrays. I'm a beginner. Thanks! Commented Oct 7, 2014 at 0:38
  • Why not introduce a role concept or an admin flag an check for a a given role or if the admin flag is set? Commented Oct 7, 2014 at 0:41
  • so those 602,232,200,563,532 are those vips ? and they are the result of SELECT userid FROM user WHERE membergroupids LIKE '%33'? Commented Oct 7, 2014 at 0:41
  • @ZombieHunter could you explain more? Commented Oct 7, 2014 at 0:42

1 Answer 1

1

If I understand correctly, you could just do something like this:

// You could gather all of those ids first
$donors = array();
$checkdonors = mysql_query("SELECT userid FROM user WHERE membergroupids LIKE '%33'");
while($r = mysql_fetch_assoc($checkdonors)) {
    $donors[] = $r['userid'];
}

So that when you're inside that other loop. You could use in_array():

if(in_array($tuserid, $donors)) {
    // if that current id in the current loop is one of those donors
    // do something
}

Sidenote: If possible, switch to the better mysql extension which is mysqli or use PDO instead.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much Ghost, this worked beautifully. In the past, people have suggested to switch to mysqli or use PDO, but I haven't learned either. I run a vBulletin powered forum, and I learned the HTML, php, mysql, etc by running vBulletin forums for years. While I'd like to learn PDO or mysqli, I don't know where to start, and this basic PHP (I guess you can call it that) is doing the job. Waiting for a minute to pass so I can give you best answer. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.