p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Passing variables from record to newpage?


Message #1 by Jefferis Peterson <jefferis@p...> on Wed, 25 Sep 2002 15:45:11 -0400
I've created a page that opens a catalog of item descriptions and thumbnail
images in a repeating table from a MySql db. I've created a link to open
larger versions of the picture for each item and I've even created a popup
to display it with javascript enclosures, but it creates a page with white
background and an uncentered image.  Now what I want to do is create a
default php page that takes the item name and number and displays the
picture in a new centered page, centered image based upon the image size.

I think I can handle most of this, but I'm not sure how to pass the
variables from a single record in a repeating table to the new page. This
page produces a repeating table with ten records per page. How do I assure
that the variables from the current record are the ones being passed to a
new page?

Jeff 

> <?php do { ?>
> </MM:DECORATION></MM_REPEATEDREGION><MM_REPEATEDREGION SOURCE="
> "></MM_REPEATEDREGION></font></font><font face="Skia, Tahoma, Trebuchet MS,
> Albertus Medium"><font size="-1"></font></font></div>
> <font face="Skia, Tahoma, Trebuchet MS, Albertus Medium"><font
> size="-1"><MM_REPEATEDREGION SOURCE=" "><MM:DECORATION OUTLINE="Repeat"
> OUTLINEID=1> 
> </MM:DECORATION></MM_REPEATEDREGION></font></font>
> <div align="center"><font size="-1"><MM_REPEATEDREGION SOURCE="
> "></MM_REPEATEDREGION></font></div>
> <font size="-1"><MM_REPEATEDREGION SOURCE=" "><MM:DECORATION OUTLINE="Repeat"
> OUTLINEID=1> 
> </MM:DECORATION></MM_REPEATEDREGION>
> <div align="center"><MM_REPEATEDREGION SOURCE=" "></MM_REPEATEDREGION></div>
> <MM_REPEATEDREGION SOURCE=" "><MM:DECORATION OUTLINE="Repeat" OUTLINEID=1>
> </MM:DECORATION></MM_REPEATEDREGION></font>
> <div align="center"><MM_REPEATEDREGION SOURCE=" "></MM_REPEATEDREGION></div>
> <MM_REPEATEDREGION SOURCE=" "><MM:DECORATION OUTLINE="Repeat" OUTLINEID=1>
> <div align="center"><br>
> </div>
> <table width="655" border="0" cellspacing="0" cellpadding="0">
> <tr> 
>   <td width="228" valign="middle">
<?php echo 
> htmlentities($row_yellow['descrip']); ?></strong></font></td>
>   <td width="98" valign="middle"> <div align="center"><font size="-2"
> face="Skia, Tahoma, Trebuchet MS, Albertus Medium"><?php echo
> $row_yellow['class']; ?><br>
>       <?php echo $row_yellow['designer']; ?> </font></div></td>
>   <td width="64" valign="middle"> <div align="center"><img src=<?php echo
> htmlentities( $row_yellow['thumbnail']); ?>><br>
>       <font size="-2" face="Skia, Tahoma, Trebuchet MS, Albertus Medium"><?php
> echo $row_yellow['item']; ?></font></div></td>
>   <td width="123" valign="middle"> <div align="center"><a href='<?php echo
> $row_yellow['pictures']; ?>' target="_top" >
>       <font size="-2" face="Arial, Helvetica, sans-serif">Larger
> Image</font></a> 
>     </div></td>
~~~~~~~~~~~~
Jefferis Peterson, Pres.
Web Design and Marketing
http://www.PetersonSales.net
Tel .  xxx-xxx-xxxx
ICQ 19112253

http://www.Slippery-Rock.com - 7,000 hits per year

Message #2 by "Nikolai Devereaux" <yomama@u...> on Wed, 25 Sep 2002 14:04:48 -0700
If you can uniquely identify a row in the images table, then just pass those
variables to the new page via the link.  If you don't have a primary key in
your table, then at least each row should, I hope, be unique.


Best case:

echo "<A href=\"showpic.php?pic_id={$pic_id}\"";


Worst case:

$getvars = array();
foreach($image_data as $key => $value)
{
    $getvars[] = $key . '=' . $value;
}

echo "<A href=\"showpic.php?" . join('&', $getvars);


In the "Worst case" example, $image_data would be the data array containing one
row of result data from the images table in the database.  In PHP, this is
expressed as

function get_images()
{
  $query = "SELECT * FROM images";
  $result = db_query($query);
  $rows = array();
  if($result)
  {
     while($row = db_fetch_array($result, DB_ASSOC))
     {
        $rows[] = $row;
     }
  }

  return $rows;
}

$images = get_images();


foreach($images as $image_data)
{
  // $image_data now holds all your db column names and values
  // as indexes in an array.
}


Hope this makes sense!


nik

Message #3 by Jefferis Peterson <jefferis@p...> on Fri, 27 Sep 2002 12:25:50 -0400
 Okay, I'm trying to do something a bit different here, and I'm not sure
this is quite right.

I'm setting up a search query on one page that will return repeating
records. The query is $viewall.
 For each record [all have a unique id called "item" ] I display a
description and a thumbnail picture. On this thumbnail picture, I can call
up a link to a larger picture with this code:

 <a href="<?php echo $row_viewall['pictures']; ?>" target="new"><img
src='<?php echo $row_viewall['thumbnail']; ?>' alt="<?php echo
$row_viewall['item_name']; ?>" border="0"></a>


The problem with this link is that it creates a new page with an uncentered
image with a white background. I want to display this image in a popup
window, somewhat centered with a black background, preferably with no scroll
bar, resizeable, and no tool bar.  I can usually do this with javascript but
I don't wan to use javascript if possible.

Now my first instinct is to create a blank php page with defaults and then
put this variable of the picture into a centered table.  Perhaps there is a
better way, but I guess it would work if on the link, I   can transfer all
current record data to the new page. I'm just not sure how I can accomplish
it, but I suspect it may be easier than I think, if all record data is
already being passed as an environment variable?  Is it?

Jeff



> From: "Nikolai Devereaux" <yomama@u...>
 
> 
> 
> If you can uniquely identify a row in the images table, then just pass those
> variables to the new page via the link.  If you don't have a primary key in
> your table, then at least each row should, I hope, be unique.
> 
> 
> Best case:
> 
> echo "<A href=\"showpic.php?pic_id={$pic_id}\"";
> 
> 
> Worst case:
> 
> $getvars = array();
> foreach($image_data as $key => $value)
> {
>   $getvars[] = $key . '=' . $value;
> }
> 
> echo "<A href=\"showpic.php?" . join('&', $getvars);
> 
> 
> In the "Worst case" example, $image_data would be the data array containing
> one
> row of result data from the images table in the database.  In PHP, this is
> expressed as
> 
> function get_images()
> {
> $query = "SELECT * FROM images";
> $result = db_query($query);
> $rows = array();
> if($result)
> {
>    while($row = db_fetch_array($result, DB_ASSOC))
>    {
>       $rows[] = $row;
>    }
> }
> 
> return $rows;
> }
> 
> $images = get_images();
> 
> 
> foreach($images as $image_data)
> {
> // $image_data now holds all your db column names and values
> // as indexes in an array.
> }
> 
> 
> Hope this makes sense!

~~~~~~~~~~~~
Jefferis Peterson, Pres.
Web Design and Marketing
http://www.PetersonSales.net
Tel .  xxx-xxx-xxxx
ICQ 19112253

http://www.Slippery-Rock.com - 7,000 hits per year

Message #4 by "jorge" <jorge@d...> on Sun, 29 Sep 2002 09:39:04 -0500
Hi Jeff
what you need to do is to create a new window using Javascript use de
window.open() an set all the properties for the new page inside.
window.open("page_to_open.htm","new_window_name",etc... see below self
explanatory)
then you need an event handler to call this function that in this case could
be onCLick
so your new code should be something like this

you can see the code in action here note that the location bar has been
removed.
http://www.propietarismo.com/vision2.0/pedidos_publico.php
click on the "Nuevos Usuarios"button

here is the code place the script in your head section.
<script language="JavaScript">
function abrir()
 {
 var
ventana2=window.open("publico/usuarios/registro_paso1.php","nombre","width=4
50,height=500,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollba
rs=1,resizable=0,copyhistory=0,left=400,top=200");
 ventana2.focus();
// Fin de abrir ventana!-->
 }
</script>

now for a button:
<input type="button" name="Ingresar2" value="Registro" onClick="abrir();" >
now for a link
<a href="#" onClick="abrir();" >My link </a>

Saludos from Mexico

Jorge Cordero



----- Original Message -----
From: "Jefferis Peterson" <jefferis@p...>
To: "beginning php" <beginning_php@p...>
Sent: Friday, September 27, 2002 11:25 AM
Subject: [beginning_php] Re: Passing variables from record to newpage?


> Okay, I'm trying to do something a bit different here, and I'm not sure
> this is quite right.
>
> I'm setting up a search query on one page that will return repeating
> records. The query is $viewall.
>  For each record [all have a unique id called "item" ] I display a
> description and a thumbnail picture. On this thumbnail picture, I can call
> up a link to a larger picture with this code:
>
>  <a href="<?php echo $row_viewall['pictures']; ?>" target="new"><img
> src='<?php echo $row_viewall['thumbnail']; ?>' alt="<?php echo
> $row_viewall['item_name']; ?>" border="0"></a>
>
>
> The problem with this link is that it creates a new page with an
uncentered
> image with a white background. I want to display this image in a popup
> window, somewhat centered with a black background, preferably with no
scroll
> bar, resizeable, and no tool bar.  I can usually do this with javascript
but
> I don't wan to use javascript if possible.
>
> Now my first instinct is to create a blank php page with defaults and then
> put this variable of the picture into a centered table.  Perhaps there is
a
> better way, but I guess it would work if on the link, I   can transfer all
> current record data to the new page. I'm just not sure how I can
accomplish
> it, but I suspect it may be easier than I think, if all record data is
> already being passed as an environment variable?  Is it?
>
> Jeff
>
>
>
> > From: "Nikolai Devereaux" <yomama@u...>
>
> >
> >
> > If you can uniquely identify a row in the images table, then just pass
those
> > variables to the new page via the link.  If you don't have a primary key
in
> > your table, then at least each row should, I hope, be unique.
> >
> >
> > Best case:
> >
> > echo "<A href=\"showpic.php?pic_id={$pic_id}\"";
> >
> >
> > Worst case:
> >
> > $getvars = array();
> > foreach($image_data as $key => $value)
> > {
> >   $getvars[] = $key . '=' . $value;
> > }
> >
> > echo "<A href=\"showpic.php?" . join('&', $getvars);
> >
> >
> > In the "Worst case" example, $image_data would be the data array
containing
> > one
> > row of result data from the images table in the database.  In PHP, this
is
> > expressed as
> >
> > function get_images()
> > {
> > $query = "SELECT * FROM images";
> > $result = db_query($query);
> > $rows = array();
> > if($result)
> > {
> >    while($row = db_fetch_array($result, DB_ASSOC))
> >    {
> >       $rows[] = $row;
> >    }
> > }
> >
> > return $rows;
> > }
> >
> > $images = get_images();
> >
> >
> > foreach($images as $image_data)
> > {
> > // $image_data now holds all your db column names and values
> > // as indexes in an array.
> > }
> >
> >
> > Hope this makes sense!
>
> ~~~~~~~~~~~~
> Jefferis Peterson, Pres.
> Web Design and Marketing
> http://www.PetersonSales.net
> Tel .  xxx-xxx-xxxx
> ICQ 19112253
>
> http://www.Slippery-Rock.com - 7,000 hits per year
>
>


Message #5 by Jefferis Peterson <jefferis@p...> on Mon, 30 Sep 2002 12:06:04 -0400
I tried this Jorge, but the information is not being passed to the page or
creating a popup.


Jeff

On 9/29/02 10:39 AM, "jorge" <jorge@d...> wrote:

> Hi Jeff
> what you need to do is to create a new window using Javascript use de
> window.open() an set all the properties for the new page inside.
> window.open("page_to_open.htm","new_window_name",etc... see below self
> explanatory)
> then you need an event handler to call this function that in this case could
> be onCLick
> so your new code should be something like this
> 
> you can see the code in action here note that the location bar has been
> removed.
> http://www.propietarismo.com/vision2.0/pedidos_publico.php
> click on the "Nuevos Usuarios"button
> 
> here is the code place the script in your head section.
> <script language="JavaScript">
> function abrir()
> {
> var
> ventana2=window.open("publico/usuarios/registro_paso1.php","nombre","width=4
> 50,height=500,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollba
> rs=1,resizable=0,copyhistory=0,left=400,top=200");
> ventana2.focus();
> // Fin de abrir ventana!-->
> }
> </script>
> 
> now for a button:
> <input type="button" name="Ingresar2" value="Registro" onClick="abrir();" >
> now for a link
> <a href="#" onClick="abrir();" >My link </a>
> 
> Saludos from Mexico

~~~~~~~~~~~~
Jefferis Peterson, Pres.
Web Design and Marketing
http://www.PetersonSales.net
Tel .  xxx-xxx-xxxx
ICQ 19112253

http://www.Slippery-Rock.com - 7,000 hits per year


  Return to Index