Обсуждение: [newbie] simple browse / edit form in PHP
hi everyone, i have a test setup with postgresql 7.2, PHP 4, and apache. everything works fine, PHP generates HTML pages with query results in it. now i want to create a simple form which shows the current record, and has these buttons: - previous, first, next, last record - delete record - add record it sounds very simple, but where do i start? i guess i should make a stateless connection (the form will be accessed via the web). i figure i need some sort of recordset, is a CURSOR the right approach? maybe someone can point me to an example? TIA -- Jules.
Hi,
>i have a test setup with postgresql 7.2, PHP 4, and apache. everything
>works fine, PHP generates HTML pages with query results in it. now i
>want to create a simple form which shows the current record, and has
>these buttons:
>
>- previous, first, next, last record
>- delete record
>- add record
>
>it sounds very simple, but where do i start? i guess i should make a
>stateless connection (the form will be accessed via the web). i figure
>i need some sort of recordset, is a CURSOR the right approach? maybe
>someone can point me to an example?
For the previous / next buttons, I use 'LIMIT / OFFSET' with the queries.
For example to show 10 records each page,
on the first page:
query = SELECT ..... LIMIT 10 OFFSET 0
the second page:
query = SELECT ..... LIMIT 10 OFFSET 10
etc
For adding or deleting a record, you'll have to do up a form of some type
to get the data.
I'll leave the practicalities to you :)
-----------------
Chris Smith
http://www.squiz.net/
HI--
{ echo "<i>$artist[$count]</i><br>"; }
// $artist is a list of ten (10) artist's names.
{ //Trying to assign the value of $c1, $c2, $c3, etc. using the value of the variable $count.
//But so far, it only processes the value of $count alone, and it ignores $c
//The line below should read like this: $c1 = $artist[0], next line: $c2 = $artist[1], etc.
$c . $count+1 = $artist[$count];
}
Help!!!
- I have the following variables: $c1 thru $c10.
- I also have a FOR loop like this:
{ echo "<i>$artist[$count]</i><br>"; }
// $artist is a list of ten (10) artist's names.
- What I'm trying to do is something like this: Combine the variables with the info inside the FOR loop:
{ //Trying to assign the value of $c1, $c2, $c3, etc. using the value of the variable $count.
//But so far, it only processes the value of $count alone, and it ignores $c
//The line below should read like this: $c1 = $artist[0], next line: $c2 = $artist[1], etc.
$c . $count+1 = $artist[$count];
}
Help!!!
Julio Cuz, Jr.
Riverside Community College
jcuz@rccd.cc.ca.us
Hi the Community,
A good exemple, it's always better that a long...
You must use the eval fonction. (www.php.net)
<?
$artist[]="Areski1";
$artist[]="Areski2";
$artist[]="Areski3";
$artist[]="Areski4";
$artist[]="Areski1";
$artist[]="Areski2";
$artist[]="Areski3";
$artist[]="Areski4";
$c0="Kiki1";
$c1="Kiki2";
$c2="Kiki3";
$c3="Kiki4";
$c1="Kiki2";
$c2="Kiki3";
$c3="Kiki4";
for($count = 0; $count < sizeof($artist); $count++)
{
eval( "echo \$c$count.\"<br>\";" ); //just to see no important
eval( "\$c$count = \"$artist[$count]\";" );
eval( "echo \"-->\".\$c$count.\"<br><br>\";" );//just to see no important
}
?>
{
eval( "echo \$c$count.\"<br>\";" ); //just to see no important
eval( "\$c$count = \"$artist[$count]\";" );
eval( "echo \"-->\".\$c$count.\"<br><br>\";" );//just to see no important
}
?>
I have the following variables: $c1 thru $c10.for($count = 0; $count < sizeof($artist); $count++)
- I also have a FOR loop like this:
{ echo "<i>$artist[$count]</i><br>"; }
// $artist is a list of ten (10) artist's names.for($count = 0; $count < sizeof($artist); $count++)
- What I'm trying to do is something like this: Combine the variables with the info inside the FOR loop:
{ //Trying to assign the value of $c1, $c2, $c3, etc. using the value of the variable $count.
//But so far, it only processes the value of $count alone, and it ignores $c
//The line below should read like this: $c1 = $artist[0], next line: $c2 = $artist[1], etc.
$c . $count+1 = $artist[$count];
}
Help!!!Julio Cuz, Jr.
Riverside Community College
jcuz@rccd.cc.ca.us
Hi Julio,
I have 4 suggestions:
i. Perform the sizeof() operation once and outside
the loop. This will save you some cpu cycles. Also,
if you know for sure that sizeof($artist) is unlikely
to change, set it as a constant.
ii. Create the $c.x string prior to assigning a value
to the variable it represents.
eg.
$artist_size=sizeof($artist);
for($count = 0; $count<$artist_size; $count++)
$varname = "c".($count+1); //
${$varname} = $artist[$count];
}
echo $c1.$c2.$c10;
iii. Go here for more notes on how to create variable variables:
http://www.php.net/manual/en/language.variables.variable.php
iv. Have lots of fun.
cheers!
Kwab
Julio Cuz, Jr. <jcuz@rccd.cc.ca.us> [2002.04.25.1757 +0200]:
> HI--
>
> * I have the following variables: $c1 thru $c10.
>
> * I also have a FOR loop like this:
>
> for($count = 0; $count < sizeof($artist); $count++)
> { echo "<i>$artist[$count]</i><br>"; }
> // $artist is a list of ten (10) artist's names.
>
> * What I'm trying to do is something like this: Combine the variables with
> the info inside the FOR loop:
>
> for($count = 0; $count < sizeof($artist); $count++)
> { //Trying to assign the value of $c1, $c2, $c3, etc.
> using the value of the variable $count.
> //But so far, it only processes the value of $count
> alone, and it ignores $c
> //The line below should read like this: $c1 = $artist[0],
> next line: $c2 = $artist[1], etc.
> $c . $count+1 = $artist[$count];
> }
>
> Help!!!
>
> Julio Cuz, Jr.
> Riverside Community College
> jcuz@rccd.cc.ca.us
-------------------------------
Kwabena Adowah Adu - Consultant
Lucid Tech Solutions, LLC
P.O. Box 135
Wallingford, PA 19086
Tel : 610.583.2737 | 484.444.0788
kwab@lucidtechsolutions.com
http://www.lucidtechsolutions.com