www.webdeveloper.com
Results 1 to 2 of 2

Thread: A loop that will change variable name? I don't know how else to explain it...

  1. #1
    Join Date
    Apr 2008
    Posts
    85

    A loop that will change variable name? I don't know how else to explain it...

    Here's my HTML code (which is actually created with a PHP loop):

    PHP Code:

    ...


    <center>

    <form method="post" action="events_save.php">
    <table>

    <?

    include("config.php"); 

    // connect to the mysql server
    $link mysql_connect($server$db_user$db_pass)
    or die (
    "Could not connect to mysql because ".mysql_error());

    // select the database
    mysql_select_db($database)
    or die (
    "Could not select database because ".mysql_error());


    $query  "SELECT chron, date, details FROM $table3";
    $result mysql_query($query);
    $variable mysql_fetch_row($result);

    while(
    $row mysql_fetch_array($resultMYSQL_ASSOC))
    {

    echo 
    "<tr>
        <td><input name=\"date
    {$row['num']}\" size=\"2\" type=\"text\" value=\"{$row['date']}\"> </td>
        <td><textarea cols=\"30\" rows=\"5\" name=\"det
    {$row['num']}\" size=\"300\">{$row['details']}</textarea></td>
    </tr>"
    ;

    }

    ?>

    </table>


    <input type="submit" value="Save">
    </form>
    </center>


    </body>
    </html>

    Here's my unfinished PHP:

    PHP Code:


    <?

    include("config.php");

    // connect to the mysql server
    $link mysql_connect($server$db_user$db_pass)
    or die (
    "Could not connect to mysql because ".mysql_error());

    // select the database
    mysql_select_db($database)
    or die (
    "Could not select database because ".mysql_error());



    // VARIABLES?!?!



    for ($num 1$num <= 13$num=$num+1) {
        

        
       
    $sql "UPDATE events SET date='', details='' WHERE chron=$num";

        
    mysql_query($sql) or die("Changes could not be saved. Please use the 'BACK' button and try again.");

    }

    echo 
    "Changes Saved"


    ?>
    I am trying to make some sort of loop that will change the value of SET 'date' and 'det' so I can have the respective content (1 through 13) inserted into the table. Does that make sense?

    I can obviously use the loop to change the value of $num which changes the row that the content is inserted to, but how can I change the CONTENT itself to each of the POSTED values upon each run through the loop?

    Thank you very much!

  2. #2
    Join Date
    Feb 2009
    Posts
    162
    for ($num = 1; $num <= 13; $num=$num+1) {

    There are two way

    first Create array in your HTML code and next page get those valurs from that array

    Secondly,

    Pass the variable with total Input box created
    next page

    get that varaible and then make the for loop

    hopes it help.

    apple iphone 2009/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles