Jump to content

Recommended Posts

Can anyone see the error here?

What i am trying to do is declare 3 variables for 15 categories named $var_category number_1 up to 3.

 

The error must be in the variables $features_$x_1 name but i am too new to find out.

Thank you.

 

// <!-- ---------------------------------------------------------------------------------------------------- -->

$x=1;
while($x <= 15)
{

$results = mysql_query("SELECT * FROM features where catid = $x");
$num_rows = mysql_num_rows($results);
$ii = $num_rows/3;
$ii = round($ii, 0, PHP_ROUND_HALF_UP);
$i = 1;
while($r = mysql_fetch_assoc($results))
{
if ($i > 00 && $i <= $ii){$features_$x_1.= "<input type='checkbox' name='features($r[id])' value='1' />$r[name] </br>";}
if ($i > $ii && $i <= $ii*2){$features_$x_2.= "<input type='checkbox' name='features($r[id])' value='1' />$r[name] </br>";}
if ($i > $ii*2 && $i <= $ii*3){$features_$x_3.= "<input type='checkbox' name='features($r[id])' value='1' />$r[name] </br>";}	        
        $i++;
        }	
$x=$x+1;       
}
        	
mysql_close();

?>

You would need variable variables here. Something along the lines of:

if ($i > 00 && $i <= $ii){$var_name = "$features_{$x}_1"; $$var_name .= "<input type='checkbox' name='features($r[id])' value='1' />$r[name] </br>";}

 

But, that looks hideous. Can't you just use arrays?

$features[$x] = "<input type='checkbox' name='features($r[id])' value='1' />$r[name] </br>";

Thank you scootstah. No i can not use array because the variable has the category number and the split number also.

 

This does not work also:

 

$x=1;
while($x <= 15)
{

$results = mysql_query("SELECT * FROM features where catid = $x");
$num_rows = mysql_num_rows($results);
$ii = $num_rows/3;
$ii = round($ii, 0, PHP_ROUND_HALF_UP);
$i = 1;
while($r = mysql_fetch_assoc($results))
{
if ($i > 00 && $i <= $ii){$var_name = "$features_{$x}_1"; $$var_name .= "<input type='checkbox' name='features($r[id])' value='1' />$r[name] </br>";}
if ($i > $ii && $i <= $ii*2){$var_name = "$features_{$x}_2"; $$var_name .= "<input type='checkbox' name='features($r[id])' value='1' />$r[name] </br>";}
if ($i > $ii*2 && $i <= $ii*3){$var_name = "$features_{$x}_3"; $$var_name .= "<input type='checkbox' name='features($r[id])' value='1' />$r[name] </br>";}	        
        $i++;
        }	
$x=$x+1;       
}

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.