473,387 Members | 1,512 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,387 software developers and data experts.

php / mysql / array

My intention;

create 3 pages of code;

Page 1: two questions are asked
a. What is the database name ($dbname)
b. How many tables to create ($tableno)

and passed onto P2 using $_GET

Page 2: creates (using a while loop) the chosen number of txt boxes (given by $tableno) and creates a unique label for each table needed.

passes onto P3

Page 3 creates the tables with no fields. (yet! lol)

Achieved;

done page 1 ok..
page 2 am suffering with,
a. dynamic creation of txt boxes - OK
b. dynamic labelling - NOT OK (ie. table0, table2, etc)
c. passing onto page 3 - NOT OK

anyone help? Here is the code for page 2;

<html>
<body>
<?php
include ('dbop.php');
$dbnamec = $_GET['create'];
$tableno = $_GET['tableno'];
$tables0 = 0;
$name[0] = 0;

$padding = '<font color="#FFFFFF">2</font><body>';

while ($tables <> $tableno)
{
echo '<form action="createtables2.php" target="main" method="get">
<table border="0" width="260">
<tr>
<td height="26">
Table ';
echo '<td height="26" width="102"><input type "text" name="$name[$tables]" /></td></tr></table>';
$tables++;
}
echo '<input type="submit" value="Create"/><BR />';
?>
</body>
</html>


(I was trying to use arrays as you can see!!)

thanks in advance.

using php5, mysql 5 on
vista with apache 2.2 (installed xampp)
Feb 12 '08 #1
8 1844
dlite922
1,584 Expert 1GB
My intention;

create 3 pages of code;

Page 1: two questions are asked
a. What is the database name ($dbname)
b. How many tables to create ($tableno)

and passed onto P2 using $_GET

Page 2: creates (using a while loop) the chosen number of txt boxes (given by $tableno) and creates a unique label for each table needed.

passes onto P3

Page 3 creates the tables with no fields. (yet! lol)

Achieved;

done page 1 ok..
page 2 am suffering with,
a. dynamic creation of txt boxes - OK
b. dynamic labelling - NOT OK (ie. table0, table2, etc)
c. passing onto page 3 - NOT OK

anyone help? Here is the code for page 2;

<html>
<body>
<?php
include ('dbop.php');
$dbnamec = $_GET['create'];
$tableno = $_GET['tableno'];
$tables0 = 0;
$name[0] = 0;

$padding = '<font color="#FFFFFF">2</font><body>';

while ($tables <> $tableno)
{
echo '<form action="createtables2.php" target="main" method="get">
<table border="0" width="260">
<tr>
<td height="26">
Table ';
echo '<td height="26" width="102"><input type "text" name="$name[$tables]" /></td></tr></table>';
$tables++;
}
echo '<input type="submit" value="Create"/><BR />';
?>
</body>
</html>


(I was trying to use arrays as you can see!!)

thanks in advance.

using php5, mysql 5 on
vista with apache 2.2 (installed xampp)

I'm gonna help, only cause this is your homework BUT you've attempted to get something...(as horrible as it is)

[PHP]
<?php

include ('dbop.php');
$dbnamec = $_GET['create'];
$tableno = $_GET['tableno'];
// your good thus far. you got the values from the last page. now display your page header: You don't have to echo it, end the php tag, and start it later...

?>

<form action="YOU_THIRD_PAGE.php" method="POST">
<table border="0" width="260">

<?php

for($i = 0; $i < $tableno; $i++)
{
echo "<td height="26">Table ", $i, "><input type='text' name='tableName[]' /></td>";
}

?>

</tr></table>
<br />
<input type="submit" value="Create"/><br />




[/PHP]

Notice You will have to use POST to make it easier. GET is a bit messier and harder to do. (so i think at this moment)

PHP will automatically create an Array for fields that have double brackers [ ] on their names.

so on the last page you do this

[PHP]
<?php

$tableNamesArray = $_POST['tableName']; // notice no bracket

//to with this array of names as you wish: such as print them.

foreach ($tableNamesArray as $tableName)
{
echo $tableName, "<br />";
}

?>


[/PHP]

Sorry for any misspellings and syntax errors. THis is not tested and written on the fly.

PLEASE WRAP YOUR CODE [PHP] and [/PHP] WHEN POSTING IT TO THIS FORUM.

makes it easier to read for us and you won't get this annoying comment anymore!

good luck
Feb 12 '08 #2
I'm gonna help, only cause this is your homework BUT you've attempted to get something...(as horrible as it is)

[PHP]
<?php

include ('dbop.php');
$dbnamec = $_GET['create'];
$tableno = $_GET['tableno'];
// your good thus far. you got the values from the last page. now display your page header: You don't have to echo it, end the php tag, and start it later...

?>

<form action="YOU_THIRD_PAGE.php" method="POST">
<table border="0" width="260">

