473,395 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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:
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..
Jan 13 '08 #1
6 1354
dlite922
1,584 Expert 1GB
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.
Jan 17 '08 #2
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....
Jan 18 '08 #3
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..
Jan 19 '08 #4
Atli
5,058 Expert 4TB
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
Jan 19 '08 #5
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.:-)
Jan 21 '08 #6
Thanku ....
Ill may sure to it frm next time.:-)

THANK U for helping and teh tips my frienD..god Bless always
Jan 31 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: claudel | last post by:
Hi I have a newb PHP/Javascript question regarding checkbox processing I'm not sure which area it falls into so I crossposted to comp.lang.php and comp.lang.javascript. I'm trying to...
0
by: Carolyn | last post by:
I am having a problem with a multiple forms database that has drop down bars on the main form. The dropdown populates fields on the form based on the Record ID chosen. As soon as I go to one of...
9
by: TD | last post by:
I am trying to add transactions to my code. The original code worked fine until I followed an example to setup transactions, now the code does strange things, but no error messages. Could...
15
by: Paul Morrison | last post by:
Hi all, I need to come up with some differences between arrays in Java and C, I have searched Google and so far all I have found is the following: Arrays in Java are reference types with...
39
by: Marcin Zmyslowski | last post by:
Hello all! I have the following problem with MS Access 2003 permissions. I have two users. One is admin and the second one is user who has full permissions to enter modify and read data. I...
14
by: Mac via DotNetMonster.com | last post by:
Hi all, As some of you would know from my previous posts that I am rewriting our Unix based system into .Net with a MDI interface. Recently I have added a tab control to the top of the MDI...
3
by: imrantbd | last post by:
I need array type name like "destList" must use for my destlist select box,not a single name.Or need a solution to capture multiple value of "destList" select box and send all selected value in php...
9
by: cendrizzi | last post by:
Hi all, I've read some stuff on this but can't seem to come up with a solution that works right. I have a semi-mature (yet very large and robust) internal web application that currently only...
19
by: zzw8206262001 | last post by:
Hi,I find a way to make javescript more like c++ or pyhon There is the sample code: function Father(self) //every contructor may have "self" argument { self=self?self:this; ...
14
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using VS2005 and .net 2.0. I'm creating an application that has 3 forms. I want allow users to move forward and backward with the forms and retain the data users have entered. I thought...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.