Jump to content

PHP Switch command?


Monkuar

Recommended Posts

like this?

if($statement_is_true){
   $myArr = swapArray($myArr, $oneIndex, $anotherIndex);
}

function swapArray($arr, $x, $y)
{
  $tmp = arr[$x];
  $arr[$x] = $arr[$y];
  $arr[$y] = $tmp;
  return $arr; 
}

 

hmm,  Thanks but I dont think it will work because i need to dynamically figure out the $anotherIndex array, which I cant..

 

I have a field in my DB, 0,1,2  and like if somone presses my "down arrow" it needs to move the 0 down 1, so it's 1,0,2. 

 

But then what if they press it again? It needs to move that 0 down 1 so it's 1,2,0  I just can't figure out how to dynamically do this?

Link to comment
Share on other sites

I have a field in my DB, 0,1,2  and like if somone presses my "down arrow" it needs to move the 0 down 1, so it's 1,0,2. 

 

But then what if they press it again? It needs to move that 0 down 1 so it's 1,2,0  I just can't figure out how to dynamically do this?

 

Are you doing that with AJAX? If so it would be easier to get the position of each element and then send it to PHP already formatted.

Link to comment
Share on other sites

is it always the one after it?

 

$myArr = swapArray($myArr, $oneIndex, $oneIndex +1);

 

otherwise i'm still unsure what you mean

 

On your last code was u missing a $? i added a $

$tmp = $arr[$x];

 

 

 

I have 3 sections, and each 1 has it's own name.

 

Section 1 is 0

 

Section 2 is 1

 

Section 3 is 2

 

my code is

 

$middle=array ( "0"  => array ( "section" => $aboutme,
                                     ),
                  "1" => array ("section" => $signature,
                                     ),


                  "2"   => array ("section" => $f,
                                     ),
                );

$order = array(0,1,2);
print_r($middle);
foreach ($order as $index)
{
  $middlesection.= $middle[$index]['section'];
}

 

See how the array is 0,1,2 ?

 

That is stored in a db field row for each users profile.  I want them to beable to change the order of the sections to there choice.  Kinda better explanation?  :shrug:

 

not with ajax

Link to comment
Share on other sites

I have a field in my DB, 0,1,2

 

If those numbers are supposed to represent ids, then you need to stop what you're doing and normalize your data.  Relational databases like MySQL are not supposed to be used like spreadsheets.  Sticking relationships between different tables into one column is a very bad idea, as you are starting to see.

 

For a quick crash course, read through: http://mikehillyer.com/articles/an-introduction-to-database-normalization/

Link to comment
Share on other sites

so you're looking to update the database instead of just swapping in php right? so that their changes will persist?

 

you have a field for priority or something in this table?

 

what exactly is "down arrow", an image with a querystring link?

 

Yep! exactly, it updates the database row "p" where ID = 1 (or w/e user is updating it)

 

if (isset($ibforums->input['down'])){
$DB->query("UPDATE ibf_members set p='WATTOADDHERE '  WHERE id={$ibforums->member['id']}");
header("Location: ?i={$ibforums->input['i']}");
}

 

See it will update that value p to 0,1,2 or whatever, I have a down arrow and a UP arrow on each field section for them to click it.

 

I would add a "up" input also, but just lost on how to update it based on what they pressed and what the other arrays are... it's so confusing  ::)

 

KevinM1, I will read that link, thank yu

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.