Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Array to Table: Help me clean my code

    I am a coding novice who has assembled the following code from various sources. I am taking long strings of text from a single field in an Oracle database. This text is tab delimited data of varying length. Rather than using

    list($a, $b, $c, $d, $e, $f, $g, $h, $j, $k, $l, $m, $n, $o, $p, $q, $r, $t, $u, $v, $w, $x, $y, $z) = split("\t", oci_result($s,$i), 24);
    print "<td>$a</td><td>$b</td><td>$c</td><td>$d</td><td>$e</td>...[SHORTENED FOR EASIER FORUM READING].......<td>$z</td>";

    to get this data into cells in a table, I would like to clean up the code with something like

    $data = split("/t", $s);

    so that there are no more fields created than needed.

    Unfortunately, my coding skills are weak enough that I can't figure out how to print this into a table correctly. Here is my full code. Can anyone help me? (And if someone wants to help me print the rows of my table in alternating colors, I would appreciate that too). Thanks much!

    <html>
    <body>

    <?php

    PutEnv("ORACLE_SID=PROD");
    PutEnv("ORACLE_HOME=/usr/local/oracle10g/product/10.2.0/db_1");
    PutEnv("LD_LIBRARY_PATH=/usr/local/oracle/oracle10gR2_client/oracle/lib");
    $dataset = $_GET["dataset"];
    #$dataset = 'gm85e09';

    $c=OCILogon("xxxxx", "xxxxx", "xxxxx");
    $s = OCIParse($c, "select dataset_value from dataset_data where dataset_name = '$dataset'");
    OCIExecute($s, OCI_DEFAULT);

    print "Data from <B>$dataset </B>";
    print '<table border="1" cellspacing="0" cellpadding="3">';


    while (oci_fetch($s))
    {
    // Print open and close HTML row tags and columns data.
    print '<tr>';
    for ($i = 1;$i <= oci_num_fields($s);$i++){
    #print '<td class="v">'.oci_result($s,$i).'</td>';
    list($a, $b, $c, $d, $e, $f, $g, $h, $j, $k, $l, $m, $n, $o, $p, $q, $r, $t, $u, $v, $w, $x, $y, $z) = split("\t", oci_result($s,$i), 24);
    print "<td>$a</td><td>$b</td><td>$c</td><td>$d</td><td>$e</td>...[SHORTENED FOR EASIER FORUM READING]....<td>$z</td>";
    }
    print '</tr>';
    }

    print "</table>";


    ?>

    </body></html>
    Last edited by Sapient; 07-02-2007 at 05:28 PM.

  • #2
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    I won't comment on your use of tab delimiting in a database (especially Oracle ).

    PHP Code:
    $data split("/t"$s);

    foreach (
    $data as $value) {
        echo 
    '<td>'.$value.'</td>';


  • #3
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks. I must be doing something wrong, because instead of getting rows with many fields, I get rows with one field, all of which say "Resource id #3". Here is my modified code. Can you tell what I am doing wrong?

    <html>
    <body>

    <?php

    PutEnv("ORACLE_SID=PROD");
    PutEnv("ORACLE_HOME=/usr/local/oracle10g/product/10.2.0/db_1");
    PutEnv("LD_LIBRARY_PATH=/usr/local/oracle/oracle10gR2_client/oracle/lib");
    $dataset = $_GET["dataset"];
    #$dataset = 'gm85e09';

    $c=OCILogon("xxxxx", "xxxxx", "xxxxx");
    $s = OCIParse($c, "select dataset_value from dataset_data where dataset_name = '$dataset'");
    OCIExecute($s, OCI_DEFAULT);

    print "Data from <B>$dataset </B>";
    print '<table border="1" cellspacing="0" cellpadding="3">';


    while (oci_fetch($s))
    {
    // Print open and close HTML row tags and columns data.
    print '<tr>';
    for ($i = 1;$i <= oci_num_fields($s);$i++){

    #print '<td class="v">'.oci_result($s,$i).'</td>';
    $data = split("/t", $s);

    foreach ($data as $value) {
    echo '<td>'.$value.'</td>';
    }
    }
    print '</tr>';
    }

    print "</table>";


    ?>

    </body></html>
    Yeah, I know my Oracle strategy stinks. Unfortunately, I have about a thousand datasets, all with different formats and sizes, that need to be consolidated quickly into Oracle and gotten online. They are all going into a single table with fields identifying what data is from what dataset.

  • #4
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    You probably need to change the first line of my example to this:

    PHP Code:
    $data split("\t"oci_result($s,$i); 
    I was assuming $s was the actual string to be seperated.

  • #5
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by aedrin View Post
    You probably need to change the first line of my example to this:

    PHP Code:
    $data split("\t"oci_result($s,$i); 
    I was assuming $s was the actual string to be seperated.
    I've done that. My output right now places all values into a single field so that my rows are turned vertically and stacked on top of each other. I'll keep trying.

    I do appreciate the help, though. Any ideas are welcome.
    Last edited by Sapient; 07-02-2007 at 10:07 PM.

  • #6
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Never mind. I was messing up my for loop. Thanks for your help.


  •  

    Posting Permissions

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