have a problem in arrays that having multiple forms

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • annerhexian
    New Member
    • Jan 2008
    • 14

    #1

    have a problem in arrays that having multiple forms

    hi..

    pls help me...
    im just new in php and i wish i could learn more.. i needed it for one day or two..hope u can reconsider my questions to you.. pls do help me..

    i want my row array will be a column.....

    pls see me first my codes:
    Code:
    DATAbase:               
    	form1academicbachelor varchar(20) not null,
    	form1bachelorschool varchar(20),
    	form1bachelorschoolyear varchar(20),
    	form1academicMasteral varchar(20) not null,
    	form1masteralschool varchar(20),
    	 form1masteralschoolyear varchar(20),
    [code=php]

    <?php
    include 'dbConnect.php' ;
    mysql_select_db ("ranking",$con );

    $form1academicb achelor=array() ;
    $form1bachelors chool=array();
    $form1bachelors choolyear=array ();
    $form1academicM asteral=array() ;

    $form1academicb achelor=$_POST['bacheloracadfo rm1'];
    $form1bachelors chool=$_POST['bachschoolname form1'];
    $form1bachelors choolyear=$_POS T['bachyeargradua tedform1'];
    $form1academicM asteral=$_POST['masteralacadem icsform1'];

    $form1academicb achelor=implode (',',$form1acad emicbachelor);
    $form1bachelors chool=implode(' ,',$form1bachel orschool);
    $form1bachelors choolyear=implo de(',',form1bac helorschoolyear );
    $form1academicM asteral=implode (',',$form1acad emicMasteral);

    echo "<table border=1 cellspacing=0 width = 700>

    <tr bgcolor=dddddd>
    <td align=center> <font color=8B0000 size=2><b> Bachelor Degree </b> </font></td>
    <td align=center> <font color=8B0000 size=2><b> School Name </b> </font></td>
    <td align=center> <font color=8B0000 size=2><b> School Year </b> </font></td>
    </td>
    ";


    echo' <tr>
    <td align=center> '.$form1academi cbachelor.' </td>
    <td align=center> '.$form1bachelo rschool.' </td>
    <td align=center> '.$form1bachelo rschoolyear.' </td>

    <td align=center>

    <span class="style2"> <font size=2>

    </font></span>

    </td>
    </tr>';

    echo "</table>";

    ?>
    [/code]

    ouput:
    Code:
    ===============================================
    BACHELOR DEGREE  | SCHOOL NAME  | SCHOOL YEAR
    ===============================================
    BSIT,BSM,BEED    | sc1,sc2,sc3  | yy1,yy2,yy3
    i want my output that will be like this
    Code:
    ==============================================
    BACHELOR DEGREE  | SCHOOL NAME  | SCHOOL YEAR
    ==============================================
    BSIT             | sc1          | yy1
    BSM              | sc2          | yy2
    BEED             | sc3          | yy3
    ==============================================
    MASTERAL DEGREE  | SCHOOL NAME  | SCHOOL YEAR
    ==============================================
    xxxx1            | kk1          | ppp1
    xxx2             | kk2          | pp2
    pls give me some suggestions in here on how to get like that format..

    I really want that the arraybachelorva riable() will be a column and not a row...
    and so on with the other.....

    hoping for your help and thank you so much in advance..
    Last edited by Atli; Jan 19 '08, 10:52 PM. Reason: Added [code] tags.
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    You really need to learn to code right, try doing some online tutorials.

    If i had 3 series of data that i needed to put in a column i would do a forlook like this

    [PHP]
    <table >
    <?php
    for ($i = 0; $i < count($oneOfMyA rrays); $i++)
    {
    echo "<tr><td>" . $arrayOne[$i] . "</td>
    <td>" . $arrayTwo[$i] . "</td>
    </td>" . $thirdArr[$i] . "</td></tr>";
    }
    ?>
    </table>
    [/PHP]

    NOTE*: The above assumes you'll always have the same size for all three arrays! There's no error checking for the index.

    Hope that helps you.

    Comment

    • enumula
      New Member
      • Apr 2007
      • 7

      #3
      Hi

      Here is code...Hope this wud help u...


      DB file:-
      Code:
      -- phpMyAdmin SQL Dump
      -- version 2.6.1
      -- [url]http://www.phpmyadmin.net[/url]
      -- 
      -- Host: localhost
      -- Generation Time: Jan 18, 2008 at 04:23 PM
      -- Server version: 4.1.9
      -- PHP Version: 4.3.10
      -- 
      -- Database: `form`
      -- 
      
      -- --------------------------------------------------------
      
      -- 
      -- Table structure for table `bachelor`
      -- 
      
      DROP TABLE IF EXISTS `bachelor`;
      CREATE TABLE `bachelor` (
        `bachelor_id` int(11) NOT NULL auto_increment,
        `form1academicbachelor` varchar(100) NOT NULL default '',
        `form1bachelorschool` varchar(100) NOT NULL default '',
        `form1bachelorschoolyear` varchar(100) NOT NULL default '',
        `form1academicMasteral` varchar(100) NOT NULL default '',
        PRIMARY KEY  (`bachelor_id`)
      ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
      
      -- 
      -- Dumping data for table `bachelor`
      -- 
      
      INSERT INTO `bachelor` VALUES (1, 'swetha', 'Keys High School', '2000', 'BRECW');
      INSERT INTO `bachelor` VALUES (2, 'Raj', 'HBSP', '2000', 'PG');
      dbConnect.php
      [code=php]
      <?
      $connection_typ e = "local";

      if ($connection_ty pe == "local")
      {
      $db_servername= "localhost" ;
      $db_username="r oot";
      $db_password="" ;
      $db_name="form" ;
      $db_link = mysql_connect($ db_servername, $db_username, $db_password) or die("could not connect to the local atebase server");
      $db= mysql_select_db ($db_name,$db_l ink) or die("Not a valid database");

      }
      ?>
      [/code]

      function.php
      [code=php]
      <?php


      class execute_query
      {
      //getting the list of categorys
      function get_result_deta ils($select_que ry)
      {
      require 'dbConnect.php' ;
      $results=array( );
      $select_query_r esult=mysql_que ry($select_quer y,$db_link) or die(" Not a valid Select Query Category ".mysql_error() );
      if(mysql_num_ro ws($select_quer y_result) > 0)
      {
      while($get_deta ils=mysql_fetch _array($select_ query_result))
      {
      $array_count=co unt($get_detail s)/2;
      for($i=0;$i<$ar ray_count;$i++)
      {
      $results[]=$get_details[$i];
      }
      }
      }
      //To Free the result set
      mysql_free_resu lt($select_quer y_result);
      //To Close the connection object
      mysql_close($db _link);
      return $results;
      }


      //Insert Query function ....
      function insert_query($i nsert_query)
      {
      require 'dbConnect.php' ;
      $insert_id="";
      $insert_query_r esult=mysql_que ry($insert_quer y,$db_link) or die(" Not a valid Insert Query ".mysql_error() );
      $insert_id=mysq l_insert_id();
      mysql_close($db _link);
      return $insert_id;
      }


      }
      ?>
      [/code]

      form.php
      [code=php]
      <?php


      require 'function.php';

      ?>
      <form name='formname' method= post action="insert. php" >
      academicbachelo r&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;<input type=textbox name="form1acad emicbachelor" value=""><br>
      bachelorschool& nbsp;&nbsp;&nbs p&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;<input type=textbox name="form1bach elorschool" value=""><br>
      bachelorschooly ear&nbsp;&nbsp; <input type=textbox name="form1bach elorschoolyear" value=""><br>
      academicMastera l&nbsp;&nbsp;&n bsp;&nbsp;<inpu t type=textbox name="form1acad emicMasteral" value="">
      <input type="hidden" name="bachelor" >
      <input type="submit" name="submit" value="submit" >
      <?

      $query="select * from bachelor";
      $obj_query= new execute_query() ;
      $type_array=$ob j_query->get_result_det ails($query);

      $array_length=c ount($type_arra y);
      $form1academicb achelor=array() ;
      $form1bachelors chool=array();
      $form1bachelors choolyear=array ();
      $form1academicM asteral=array() ;

      echo "<table border=1 cellspacing=0 width = 700>

      <tr bgcolor=dddddd>
      <td align=center> <font color=8B0000 size=2><b> Bachelor ID </b> </font></td>
      <td align=center> <font color=8B0000 size=2><b> Bachelor Name </b> </font></td>
      <td align=center> <font color=8B0000 size=2><b> School Name </b> </font></td>
      <td align=center> <font color=8B0000 size=2><b> School Year </b> </font></td>
      <td align=center> <font color=8B0000 size=2><b> Bachelor Masteral </b> </font></td>
      </td>
      ";

      for($i=0;$i<$ar ray_length;$i++ )
      {
      echo' <tr>
      <td align=center> '.$type_array[$i].' </td>
      <td align=center> '.$type_array[$i+1].' </td>
      <td align=center> '.$type_array[$i+2].' </td>
      <td align=center> '.$type_array[$i+3].' </td>
      <td align=center> '.$type_array[$i+4].' </td>

      </tr>';
      $i=$i+4;
      }

      echo "</table>";

      ?>
      [/code]

      insert.php
      [code=php]
      <?

      include 'settings.php';
      require 'function.php';
      $obj_query= new execute_query() ;
      $form1academicb achelor=$_POST['form1academicb achelor'];
      $form1bachelors chool=$_POST['form1bachelors chool'];
      $form1bachelors choolyear=$_POS T['form1bachelors choolyear'];
      $form1academicM asteral=$_POST['form1academicM asteral'];
      $insert="insert into bachelor (form1academicb achelor,form1ba chelorschool,fo rm1bachelorscho olyear,form1aca demicMasteral) values ('$form1academi cbachelor','$fo rm1bachelorscho ol','$form1bach elorschoolyear' ,'$form1academi cMasteral')";
      $insert_value= $obj_query->insert_query($ insert);

      header("Locatio n:form.php");
      exit;
      ?>
      [/code]
      output:-
      Code:
      Bachelor ID  Bachelor Name  School Name  School Year  Bachelor Masteral  
      1                        swetha     Keys High School        2000              BRECW  
      2                            Raj            HBSP                   2000                  PG
      Check it out....
      Last edited by Atli; Jan 19 '08, 10:55 PM. Reason: Added [code] tags.

      Comment

      • annerhexian
        New Member
        • Jan 2008
        • 14

        #4
        Originally posted by enumula
        Hi

        Here is code...Hope this wud help u...

        ...

        output:-

        Bachelor ID Bachelor Name School Name School Year Bachelor Masteral
        1 swetha Keys High School 2000 BRECW
        2 Raj HBSP 2000 PG


        Check it out....

        thnak you for the help it was already solved already..
        Last edited by Atli; Jan 19 '08, 10:58 PM. Reason: Shortened the quote to make the post readable.

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Hi annerhexian and enumula.

          Please use &#91;code] tags when posting your code examples. (See How to ask a question)

          &#91;code=ph p] ...PHP code goes here... &#91;/code]

          Thank you.
          Moderator

          Comment

          • enumula
            New Member
            • Apr 2007
            • 7

            #6
            Originally posted by Atli
            Hi annerhexian and enumula.

            Please use &#91;code] tags when posting your code examples. (See How to ask a question)

            &#91;code=ph p] ...PHP code goes here... &#91;/code]

            Thank you.

            Moderator

            Thanku ....
            Ill may sure to it frm next time.:-)

            Comment

            • annerhexian
              New Member
              • Jan 2008
              • 14

              #7
              Originally posted by enumula
              Thanku ....
              Ill may sure to it frm next time.:-)

              THANK U for helping and teh tips my frienD..god Bless always

              Comment

              Working...