Jump to content

Please help me


alphaalu

Recommended Posts

I am trying to pass a session variable from one script to another script.In a while loop i assigned value to the session variable and in the second script it shows only the last value assigned.

 

Code Snippet

 

Script1............

 

<?php

session_start();?>

<?php require_once('Connections/con1.php'); ?>

.

....

<?php do {

$_SESSION['var1'] =$row_rs['id'];

//echo $_SESSION['var1'];

?>

  <tr>

    <td height="104"><?php echo $_SESSION['var1']; //echo $row_rs['id']; 

?></td>

    <td><?php echo $row_rs['title']; ?></td>

    <td><img src="picscript1.php?" width="100" height="100" alt="" /></td>

  </tr>

  <?php

  } while ($row_rs = mysql_fetch_assoc($rs)); ?>

</table>

  <p> </p>

  <p> </p>

</form>

 

picscript1.php

 

 

 

<?php

session_start();

mysql_connect("localhost","root","vertrigo");

mysql_select_db("pix");

$im1=$_SESSION['var1'];

$rs = mysql_query("select imgdata from image where id=$im1");

$row = mysql_fetch_assoc($rs);

$imagebytes = $row[imgdata];

header("Content-type: image/jpeg");

print $row[imgdata];

//print $imagebytes;

session_destroy();

?>

 

In output id and title will be displayed properly,

i think the pblm is in the session variable, in the picscript1.php the session variable gets only last value.

Please help meeeeeee

 

 

Link to comment
https://forums.phpfreaks.com/topic/205738-please-help-me/
Share on other sites

I think this is working as it should.. just not as you want. You are rewriting to the same variable I think.

 

Use an array then send the array to the session variable.

$_SESSION['vars1']=$my_array;

 

Then treat the $_SESSION['vars1'] in the your other script as an array. See if that helps.

Link to comment
https://forums.phpfreaks.com/topic/205738-please-help-me/#findComment-1076598
Share on other sites

thanks

 

i want print images from the pix table.i cant print text and images in a single script.

in the first script it will print the image id and title, and the second script is used to print the images.

pix table contains 3 fields id (integer),title(varchar),&imgdata(blob).

Link to comment
https://forums.phpfreaks.com/topic/205738-please-help-me/#findComment-1076605
Share on other sites

Ah ok. Did you try sending an array of the variables instead?

 

<?php 
$count = 0;
$my_array = array();
do {
   $my_array[$count] =$row_rs['id'];
   //echo $_SESSION['var1'];
   ?>
  <tr>
    <td height="104"><?php echo $my_array[$count]; //echo $row_rs['id']; 
   ?></td>
    <td><?php echo $row_rs['title']; ?></td>
    <td><img src="picscript1.php?" width="100" height="100" alt="" /></td>
  </tr>
   <?php
$count = $count + 1;
  } while ($row_rs = mysql_fetch_assoc($rs)); 
$_SESSION['var1']=$my_array;
?>

 

Then on the other end remeber to loop through the $_SESSIONS['var1'] as an array for the values.... foreach or do a count on the array for other loops to determine number of times to loop.

Link to comment
https://forums.phpfreaks.com/topic/205738-please-help-me/#findComment-1076667
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.