Help with Arrays

From: Date: Fri, 02 May 2003 17:15:50 +0000
Subject: Help with Arrays
Groups: php.db 
Request: Send a blank email to php-db+get-27490@lists.php.net to get a copy of this message
Am I doing this right? Is there documentation online somewhere for how to do this? I have a form in which the user can select multiple checkboxes for each day of the week...that form is then passed to the script below and what I need to be able to do is declare some type of loop or foreach statement that follows this logic: FOREACH $dayofweek INSERT $newrow INTO TABLE $dayofweek is an Array...my code below is working IF I want to only enter one of the checkbox values, BUT if I want to enter seperate rows for each checkbox it breaks or gets thrown into an endless loop.... Any ideas would be appreciated. ======= THIS PORTION WORKS ======== <? $airdate = $_REQUEST['airdate'];
        if (count($airdate) > 0)
        {
                for ($i=0; $i < count($airdate); $i++)
                {
                        $connection = mysql_connect("localhost","user","pass") or die ("Couldn't make connection.");
                        $db = mysql_select_db("testing", $connection) or die ("Couldn't select database.");
                        $sql = "INSERT INTO days (airdate) VALUES ('$airdate[$i]')";
                        $sql_result = mysql_query($sql,$connection) or die("Couldn't execute query.");
                        $sql2 = "SELECT dayid FROM days WHERE airdate = '$airdate[$i]'";
                        $sql_result2 = mysql_query($sql2,$connection) or die("Couldn't execute query.");
                        while ($row = mysql_fetch_array($sql_result2)):
                                $dayid = $row["dayid"];
                        endwhile;
                        $sql3 = "SELECT timeid FROM times WHERE airtime = '$_REQUEST[airtime]'";
                        $sql_result3 = mysql_query($sql3,$connection) or die("Couldn't execute query.");
                        while ($row = mysql_fetch_array($sql_result3)):
                                $timeid = $row["timeid"];
                        endwhile;
                        $sql4 = "SELECT showid FROM shows WHERE showid = '$_REQUEST[showid]'";
                        $sql_result4 = mysql_query($sql4,$connection) or die("Couldn't execute query.");
                        while ($row = mysql_fetch_array($sql_result4)):
                                $showid = $row["showid"];
                        endwhile;
                        ===== UP TO HERE =====
                        ===== THIS PORTION BREAKS =====
                        $dayids = count($dayid) > 0;
                        {
                                echo "$dayids[]";
                                //$sql5 = "INSERT INTO schedule (id, dayid, timeid, showid) VALUES ('', '$dayid', '$timeid', '$showid')";
                                //$sql_result5 = mysql_query($sql5,$connection) or die("Couldn't execute query.");
                        }
                        mysql_close($connection);
                }
        }
?> Thanks in advance... Jay Fitzgerald, Design Director - CPW-A, CPWDS-A, CPWDV-A, CECM-A, CWCSB-A Bayou Internet - http://www.bayou.com Toll Free: 888.30.BAYOU (22968) Vox: 318.338.2034 / Fax: 318.338.2506 E-Mail: jayfitz@bayou.com ICQ: 38823829 / AIM: bayoujf / MSN: bayoujf / Yahoo: bayoujf

« previous php.db (#27490) next »