Connecting Tech Pros Worldwide Forums | Help | Site Map

have a problem in arrays that having multiple forms

Newbie
 
Join Date: Jan 2008
Posts: 14
#1: Jan 13 '08
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:
Expand|Select|Wrap|Line Numbers
  1. DATAbase:               
  2.     form1academicbachelor varchar(20) not null,
  3.     form1bachelorschool varchar(20),
  4.     form1bachelorschoolyear varchar(20),
  5.     form1academicMasteral varchar(20) not null,
  6.     form1masteralschool varchar(20),
  7.      form1masteralschoolyear varchar(20),
  8.  
Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php    
  3.     include 'dbConnect.php';
  4.     mysql_select_db("ranking",$con);
  5.  
  6.     $form1academicbachelor=array();
  7.     $form1bachelorschool=array();
  8.     $form1bachelorschoolyear=array();
  9.     $form1academicMasteral=array();
  10.  
  11.     $form1academicbachelor=$_POST['bacheloracadform1'];
  12.     $form1bachelorschool=$_POST['bachschoolnameform1'];
  13.     $form1bachelorschoolyear=$_POST['bachyeargraduatedform1'];
  14.     $form1academicMasteral=$_POST['masteralacademicsform1'];
  15.  
  16.     $form1academicbachelor=implode(',',$form1academicbachelor);
  17.     $form1bachelorschool=implode(',',$form1bachelorschool);
  18.     $form1bachelorschoolyear=implode(',',form1bachelorschoolyear);
  19.     $form1academicMasteral=implode(',',$form1academicMasteral);
  20.  
  21. echo "<table border=1 cellspacing=0 width = 700>
  22.  
  23.         <tr bgcolor=dddddd>
  24.         <td align=center> <font color=8B0000 size=2><b> Bachelor Degree </b> </font></td>
  25.         <td align=center> <font color=8B0000 size=2><b> School Name </b> </font></td>
  26.         <td align=center> <font color=8B0000 size=2><b> School Year </b> </font></td>
  27.         </td>
  28. ";
  29.  
  30.  
  31. echo'     <tr>
  32.         <td align=center> '.$form1academicbachelor.' </td>
  33.         <td align=center> '.$form1bachelorschool.' </td>
  34.         <td align=center> '.$form1bachelorschoolyear.' </td>
  35.  
  36.         <td align=center>
  37.  
  38.         <span class="style2"><font size=2>
  39.  
  40.         </font></span>
  41.  
  42.         </td>
  43.         </tr>';
  44.  
  45. echo "</table>";
  46.  
  47. ?>
  48.  
ouput:
Expand|Select|Wrap|Line Numbers
  1. ===============================================
  2. BACHELOR DEGREE  | SCHOOL NAME  | SCHOOL YEAR
  3. ===============================================
  4. BSIT,BSM,BEED    | sc1,sc2,sc3  | yy1,yy2,yy3
  5.  
i want my output that will be like this
Expand|Select|Wrap|Line Numbers
  1. ==============================================
  2. BACHELOR DEGREE  | SCHOOL NAME  | SCHOOL YEAR
  3. ==============================================
  4. BSIT             | sc1          | yy1
  5. BSM              | sc2          | yy2
  6. BEED             | sc3          | yy3
  7. ==============================================
  8. MASTERAL DEGREE  | SCHOOL NAME  | SCHOOL YEAR
  9. ==============================================
  10. xxxx1            | kk1          | ppp1
  11. xxx2             | kk2          | pp2
  12.  
pls give me some suggestions in here on how to get like that format..

I really want that the arraybachelorvariable() 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..

dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,095
#2: Jan 17 '08

re: have a problem in arrays that having multiple forms


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($oneOfMyArrays); $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.
Newbie
 
Join Date: Apr 2007
Posts: 7
#3: Jan 18 '08

re: have a problem in arrays that having multiple forms


Hi

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


