Array Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Freelancer Deepak
    New Member
    • Jan 2008
    • 13

    Array Problem

    hi friends i have a problem i have written a code for accepting table name , feld names and datatype from user and i want to create a table in database . my problem is that i am auable to create a string for creating table can you suggest me the solutions. I this code $tname is table name , fname is array containg values field names and Dtype is an array containg datatype. when i use print_r($_REQUE ST) i am getting all values that array contains but when i m trying to make string using for loop i am notgetting values.

    [PHP]

    include("conn.p hp");
    echo $fnm = count($_GET['Fname']);
    echo $dtyp = count($_GET['Dtype']);
    $tname = $_REQUEST['tname'];
    print_r($_REQUE ST);
    $str = "create table ".$tname."( ";

    for($i=0;$i<=$f nm;$i++)
    {
    echo $_REQUEST["Fname"][$i];
    echo $str .= $_GET["Fname"][$i]." ".$_GET["Dtype"][$i];
    if(strlen($_GET["Dtype"][$i])>0 && $i != $fnm-1)
    $str.=",";
    }

    $str.=") values";
    echo $str ;







    [/PHP]
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    At first sight I see no problem, except for the $i<=$fnm, which is wrong, but it's early day. This works:[php]$str = "create table ".$tname."( ";
    for($i=0;$i<$fn m;$i++)
    {
    if ($i)
    $str .= ',';
    $sql .= $_GET["Fname"][$i]." ".$_GET["Dtype"][$i];
    }
    $str .= ')';[/php]Ronald

    Comment

    Working...