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
https://forums.phpfreaks.com/topic/88598-dimensional-php-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.