DB file:-
Expand|Select|Wrap|Line Numbers
  1. -- phpMyAdmin SQL Dump
  2. -- version 2.6.1
  3. -- http://www.phpmyadmin.net
  4. -- 
  5. -- Host: localhost
  6. -- Generation Time: Jan 18, 2008 at 04:23 PM
  7. -- Server version: 4.1.9
  8. -- PHP Version: 4.3.10
  9. -- 
  10. -- Database: `form`
  11. -- 
  12.  
  13. -- --------------------------------------------------------
  14.  
  15. -- 
  16. -- Table structure for table `bachelor`
  17. -- 
  18.  
  19. DROP TABLE IF EXISTS `bachelor`;
  20. CREATE TABLE `bachelor` (
  21.   `bachelor_id` int(11) NOT NULL auto_increment,
  22.   `form1academicbachelor` varchar(100) NOT NULL default '',
  23.   `form1bachelorschool` varchar(100) NOT NULL default '',
  24.   `form1bachelorschoolyear` varchar(100) NOT NULL default '',
  25.   `form1academicMasteral` varchar(100) NOT NULL default '',
  26.   PRIMARY KEY  (`bachelor_id`)
  27. ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
  28.  
  29. -- 
  30. -- Dumping data for table `bachelor`
  31. -- 
  32.  
  33. INSERT INTO `bachelor` VALUES (1, 'swetha', 'Keys High School', '2000', 'BRECW');
  34. INSERT INTO `bachelor` VALUES (2, 'Raj', 'HBSP', '2000', 'PG');
  35.  
dbConnect.php
Expand|Select|Wrap|Line Numbers
  1. <?
  2.     $connection_type = "local";
  3.  
  4.     if ($connection_type == "local")
  5.     {
  6.         $db_servername="localhost";        
  7.         $db_username="root";
  8.         $db_password="";
  9.         $db_name="form";
  10.         $db_link = mysql_connect($db_servername, $db_username, $db_password) or die("could not connect to the local atebase server");
  11.         $db= mysql_select_db($db_name,$db_link) or die("Not a valid database");
  12.  
  13.     }
  14.     ?>
  15.  
function.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.  
  4. class execute_query
  5. {
  6.     //getting the list of categorys
  7.     function get_result_details($select_query)
  8.     {
  9.         require 'dbConnect.php';
  10.         $results=array();
  11.         $select_query_result=mysql_query($select_query,$db_link) or die(" Not a valid Select Query Category ".mysql_error());
  12.         if(mysql_num_rows($select_query_result) > 0)
  13.         {
  14.             while($get_details=mysql_fetch_array($select_query_result))
  15.             {
  16.                 $array_count=count($get_details)/2;
  17.                 for($i=0;$i<$array_count;$i++)
  18.                 {    
  19.                     $results[]=$get_details[$i];
  20.                 }
  21.             }
  22.         }
  23.         //To Free the result set
  24.         mysql_free_result($select_query_result);
  25.         //To Close the connection object
  26.         mysql_close($db_link);
  27.         return $results;
  28.     }
  29.  
  30.  
  31.     //Insert Query function ....
  32.     function insert_query($insert_query)
  33.     {
  34.         require 'dbConnect.php';
  35.         $insert_id="";
  36.         $insert_query_result=mysql_query($insert_query,$db_link) or die(" Not a valid Insert Query ".mysql_error());
  37.         $insert_id=mysql_insert_id();
  38.         mysql_close($db_link);
  39.         return $insert_id;
  40.     }
  41.  
  42.  
  43. }
  44. ?>
  45.  
form.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.  
  4. require 'function.php';
  5.  
  6. ?>
  7. <form name='formname' method= post action="insert.php" >
  8. academicbachelor&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=textbox name="form1academicbachelor" value=""><br>
  9. bachelorschool&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=textbox name="form1bachelorschool" value=""><br>
  10. bachelorschoolyear&nbsp;&nbsp;<input type=textbox name="form1bachelorschoolyear" value=""><br>
  11. academicMasteral&nbsp;&nbsp;&nbsp;&nbsp;<input type=textbox name="form1academicMasteral" value="">
  12. <input type="hidden" name="bachelor">
  13. <input type="submit" name="submit" value="submit" >
  14. <?
  15.  
  16. $query="select * from bachelor";
  17.      $obj_query= new execute_query();
  18.      $type_array=$obj_query->get_result_details($query);
  19.  
  20. $array_length=count($type_array);
  21. $form1academicbachelor=array();
  22. $form1bachelorschool=array();
  23. $form1bachelorschoolyear=array();
  24. $form1academicMasteral=array();
  25.  
  26. echo "<table border=1 cellspacing=0 width = 700>
  27.  
  28. <tr bgcolor=dddddd>
  29. <td align=center> <font color=8B0000 size=2><b> Bachelor ID </b> </font></td>
  30. <td align=center> <font color=8B0000 size=2><b> Bachelor Name </b> </font></td>
  31. <td align=center> <font color=8B0000 size=2><b> School Name </b> </font></td>
  32. <td align=center> <font color=8B0000 size=2><b> School Year </b> </font></td>
  33. <td align=center> <font color=8B0000 size=2><b> Bachelor Masteral </b> </font></td>
  34. </td>
  35. ";
  36.  
  37. for($i=0;$i<$array_length;$i++)
  38. {
  39. echo' <tr>
  40. <td align=center> '.$type_array[$i].' </td>
  41. <td align=center> '.$type_array[$i+1].' </td>
  42. <td align=center> '.$type_array[$i+2].' </td>
  43. <td align=center> '.$type_array[$i+3].' </td>
  44. <td align=center> '.$type_array[$i+4].' </td>
  45.  
  46. </tr>';
  47. $i=$i+4;
  48. }
  49.  
  50. echo "</table>";
  51.  
  52. ?>
  53.  
insert.php
Expand|Select|Wrap|Line Numbers
  1. <?
  2.  
  3. include 'settings.php';
  4. require 'function.php';
  5. $obj_query= new execute_query();
  6. $form1academicbachelor=$_POST['form1academicbachelor'];
  7.   $form1bachelorschool=$_POST['form1bachelorschool'];
  8. $form1bachelorschoolyear=$_POST['form1bachelorschoolyear'];
  9. $form1academicMasteral=$_POST['form1academicMasteral'];
  10.  $insert="insert into bachelor (form1academicbachelor,form1bachelorschool,form1bachelorschoolyear,form1academicMasteral) values ('$form1academicbachelor','$form1bachelorschool','$form1bachelorschoolyear','$form1academicMasteral')";
  11. $insert_value= $obj_query->insert_query($insert);
  12.  
  13. header("Location:form.php");
  14. exit;
  15. ?>
  16.  
output:-
Expand|Select|Wrap|Line Numbers
  1. Bachelor ID  Bachelor Name  School Name  School Year  Bachelor Masteral  
  2. 1                        swetha     Keys High School        2000              BRECW  
  3. 2                            Raj            HBSP                   2000                  PG  
  4.  
Check it out....
Newbie
 
Join Date: Jan 2008
Posts: 14
#4: Jan 19 '08

re: have a problem in arrays that having multiple forms


Quote:

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..
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,758
#5: Jan 19 '08

re: have a problem in arrays that having multiple forms


Hi annerhexian and enumula.

Please use [code] tags when posting your code examples. (See How to ask a question)

[code=php] ...PHP code goes here... [/code]

Thank you.
Moderator
Newbie
 
Join Date: Apr 2007
Posts: 7
#6: Jan 21 '08

re: have a problem in arrays that having multiple forms


Quote:

Originally Posted by Atli

Hi annerhexian and enumula.

Please use [code] tags when posting your code examples. (See How to ask a question)

[code=php] ...PHP code goes here... [/code]

Thank you.

Moderator


Thanku ....
Ill may sure to it frm next time.:-)
Newbie
 
Join Date: Jan 2008
Posts: 14
#7: Jan 31 '08

re: have a problem in arrays that having multiple forms


Quote:

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
Reply