<?php

for($i = 0; $i < $tableno; $i++)
{
echo "<td height="26">Table ", $i, "><input type='text' name='tableName[]' /></td>";
}

?>

</tr></table>
<br />
<input type="submit" value="Create"/><br />




[/PHP]

Notice You will have to use POST to make it easier. GET is a bit messier and harder to do. (so i think at this moment)

PHP will automatically create an Array for fields that have double brackers [ ] on their names.

so on the last page you do this

[PHP]
<?php

$tableNamesArray = $_POST['tableName']; // notice no bracket

//to with this array of names as you wish: such as print them.

foreach ($tableNamesArray as $tableName)
{
echo $tableName, "<br />";
}

?>


[/PHP]

Sorry for any misspellings and syntax errors. THis is not tested and written on the fly.

PLEASE WRAP YOUR CODE [PHP] and [/PHP] WHEN POSTING IT TO THIS FORUM.

makes it easier to read for us and you won't get this annoying comment anymore!

good luck

Thanks dlite922 much appreciated and this was (believe it or not) self inflicted homework as I felt it was high time I got to grips with some development work.

page 2 now give me this error; Parse error: syntax error, unexpected T_LNUMBER, expecting ',' or ';' in C:\pathname\createtable.php on line 16

line 16 is;
echo "<td height="26">Table ", $i, "><input type='text' name='tableName[]' /></td>";

I have tried to look this up and I think its due to the fact that the variable inside the array is starting with a number. If that's right, can I pre-determine what the variable starts with?

thanks

John
Feb 13 '08 #3
ronverdonk
4,258 Expert 4TB
Double quotes within a double quoted string for height. Either use single quotes or escape them:[php]
echo "<td height='26'>Table $i><input type='text' name='tableName[]' /></td>";[/php]
Ronald
Feb 13 '08 #4
Markus
6,050 Expert 4TB
The quotes around
td height="26"
need to be escaped with backslashes.
[php]
td height=\"26\"
[/php]

EDIT: Darn you ronver!
Feb 13 '08 #5
ronverdonk
4,258 Expert 4TB
The quotes around

need to be escaped with backslashes.
[php]
td height=\"26\"
[/php]

EDIT: Darn you ronver!
Next time I'll wait until you had your say.

Ronald
Feb 13 '08 #6
Markus
6,050 Expert 4TB
Next time I'll wait until you had your say.

Ronald
Let that be a lesson to all of you!
Feb 13 '08 #7
Hi All,

($i = 0; $i < $tableno; $i++)

just trying to understand this code... is $i just a counter?

John
Feb 14 '08 #8
ronverdonk
4,258 Expert 4TB
Yes. This statement says (simple view):
- at the start of the operation: initialize the counter to 0
- perform this operation as long as the counter is lower than the value in $tableno
- at the end of each opperation increment the counter by 1

Ronald
Feb 14 '08 #9

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

Similar topics

0
by: James | last post by:
Hi, I have the following code: <PRE> <?php $username = "####t"; $password = "####"; $hostname = "####"; mysql_connect($hostname, $username, $password) or die("Unable to connect to
0
by: W i l l | last post by:
I have Apache 2 parsing and serving PHP files just fine on my winXP box, however, when I try to add some mysql database functionality I get a warning that looks like this: Fatal error: Call to...
0
by: Phil Powell | last post by:
The table already has a fulltext index and from there I can use the MySQL fulltext search query to get results as well as the relevancy score. The problem I have is that MySQL has a default...
9
by: Börni | last post by:
Hi, I have an sql query like this: SELECT column FROM table WHERE column1="3" AND column2="1" This query works perfectly if i run it in the command line, to be exactly it return two results. But...
10
by: John Smith | last post by:
I know that uploading an image to a database has been covered, oh, about 3 trillion times. However, I haven't found anything covering uploading to a MySQL database with .net. Please don't...
5
by: strawberry | last post by:
In the function below, I'd like to extend the scope of the $table variable such that, once assigned it would become available to other parts of the function. I thought 'global $table;' would solve...
6
by: bill | last post by:
I am about to start on a module that will accept a location from a user, use Google geolocation services to get the lat/lon and then compute the distance from the site visitor to about 100 kennels...
5
by: Marijn | last post by:
Hello everybody, I am new to PHP and working on extending my knowledge of OOP. The posts in this group concerned with whether or not to use an OO approach when programming in PHP is not what I...
3
by: ist | last post by:
Hi, I am trying to get (and transfer over ASP.NET) some encrypted data from some MySQL fields. Since the data contains many unicode characters, I tried to get the data as a series of ASCII...
11
by: rich | last post by:
I'm having a tough time figuring out which of these two options are best. This is a matter of processing my data in PHP, vs MySQL. Usually that's a no brainer, but I have a couple gotchyas here...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.