have a problem in arrays that having multiple forms | Newbie | | Join Date: Jan 2008
Posts: 14
| |
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: -
DATAbase:
-
form1academicbachelor varchar(20) not null,
-
form1bachelorschool varchar(20),
-
form1bachelorschoolyear varchar(20),
-
form1academicMasteral varchar(20) not null,
-
form1masteralschool varchar(20),
-
form1masteralschoolyear varchar(20),
-
-
-
<?php
-
include 'dbConnect.php';
-
mysql_select_db("ranking",$con);
-
-
$form1academicbachelor=array();
-
$form1bachelorschool=array();
-
$form1bachelorschoolyear=array();
-
$form1academicMasteral=array();
-
-
$form1academicbachelor=$_POST['bacheloracadform1'];
-
$form1bachelorschool=$_POST['bachschoolnameform1'];
-
$form1bachelorschoolyear=$_POST['bachyeargraduatedform1'];
-
$form1academicMasteral=$_POST['masteralacademicsform1'];
-
-
$form1academicbachelor=implode(',',$form1academicbachelor);
-
$form1bachelorschool=implode(',',$form1bachelorschool);
-
$form1bachelorschoolyear=implode(',',form1bachelorschoolyear);
-
$form1academicMasteral=implode(',',$form1academicMasteral);
-
-
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> '.$form1academicbachelor.' </td>
-
<td align=center> '.$form1bachelorschool.' </td>
-
<td align=center> '.$form1bachelorschoolyear.' </td>
-
-
<td align=center>
-
-
<span class="style2"><font size=2>
-
-
</font></span>
-
-
</td>
-
</tr>';
-
-
echo "</table>";
-
-
?>
-
ouput: -
===============================================
-
BACHELOR DEGREE | SCHOOL NAME | SCHOOL YEAR
-
===============================================
-
BSIT,BSM,BEED | sc1,sc2,sc3 | yy1,yy2,yy3
-
i want my output that will be like this -
==============================================
-
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 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..
|  | Expert | | Join Date: Dec 2007 Location: Moon, Dark Side
Posts: 1,095
| | | 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
| | | re: have a problem in arrays that having multiple forms
Hi
Here is code...Hope this wud help u... DB file:- -
-- phpMyAdmin SQL Dump
-
-- version 2.6.1
-
-- http://www.phpmyadmin.net
-
--
-
-- 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 -
<?
-
$connection_type = "local";
-
-
if ($connection_type == "local")
-
{
-
$db_servername="localhost";
-
$db_username="root";
-
$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_link) or die("Not a valid database");
-
-
}
-
?>
-
function.php -
<?php
-
-
-
class execute_query
-
{
-
//getting the list of categorys
-
function get_result_details($select_query)
-
{
-
require 'dbConnect.php';
-
$results=array();
-
$select_query_result=mysql_query($select_query,$db_link) or die(" Not a valid Select Query Category ".mysql_error());
-
if(mysql_num_rows($select_query_result) > 0)
-
{
-
while($get_details=mysql_fetch_array($select_query_result))
-
{
-
$array_count=count($get_details)/2;
-
for($i=0;$i<$array_count;$i++)
-
{
-
$results[]=$get_details[$i];
-
}
-
}
-
}
-
//To Free the result set
-
mysql_free_result($select_query_result);
-
//To Close the connection object
-
mysql_close($db_link);
-
return $results;
-
}
-
-
-
//Insert Query function ....
-
function insert_query($insert_query)
-
{
-
require 'dbConnect.php';
-
$insert_id="";
-
$insert_query_result=mysql_query($insert_query,$db_link) or die(" Not a valid Insert Query ".mysql_error());
-
$insert_id=mysql_insert_id();
-
mysql_close($db_link);
-
return $insert_id;
-
}
-
-
-
}
-
?>
-
form.php -
<?php
-
-
-
require 'function.php';
-
-
?>
-
<form name='formname' method= post action="insert.php" >
-
academicbachelor <input type=textbox name="form1academicbachelor" value=""><br>
-
bachelorschool   <input type=textbox name="form1bachelorschool" value=""><br>
-
bachelorschoolyear <input type=textbox name="form1bachelorschoolyear" value=""><br>
-
academicMasteral <input type=textbox name="form1academicMasteral" value="">
-
<input type="hidden" name="bachelor">
-
<input type="submit" name="submit" value="submit" >
-
<?
-
-
$query="select * from bachelor";
-
$obj_query= new execute_query();
-
$type_array=$obj_query->get_result_details($query);
-
-
$array_length=count($type_array);
-
$form1academicbachelor=array();
-
$form1bachelorschool=array();
-
$form1bachelorschoolyear=array();
-
$form1academicMasteral=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<$array_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>";
-
-
?>
-
insert.php -
<?
-
-
include 'settings.php';
-
require 'function.php';
-
$obj_query= new execute_query();
-
$form1academicbachelor=$_POST['form1academicbachelor'];
-
$form1bachelorschool=$_POST['form1bachelorschool'];
-
$form1bachelorschoolyear=$_POST['form1bachelorschoolyear'];
-
$form1academicMasteral=$_POST['form1academicMasteral'];
-
$insert="insert into bachelor (form1academicbachelor,form1bachelorschool,form1bachelorschoolyear,form1academicMasteral) values ('$form1academicbachelor','$form1bachelorschool','$form1bachelorschoolyear','$form1academicMasteral')";
-
$insert_value= $obj_query->insert_query($insert);
-
-
header("Location:form.php");
-
exit;
-
?>
-
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....
| | Newbie | | Join Date: Jan 2008
Posts: 14
| | | 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..
|  | Moderator | | Join Date: Nov 2006 Location: Iceland
Posts: 3,758
| | | 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
| | | 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
| | | 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
|  | | | | Forums
Visit our community forums for general discussions and latest on Bytes
/bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,562 network members.
|