Jump to content

Sessions Help


Lukey

Recommended Posts

I have created a database with a table called houses with various house information as fields.

My search page is working fine and loads up each result in a separate table using a loop:

 

while($newarray = mysqli_fetch_array($result, MYSQLI_ASSOC))
	{
	$rname = $newarray["hname"];
	$rcountry = $newarray["hcountry"];
	$rbeds = $newarray["beds"];
	$rprice = $newarray["hprice"];


	?>
	<table cellspacing="0" cellpadding="4" border="1" width="80%" bgColor="#ccff99" borderColor="#ffcccc">
  <tr><form action="http://localhost/housedetail.php" method="post">




    <!-- Row 1 Column 1 -->
    <td>
    <img src="C:\Documents and Settings\Lukey\Desktop\MAIN PROJECT\<?php echo($rname);?>.jpg">
     
      
      
    </td>
    <!-- Row 1 Column 2 -->
    <td><div align="left">
      <?php 
      echo"<li>$rname</li><br/>";
      echo"<li>$rcountry</li><br/>";
      echo"<li>$rbeds Bedrooms</li><br/>";
      echo"<li><i>£ $rprice</i></li><br/>";
   session_start();
      $_SESSION['housename'] = $rname;
      
      
      
      ?></div>
    </td>
    <!-- Row 1 Column 3 -->
    <td>
    <center><h5>Please Click the Button for futher details</h5><br/>
      <input type="submit" value=" House Details "/></center>
    </td>
  </tr>
  </form>
</table>



	<?php
	echo"<br/>";

	}

 

However i have a button in each result table which links to a php script that loads up a page with further details of the house.

I decided to use SESSIONS to pass the housename to the next script so i can retrive the data and display it BUT i can only start one session at a time and because it loops i get errors on my page:

 

Notice: A session had already been started - ignoring session_start() in C:\Program Files\Apache Group\Apache2\htdocs\housesearch.php on line 210

 

 

Any help would be most appreciated!

Link to comment
Share on other sites

Ummm yeah why would you need more than one session going at a time?

 

Since it's an array you can just use $_SESSION['somevar'] = "something"; $_SESSION['someothervar'] = "Somethineelse"; etcetera.

 

You should be able to safely delete the session_start on line 210 of housesearch.php, but I didn't read your code... so.... lol

Link to comment
Share on other sites

Aha thanks that was a stupid thing to miss however it has given me a different problem in that the only variable it is passing to the next script is the last record of the results and not the correct one clicked :(

 

As you can see in the attached screenshot i am aiming to get the button to pass the correct housename across.

 

[attachment deleted by admin]

Link to comment
Share on other sites

This should work...

 

print $array[0];

 

Depending on how many array's you have, the variable is either 0 - ** where star is being the last one.

 

if you want to use only 0, 3 and 7, then it would be

 

echo $array[0] $array[3] $array[7];

 

Link to comment
Share on other sites

Its ok mate i bodged my way around it by adding a html hidden type input and putting each housename into that as it goes through the loop.  Each hidden box with the variable value has a corresponding button and it works!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.