RE: [PHP-DB] Passing contents of array on as variables...
| From: | Beau Lebens | Date: | Tue, 26 Feb 2002 02:08:11 +0000 |
| Subject: | RE: [PHP-DB] Passing contents of array on as variables... | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-17290@lists.php.net to get a copy of this message | ||
rather than all the hidden fields and stuff you guys are trying to do - why
not just build the array variable you want, then save it into a session, on
the next page, access the session variable and wallah - there's your array,
still in tact and just as you left it (ie. containing all the info you want,
not the word "Array")
HTH
beua
// -----Original Message-----
// From: jas [mailto:jlgerfen@hotmail.com]
// Sent: Monday, 25 February 2002 5:50 PM
// To: php-db@lists.php.net
// Subject: Re: [PHP-DB] Passing contents of array on as variables...
//
//
// Bjorn,
// I just wanted to thank you for giving me alot of insight
// into what I was
// trying to accomplish however, due to time restraints I have
// decided to do it
// a different way by pulling the entries into a select box
// that a customer can
// use to delete the different items. Once again, thanks a ton!!!!
// Jas
//
// "Jas" <jlgerfen@hotmail.com> wrote in message
// news:20020225200728.92698.qmail@pb1.pair.com...
// > Ok, I think I understand what you are talking about. So
// now I know what I
// > need to accomplish, and would you happen to know of a good
// place to learn
// > about something like this? For some reason this function
// keeps seeming to
// > elude me and if you know of a good tutorial on how to
// accomplish this I
// > would appreciate it. Thanks again,
// > Jas
// > <biorn@ebmstpa.com> wrote in message
// > news:200202251959.MAA25729@www2.ebmstpa.com...
// > > One problem I see is that you are sending all of the
// values for all of
// > your
// > > fields (except the id field) from the first page to the
// second page, not
// > just
// > > the ones that are checked, so even if it was working
// properly, you would
// > get
// > > a list of all items in the table, not just the checked
// items. You need
// to
// > > send the array of id's (since this is the name for the
// checkbox) from
// the
// > > first page to the second one (again in the checkbox form
// element, you
// did
// > not
// > > put a value on it).
// > >
// > > What your first page is currently doing is pulling all of the
// information
// > out
// > > of the database. Then as soon as you pull each item out, you are
// putting
// > it
// > > into an hidden form element array, ie. $car_type[],
// $car_model[], etc.
// > > regardless of whether the checkbox is checked or not to
// pass to the next
// > > page. You do not know if the checkbox is checked or not
// until the next
// > page
// > > when it looks at the values in the id array. On the
// second page, you
// need
// > to
// > > look at the id array and then (through a database call)
// pull the row
// from
// > the
// > > table for each id in the array.
// > >
// > > HTH
// > >
// > > MB
// > >
// > > jas <jlgerfen@hotmail.com> said:
// > >
// > > > $i=0;
// > > > while
// > > >
// ($car_type[$i],$car_model[$i],$car_year[$i],$car_price[$i],$c
// ar_vin[$i])
// > {
// > > > $i ++;
// > > > }
// > > > Is what I added and this is what is being output to
// the screen at this
// > > > point...
// > > > =0; while (,,,,) { ++; }
// > > > now i am still too new to php to understand why it is
// not putting the
// > > > contents of the array into my hidden fields like it
// does on my first
// > page (i
// > > > can see them when I view source).
// > > > <biorn@ebmstpa.com> wrote in message
// > > > news:200202251923.MAA24645@www2.ebmstpa.com...
// > > > > When you call your $car_type in the second page, you
// need to set a
// > > > variable
// > > > > starting at 0 and call it as $car_type[0] and loop
// through all of
// the
// > > > values
// > > > > in the array.
// > > > >
// > > > > ie.
// > > > >
// > > > > $i=0;
// > > > > while ($car_type[$i]) {
// > > > >
// > > > > I have added more code below that should help.
// > > > >
// > > > > MB
// > > > >
// > > > >
// > > > > jas <jlgerfen@hotmail.com> said:
// > > > >
// > > > > > Yeah, tried that and it still isnt passing the
// contents of the
// array
// > as
// > > > a
// > > > > > varible to the confirmation page for deletion. I
// am at a loss on
// > this
// > > > one.
// > > > > > <biorn@ebmstpa.com> wrote in message
// > > > > > news:200202251827.LAA23043@www2.ebmstpa.com...
// > > > > > > You didn't add the value part of the hidden element, ie.
// > > > > > >
// > > > > > > <INPUT TYPE=\"hidden\" NAME=\"car_type\"
// > value=\"$myrow[car_type]\">
// > > > > > >
// > > > > > > You were naming the field as an array with no value.
// > > > > > >
// > > > > > > if you want to pass this as an array of values,
// you would need
// to
// > use:
// > > > > > >
// > > > > > > <INPUT TYPE=\"hidden\" NAME=\"car_type[]\"
// > value=\"$myrow[car_type]\">
// > > > > > >
// > > > > > > Give that a try and see if it works.
// > > > > > >
// > > > > > > HTH
// > > > > > >
// > > > > > > MB
// > > > > > >
// > > > > > >
// > > > > > > jas <jlgerfen@hotmail.com> said:
// > > > > > >
// > > > > > > > As of right now if you run the php script and
// view source on
// the
// > > > page
// > > > > > you
// > > > > > > > can see that it does place the content of db table into
// array...
// > ex.
// > > > > > > > <B>Current Inventory</B></font><hr
// color="333333"></td></tr>
// > > > > > > > <INPUT TYPE="hidden"
NAME="car_type[Ford]">
// > > > > > > > <INPUT TYPE="hidden"
NAME="car_model[Ranger]">
// > > > > > > > <INPUT TYPE="hidden"
NAME="car_year[1999]">
// > > > > > > > <INPUT TYPE="hidden"
NAME="car_price[5600]">
// > > > > > > > <INPUT TYPE="hidden" NAME="car_vin[no
vin]">
// > > > > > > > <tr><td width="30%"><B>Type Of
Car:
// > </B></td><td>Ford</td><td><input
// > > > > > > > type="checkbox"
name="id[1]">remove</td></tr>
// > > > > > > > but on the following page (after selecting
// items to delete) it
// > just
// > > > > > displays
// > > > > > > > the word array for each field (i.e. car_type etc.)
// > > > > > > >
// > > > > > > > "Jas" <jlgerfen@hotmail.com> wrote in message
// > > > > > > > news:20020225180612.7245.qmail@pb1.pair.com...
// > > > > > > > > Oops... yeah its a monday.
// > > > > > > > > Bjorn, I reverted back to my original code
// because I was
// > getting
// > > > > > > > confused...
// > > > > > > > > Here is page one...
// > > > > > > > > <?php
// > > > > > > > > // Database connection paramaters
// > > > > > > > > require '../path/to/db.php';
// > > > > > > > > // SQL statement to get current inventory
// > > > > > > > > $result = @mysql_query("SELECT * FROM
// cur_inv",$dbh) or
// > die("Could
// > > > not
// > > > > > > > > execute query, please try again later");
// > > > > > > > > // Creating table to make data look pretty
// > > > > > > > > echo "<table border=\"0\"
class=\"table-body\"
// > > > width=\"100%\"><form
// > > > > > > > > name=\"rem_inv\" method=\"post\"
// action=\"rem_conf.php3\">
// > > > > > > > > <tr><td align=\"center\"
colspan=\"3\"><font
// > size=\"4\"><B>Current
// > > > > > > > > Inventory</B></font><hr
color=\"333333\"></td></tr>";
// > > > > > > > > // Start to count number of records in
// selected table and
// loop
// > > > until
// > > > > > done
// > > > > > > > > $count = -1;
// > > > > > > > > while ($myrow = mysql_fetch_array($result)) {
// > > > > > > > > $count ++;
// > > > > > > > > // Begin placing them into an hidden fields
// and then array
// > > > > > > > > echo "
// > > > > > > > > <INPUT TYPE=\"hidden\"
// > NAME=\"car_type[".$myrow[car_type]."]\">
// > > > > > > > > <INPUT TYPE=\"hidden\"
// > NAME=\"car_model[".$myrow[car_model]."]\">
// > > > > > > > > <INPUT TYPE=\"hidden\"
// > NAME=\"car_year[".$myrow[car_year]."]\">
// > > > > > > > > <INPUT TYPE=\"hidden\"
// > NAME=\"car_price[".$myrow[car_price]."]\">
// > > > > > > > > <INPUT TYPE=\"hidden\"
// NAME=\"car_vin[".$myrow[car_vin]."]\">
// > > > > > > > > // Place items on separate cells in html table
// > > > > > > > > <tr><td width=\"30%\"><B>Type
Of Car: </B></td><td>";
// > > > > > > > >
printf(mysql_result($result,$count,"car_type"));
// > > > > > > > > // Create checkbox so user can delete items if needed
// > > > > > > > > echo "</td><td><input
type=\"checkbox\"
// > > > > > > > >
name=\"id[".$myrow[id]."]\">remove</td></tr>\n";
// > > > > > > > > echo "<tr><td
width=\"30%\"><B>Model Of Car:
// </B></td><td>";
// > > > > > > > >
printf(mysql_result($result,$count,"car_model"));
// > > > > > > > > echo "</td></tr>\n";
// > > > > > > > > echo "<tr><td
width=\"30%\"><B>Year Of Car:
// </B></td><td>";
// > > > > > > > >
printf(mysql_result($result,$count,"car_year"));
// > > > > > > > > echo "</td></tr>\n";
// > > > > > > > > echo "<tr><td
width=\"30%\"><B>Price Of Car:
// </B></td><td>$";
// > > > > > > > >
printf(mysql_result($result,$count,"car_price"));
// > > > > > > > > echo "</td></tr>\n";
// > > > > > > > > echo "<tr><td
width=\"30%\"><B>VIN Of Car:
// </B></td><td>";
// > > > > > > > > printf(mysql_result($result,$count,"car_vin"));
// > > > > > > > > echo "</td></tr><tr><td
colspan=\"3\"><hr
// > > > > > color=\"333333\"></td></tr>\n";
// > > > > > > > > }
// > > > > > > > > // End loop and print the infamous delete button
// > > > > > > > > echo "<tr><td><input
type=\"submit\" name=\"delete\"
// > > > > > > > >
value=\"delete\"></td></tr></form></table>";
// > > > > > > > > ?>
// > > > > > > > > Here is page two...
// > > > > > > > > <?php
// > > > > > > > > print("
// > > > > > > > > <table border=\"0\"
class=\"table-body\"
// width=\"100%\">
// > > > > > > > > <form name=\"rem_inv\"
method=\"post\"
// action=\"done2.php3\">
// > > > > > > > > <INPUT TYPE=\"hidden\"
// > NAME=\"car_type[".$myrow[car_type]."]\">
// > > > > > > > > <INPUT TYPE=\"hidden\"
// > NAME=\"car_model[".$myrow[car_model]."]\">
// > > > > > > > > <INPUT TYPE=\"hidden\"
// > NAME=\"car_year[".$myrow[car_year]."]\">
// > > > > > > > > <INPUT TYPE=\"hidden\"
// > NAME=\"car_price[".$myrow[car_price]."]\">
// > > > > > > > > <INPUT TYPE=\"hidden\"
// NAME=\"car_vin[".$myrow[car_vin]."]\">
// > > > > > > > > <tr>
// > > > > > > > > <td align=\"center\"
colspan=\"3\"><font
// > size=\"4\"><B>Confirm
// > > > > > Record
// > > > > > > > > Deletion</B></font><hr
color=\"333333\"></td>
// > > > > > > > > </tr>
// > > > >
// > > > > Here is where above loop code would go and
// $car_type, $car_model,
// etc.
// > > > would
// > > > > be called as $car_type[$i], $car_model[$i], etc.
// > > > >
// > > > >
// > > > > > > > > <tr>
// > > > > > > > > <td width=\"30%\"><B>Type Of
Car: </B></td>
// > > > > > > > > <td>$car_type</td> // here is where it
// prints the word
// > "array"
// > > > > > instead of
// > > > > > > > > type of car
// > > > > > > > > </tr>
// > > > > > > > > <tr>
// > > > > > > > > <td width=\"30%\"><B>Model Of
Car: </B></td>
// > > > > > > > > <td>$car_model</td>
// > > > > > > > > </tr>
// > > > > > > > > <tr>
// > > > > > > > > <td width=\"30%\"><B>Year Of
Car: </B></td>
// > > > > > > > > <td>$car_year</td>
// > > > > > > > > </tr>
// > > > > > > > > <tr>
// > > > > > > > > <td width=\"30%\"><B>Price Of
Car: </B></td>
// > > > > > > > > <td>$car_price</td>
// > > > > > > > > </tr>
// > > > > > > > > <tr>
// > > > > > > > > <td width=\"30%\"><B>VIN Of
Car: </B></td>
// > > > > > > > > <td>$car_vin</td>
// > > > > > > > > </tr>
// > > > >
// > > > > increment $i and
// > > > > end loop
// > > > >
// > > > >
// > > > > > > > > <tr>
// > > > > > > > > <td colspan=\"3\"><hr
color=\"333333\"></td>
// > > > > > > > > </tr>
// > > > > > > > > <tr>
// > > > > > > > > <td><input type=\"submit\"
name=\"delete\"
// > > > value=\"delete\"></td>
// > > > > > > > > </tr>
// > > > > > > > > </form>
// > > > > > > > > </table>");
// > > > > > > > > ?>
// > > > > > > > >
// > > > > > > > > <biorn@ebmstpa.com> wrote in message
// > > > > > > > > news:200202251800.LAA22108@www2.ebmstpa.com...
// > > > > > > > > > Let's see what your code looks like now
// and where it is
// > > > returning
// > > > > > the
// > > > > > > > > > word "array". That might help determine
// where the problem
// > lies
// > > > now.
// > > > > > > > > >
// > > > > > > > > > MB
// > > > > > > > > >
// > > > > > > > > > jas <jlgerfen@hotmail.com> said:
// > > > > > > > > >
// > > > > > > > > > > Ok to this point I have been able to
// query a database
// > table,
// > > > > > display
// > > > > > > > the
// > > > > > > > > > > results in tables and within a form. As
// of yet I have
// > been
// > > > able
// > > > > > to
// > > > > > > > > insert
// > > > > > > > > > > the contents of the db query into an
// array for further
// > > > processing.
// > > > > > > > > However,
// > > > > > > > > > > when I try to pass the contents of that
// array on to
// > another
// > > > page
// > > > > > to
// > > > > > > > > delete
// > > > > > > > > > > selected records from the db it only
// displays the word
// > > > "array".
// > > > > > Not
// > > > > > > > > quite
// > > > > > > > > > > sure where I need to go from here... Any
// insight would
// be
// > a
// > > > great
// > > > > > > > help.
// > > > > > > > > > > Thanks in advance,
// > > > > > > > > > > Jas
// > > > > > > > > > >
// > > > > > > > > > >
// > > > > > > > > > >
// > > > > > > > > > > --
// > > > > > > > > > > PHP Database Mailing List (http://www.php.net/)
// > > > > > > > > > > To unsubscribe, visit:
// http://www.php.net/unsub.php
// > > > > > > > > > >
// > > > > > > > > >
// > > > > > > > > >
// > > > > > > > > >
// > > > > > > > > > --
// > > > > > > > > >
// > > > > > > > > >
// > > > > > > > > >
// > > > > > > > >
// > > > > > > > >
// > > > > > > >
// > > > > > > >
// > > > > > > >
// > > > > > > > --
// > > > > > > > PHP Database Mailing List (http://www.php.net/)
// > > > > > > > To unsubscribe, visit: http://www.php.net/unsub.php
// > > > > > > >
// > > > > > >
// > > > > > >
// > > > > > >
// > > > > > > --
// > > > > > >
// > > > > > >
// > > > > > >
// > > > > >
// > > > > >
// > > > > >
// > > > > > --
// > > > > > PHP Database Mailing List (http://www.php.net/)
// > > > > > To unsubscribe, visit: http://www.php.net/unsub.php
// > > > > >
// > > > >
// > > > >
// > > > >
// > > > > --
// > > > >
// > > > >
// > > > >
// > > >
// > > >
// > > >
// > > > --
// > > > PHP Database Mailing List (http://www.php.net/)
// > > > To unsubscribe, visit: http://www.php.net/unsub.php
// > > >
// > >
// > >
// > >
// > > --
// > >
// > >
// > >
// >
// >
//
//
//
// --
// PHP Database Mailing List (http://www.php.net/)
// To unsubscribe, visit: http://www.php.net/unsub.php
//