chris_s_22 Posted December 1, 2009 Share Posted December 1, 2009 when i do a search on the database i display data like so echo '<a href="view.php">' . $row['username'] . '</a>'; if a user clicks on the link of a result it takes them to a page that does includes for each part of a page. This is view.php <?php include_once 'Connect.php'; if (!is_authed()) { die ('You are not permitted to view this page, <a href="index.php">click here</a> to go back.'); } ?> <html><head><title>Untitled Document</title> <link href="style.css" rel="stylesheet" type="text/css"></head> <body> <div class=logo><?php include "logo.php";?></div> <div class=navigationbarbox><?php include "navigationbar.php";?></div> <div class=photo><?php include "image.php";?></div> <div class=sidelinks><?php include "sidebar.php";?></div> <div class=info><?php include "info.php";?></div> <div class=footerbox><?php include "footer.php";?></div> </body></html> the logo,navbar and footer will always be same, however the image, sidebar and info will differ currently each page is coded to display the session users data. this is image.php <?php include_once 'Connect.php'; $thequery = ("SELECT * FROM members WHERE username = '$username' "); $query = mysql_query($thequery) or die ('failed query.'); while ($row = mysql_fetch_assoc($query)) { $photo = $row["photo"]; } ?> <html> <head></head> <body> <img src="http://www.escortellie.co.uk/NEWTEACH/userimages/<?php echo $photo?>" width="100" height="150"> </body> </html> i want it still to display the sesion data but if came from the search to display the data of that user instead which parts and how do i alter my code so this can be acomplished Quote Link to comment Share on other sites More sharing options...
Adam Posted December 1, 2009 Share Posted December 1, 2009 You just need to modify the WHERE clause of your SQL to select another user's data instead. I don't think you've really provided enough information here though. Where does the $username variable come from within image.php? What do you mean by "if came from the search"? Where do you display the "session data"? -- What is the session data you mean? Quote Link to comment Share on other sites More sharing options...
chris_s_22 Posted December 1, 2009 Author Share Posted December 1, 2009 the $username is the session data the site im creating so far users can register/login which starts a session user then can upload photos, edit there profiles and view there own profile when they goto view.php user can search for other user this is where im up to. i want a user to be able to, not only search but to click on there name and view there profile when someone uses my search it dispalys some brief users data with a link. if a user clicks on that link i want it to display there data NOT THE SESSION DATA but... i need the script to carry on as it is displaying session data so if a user visit view.php it still views there data I ONLY need to do the above if it came from the search results. im guessing i have to add something to the search results link view.php? this should send data to the view.php then on the view.php do a check to see if it there was any data sent otherwise to do what it was original just im not sure exactly what Quote Link to comment Share on other sites More sharing options...
Adam Posted December 1, 2009 Share Posted December 1, 2009 Send each user ID / username through the URL (e.g. view.php?user_id=123) from your search links, then you can test if it isset (and valid) within view.php - if it's not obviously you just use the current user's ID. It looks like you're performing individual queries in each included file and returning every field (*) each time. Why don't you just perform a single query at the start of view.php and the included files just use that data? Quote Link to comment Share on other sites More sharing options...
chris_s_22 Posted December 1, 2009 Author Share Posted December 1, 2009 would this be consider right? while($row=mysql_fetch_array($result)) { $userid = $row["id"]; echo '<a href="profileindex.php?user_id='$userid'">' . $row['username'] . '</a><br>'; } 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.