fireice87 Posted July 25, 2007 Share Posted July 25, 2007 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 Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 25, 2007 Share Posted July 25, 2007 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. Quote Link to comment Share on other sites More sharing options...
fireice87 Posted July 25, 2007 Author Share Posted July 25, 2007 Thanks alot that works perfectly iv been trying many what know seem slighlty iraational methods to get that to work all day! thats very useful to know i think ill be looking into that as tbh i knew nothing of it ??? cheers! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.