Jump to content

dimensional php array


welch

Recommended Posts

I have a bit of a problem. I have a table that contains all the navigation links with ID, Name(input), URL(input_, Display_order(input), and active(checkbox).

 

I loop through these to create an edit table. I am lost what the best method would be to take each row as an array, then update it where id=id.

 


while(false !== $rs = mysql_fetch_array($result)) {
          $id = $rs["id"];
          echo ("
          <tr>
                <td width=\"30%\"><input type=\"text\" name=\"name[]\" size=\"30\" value=\"" . $rs["name"] . "\"> </td>
                <td width=\"40%\"><input type=\"text\" name=\"url[]\" size=\"40\" value=\"". $rs["url"] ."\"> </td>
                <td width=\"15%\"><input type=\"text\" name=\"display_order[]\" size=\"2\" value=\"".$rs["display_order"]."\"> </td>
                <td width=\"7%\"><input type=\"checkbox\" name=\"active[]\" value=\"".$rs["id"]."\" "); if($rs["active"] == 1){ echo "checked"; } echo ("></td>
                <td width=\"7%\"><input type=\"checkbox\" value=\"".$rs["id"]."\"  name=\"delete[]\"></td>
          </tr>
          ");
          }

 

So far I have this

 

if($_SERVER['REQUEST_METHOD']=='POST'){

    /* Loop through post and add it to array */
    $i=0;
    foreach( $_POST as $pkey => $pval ){
        $posted[$i][]=$pkey;
        $posted[$i][]=$pval;
        $i++;
        htmlspecialchars($pval);
    }
    /* Loop through the Array and Display the Values */
    echo "<b>Echo Keys and Values</b><p>";
    for($z=0;$z<$i;$z++){
        echo 'The key "'.$posted[$z][0].'" equals value "'.$posted[$z][1].'"<br>';
    }
    /* Loop through each Key and Value and Add it to the String */
    echo "<p><b>Create Select Statement</b><p>";
    $string = '';
    for($z=1;$z<$i - 1;$z++){
        $string .= ' and ' . $posted[$z][0] . '="'.$posted[$z][1].'"';
    }
    /* Create the Query */
    $querythis = 'UPDATE swappnavigation SET '. $posted[0][0] .'="'. $posted[0][1] .'"'. $string .'';
    echo $querythis;
    echo '<br><input type="button" value="Back" onClick="history.go(-1)">';

}

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.