Jump to content

[SOLVED] guidance needed!! how can i get this variable to the next page


fireice87

Recommended Posts

Right iv got this page http://www.thewu.site23.co.uk/browseallprofiles.php

 

whitch works like this

 

$sql = "Select `user` FROM profile_quickfacts";  //pull the users from the table

    $result= @mysql_query($sql, $conn )
or die(" Could not add style facts");

echo "<table>";
while($row = mysql_fetch_array($result))   
  {
  echo "<tr>";       
  echo "<td>" ?> <a href="ViewProfile.php"><?php echo $row['user'] ?></a> <?php  "</td>"; //use the variable row to show username
  $view = $row['user'];
    echo "</tr>";  
    echo "<td>" ?> <img src="DisplayPic_Tiny/<?php echo $row['user']?>.jpg"/> <?php "</td>"; // use the varaible row to display image DisplayPic_Tiny/user
  echo "</tr>";
  }
echo "</table>";

 

clicking the user name acts as a link to the page ViewProfile.php but what i need to do is pass to the ViewProfile.php page the $row['user']  variable as the next page works like this

$sql = "Select `user`,`displayname`,`category`,`sex`,`orientation`,`status`,`location`,`highSchool`,`occupation`,`day`,`month`,`year` FROM profile_quickfacts WHERE user= '$row' "; 
--------------------display code

 

i cant figure out how to get the variable across i cant use a cookie as it needs to be in a middle of the page as you can see from the link above

im thinking i need to use a form but cant quite figure out how to do it iv got to this http://www.thewu.site23.co.uk/browseallprofiles2.php

 

while($row = mysql_fetch_array($result))   
  { 
  ?>
   <form action="StoreLists.php" method="post">
  <?php
  echo "<tr>";       
  echo "<td>" ?> <a href="ViewProfile.php"><?php echo $row['user'] ?></a> <?php  "</td>"; //use the variable row to show username
  $view = $row['user'];
    echo "</tr>";  
    echo "<td>" ?> <img src="DisplayPic_Tiny/<?php echo $row['user']?>.jpg"/> <?php "</td>"; // use the varaible row to display image DisplayPic_Tiny/user
  echo "</tr>";
  
   echo "<td>" ?><input type="submit" value="view profile" name="view" /><?php "</td>";
      ?> </form> <?php
  }
echo "</table>";  
  ?>

 

i think im almost there but cant figure out how to get the form to actual pass the variable i want it too the $row['user'] varibale so i can use it to pull the right user from the database on the viewprofile page by using WHERE user = $variable

 

thanks for anyhelp :)

 

Link to comment
Share on other sites

You use GET. Ever done a google search and wondered what all the junk after the url is? For example:

 

http://www.google.co.uk/search?hl=en&q=test&btnG=Google+Search&meta=

 

You can pass variables through the url in this way.

 

As an example, we'll use page1.php and page2.php.

 

page1.php:

<?php
$var = 'foo';
echo '<a href="page2.php?var='.$var.'">Click here</a>';
?>

page2.php:

<?php
echo $_GET['var'];
//output would be foo
?>

 

You can also pass multiple variables in the url by separating each variable name and value pair with an ampersand (&) - rather like the above google example.

 

So, in answer to your original question, you would make your links something along the lines of:

 

echo '<a href="ViewProfile.php?user='.$row['user'].'">View profile</a>';

 

And then on Viewprofile.php:

 

<?php
$user = $_GET['user'];
$sql = "SELECT * FROM `yourtable` WHERE `user`='$user'"
//query and display data
?>

 

I hope that explains it. Although i feel i might have rambled slightly.

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.