harkly Posted July 29, 2010 Share Posted July 29, 2010 I have a search page that pulls up a group of users. You then click on a user name and it take you to a more detailed page. I am using an array with all the users pulled in the search and then passing it in a session to the next page so I can do a Previous & Next. When I do that it currently always starts with the 1st user in the array. I want it to go to the user selected, so if the 3rd user is selected then their info opens. How can I do that? some code from page one (not sure what may be needed it has a lot of code) search here while ($r=mysql_fetch_array($result)){ $userID=$r["userID"]; $aUserIDs[] = $userID; if (0 < $c && 0 == $c % $cells_wide){ echo "<div id='profiles'> <a href='test1.php?userID=$r[userID]'> <div id='name'>$userID</div> "; $c++; } // end of while }// end search results } $_SESSION['userID']=$aUserIDs; this is the 2nd page <?php session_start(); // start up your PHP session! ?> <!-- html code goes in here --> <?php include('library/login.php'); login(); mysql_select_db('test'); foreach($_SESSION['userID'] as $key=>$value) { // and print out the values echo 'The value of $_SESSION['."'".$key."'".'] is '."'".$value."'".' <br />'; } echo " <div id='content'> <div id='box'><h2>Edit Profile</h2> <div id='navigation'> <a href='search.php' title='Log Details'>Back to Search</a> <img src='img/lineSep_2.jpg' width='1' height='21'> <a href='search.php' title='Billing'>New Search</a> <img src='img/lineSep_2.jpg' width='1' height='21'>"; // Get the current page $currentPage = trim($_REQUEST ); // Pagination settings $perPage = 1; $numPages = ceil(count($_SESSION['userID']) / $perPage); if(!$currentPage || $currentPage > $numPages) $currentPage = 0; $start = $currentPage * $perPage; $end = ($currentPage * $perPage) + $perPage; // Extract ones we need foreach($_SESSION['userID'] AS $key => $val) { if($key >= $start && $key < $end) $pagedData[] = $_SESSION['userID'][$key]; } if($currentPage > 0 && $currentPage < $numPages) echo ' <A href="?page=' . ($currentPage - 1) . '">« Previous</A> '; if($numPages > $currentPage && ($currentPage + 1) < $numPages) echo ' <A class=right href="?page=' . ($currentPage + 1) . '">Next »</A> '; foreach($pagedData AS $item) $result = mysql_query("SELECT userID, user.city FROM user WHERE userID = '$item'") or die(mysql_error()); while ($r=mysql_fetch_array($result)) { $userID=$r["userID"]; $city=$r["city"]; } echo "<br><br> $userID, $city "; ?> Link to comment https://forums.phpfreaks.com/topic/209243-how-can-i-do-this/ Share on other sites More sharing options...
harkly Posted July 29, 2010 Author Share Posted July 29, 2010 I think it may have something to do with searching the array and I can do that but not sure how to pass that info on modified 2nd page code <?php session_start(); // start up your PHP session! ?> <!-- html code goes in here --> <?php include('library/login.php'); login(); mysql_select_db('harkly'); $userID=$_GET["userID"]; // searching the array ($_SESSION['userID'] echo "passing - $userID <br><br>"; $selectedUser = array_search($userID, $_SESSION['userID']); // $key = 2; echo "Key - "; print_r($selectedUser); echo "<br><Br>"; print_r(array_values($_SESSION['userID'])); // brings up all the users info and sets the Previou & Next links echo "<br><Br>"; foreach($_SESSION['userID'] as $key=>$value) { // and print out the values echo 'The value of $_SESSION['."'".$key."'".'] is '."'".$value."'".' <br />'; } echo " <div id='content'> <div id='box'><h2>Edit Profile</h2> <div id='navigation'> <a href='search.php' title='Log Details'>Back to Search</a> <img src='img/lineSep_2.jpg' width='1' height='21'> <a href='search.php' title='Billing'>New Search</a> <img src='img/lineSep_2.jpg' width='1' height='21'>"; // Get the current page $currentPage = trim($_REQUEST ); // Pagination settings $perPage = 1; $numPages = ceil(count($_SESSION['userID']) / $perPage); if(!$currentPage || $currentPage > $numPages) $currentPage = 0; $start = $currentPage * $perPage; $end = ($currentPage * $perPage) + $perPage; // Extract ones we need foreach($_SESSION['userID'] AS $key => $val) { if($key >= $start && $key < $end) $pagedData[] = $_SESSION['userID'][$key]; } if($currentPage > 0 && $currentPage < $numPages) echo ' <A href="?page=' . ($currentPage - 1) . '">« Previous</A> '; if($numPages > $currentPage && ($currentPage + 1) < $numPages) echo ' <A class=right href="?page=' . ($currentPage + 1) . '">Next »</A> '; foreach($pagedData AS $item) $result = mysql_query("SELECT userID, user.city FROM user WHERE userID = '$item'") or die(mysql_error()); while ($r=mysql_fetch_array($result)) { $userID=$r["userID"]; $city=$r["city"]; } echo "<br><br> $userID, $city "; ?> Link to comment https://forums.phpfreaks.com/topic/209243-how-can-i-do-this/#findComment-1092655 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.