Jump to content

while


unidox

Recommended Posts

This was my original code:

 

if (($_POST['sort'] == "1") && ($lvl <= 2)) {
		$q2 = mysql_query("SELECT * FROM `pcp_users` WHERE level = '2' AND conf = '1'");
		$q = mysql_query("SELECT * FROM `pcp_users` WHERE level = '2' AND conf = '1' LIMIT $start, $limit");
	} elseif (($_POST['sort'] == "2") && ($lvl <= 3)) {
		$q2 = mysql_query("SELECT * FROM `pcp_users` WHERE level = '3' AND conf = '1'");
		$q = mysql_query("SELECT * FROM `pcp_users` WHERE level = '3' AND conf = '1' LIMIT $start, $limit");
	} elseif (($_POST['sort'] == "3") && ($lvl <= 4)) {
		$q2 = mysql_query("SELECT * FROM `pcp_users` WHERE level = '4' AND conf = '1'");
		$q = mysql_query("SELECT * FROM `pcp_users` WHERE level = '4' AND conf = '1' LIMIT $start, $limit");
	} elseif (($_POST['sort'] == "4") && ($lvl <= 5)) {
		$q2 = mysql_query("SELECT * FROM `pcp_users` WHERE level = '5' AND conf = '1'");
		$q = mysql_query("SELECT * FROM `pcp_users` WHERE level = '5' AND conf = '1' LIMIT $start, $limit");
	} elseif (($_POST['sort'] == "5") && ($lvl <= 6)) {
		$q2 = mysql_query("SELECT * FROM `pcp_users` WHERE level = '6' AND conf = '1'");
		$q = mysql_query("SELECT * FROM `pcp_users` WHERE level = '6' AND conf = '1' LIMIT $start, $limit");
	} elseif ($_POST['sort'] == "6") {
		$q2 = mysql_query("SELECT * FROM `pcp_users` WHERE conf = '2'");
		$q = mysql_query("SELECT * FROM `pcp_users` WHERE conf = '2'");
	} else {
		$q2 = mysql_query("SELECT * FROM `pcp_users` WHERE level >= '$lvl' AND level != '1' AND username != '$user' AND conf = '1'");
		$q = mysql_query("SELECT * FROM `pcp_users` WHERE level >= '$lvl' AND level != '1' AND username != '$user' AND conf = '1' ORDER BY `$order` ASC LIMIT $start, $limit");
	}

 

and I am trying to turn it into a while like this:

 

if (!$_POST['sort']) {
		$q2 = mysql_query("SELECT * FROM `pcp_users` WHERE level >= '$lvl' AND level != '1' AND username != '$user' AND conf = '1'");
		$q = mysql_query("SELECT * FROM `pcp_users` WHERE level >= '$lvl' AND level != '1' AND username != '$user' AND conf = '1' ORDER BY `$order` ASC LIMIT $start, $limit");
	} else {
		if (!is_numeric($_POST['sort'])) {
			exit();
		}
		$q = mysql_query("SELECT * FROM `pcp_groups`");
		$sort = 0;
		while ($r = mysql_fetch_array($q)) {
			$sort++;
			$level = $r['level'];
			if (($_POST['sort'] == $sort) && ($lvl <= $level)) {
				$q2 = mysql_query("SELECT * FROM `pcp_users` WHERE level = '$level' AND conf = '1'");
				$q = mysql_query("SELECT * FROM `pcp_users` WHERE level = '$level' AND conf = '1' LIMIT $start, $limit");
			}
		}
	}

 

but how do I change if (($_POST['sort'] == $sort) && ($lvl <= $level)) { to elseif?

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.