chutchick Posted December 24, 2011 Share Posted December 24, 2011 Good day and Merry Christmas to all, I just spent a good time of my christmas eve trying to figure out this problem. I hope one of you santas would be so kind as to help me with it. First off I have two tables; employee and employee_works both connected via employee_id key. Basically I have a parent window we'll call parent.php. inside the parent page is a search button that once clicked will open a child window we'll call child.php inside the child page is a list, lets say employees with name, employee_id, etc. My main concern is this: How do I populate parent.php based off the employee selection I made in the child window. Example: -Access parent.php -Click on search -Click on [iD: 004] [NAME: JOHN SMITH] [PHONE: 1233456] [DATE HIRED: JULY 16, 1992] <---format of a row in child.php -child.php automatically closes and parent.php now shows all data from employee_works with the employee_id = 004 Is this even possible? I know this is vary vague and would be willing to explain more if needed. My website is built mostly on javascript and php. Quote Link to comment https://forums.phpfreaks.com/topic/253809-display-query-based-off-selection-on-child-page/ Share on other sites More sharing options...
Pikachu2000 Posted December 24, 2011 Share Posted December 24, 2011 It isn't clear which part you're having trouble with. Quote Link to comment https://forums.phpfreaks.com/topic/253809-display-query-based-off-selection-on-child-page/#findComment-1301196 Share on other sites More sharing options...
chutchick Posted December 24, 2011 Author Share Posted December 24, 2011 I cant figure out how to populate the parent window. How do I pass a php variable from child to parent and then using that variable to "auto-query" on the parent window. Is that at all possible with a Server side lang? Quote Link to comment https://forums.phpfreaks.com/topic/253809-display-query-based-off-selection-on-child-page/#findComment-1301197 Share on other sites More sharing options...
Pikachu2000 Posted December 24, 2011 Share Posted December 24, 2011 Server side languages aren't aware of whether a window is a parent or child, but you could always use a $_SESSION variable. That would be available globally. Quote Link to comment https://forums.phpfreaks.com/topic/253809-display-query-based-off-selection-on-child-page/#findComment-1301198 Share on other sites More sharing options...
chutchick Posted December 24, 2011 Author Share Posted December 24, 2011 so lets say i assign a $session[id] = 4; then i call a javascript function to close the child window and window.opener.reload() to refresh the parent window. then on the parent window i add something like: if($session[id]) { //code for employee_works here } would this be ok? Quote Link to comment https://forums.phpfreaks.com/topic/253809-display-query-based-off-selection-on-child-page/#findComment-1301199 Share on other sites More sharing options...
Pikachu2000 Posted December 24, 2011 Share Posted December 24, 2011 It should work. Give it a shot and see what happens. Make sure you call session_start() in each script that will use $_SESSION data, before any output is generated by the script. Quote Link to comment https://forums.phpfreaks.com/topic/253809-display-query-based-off-selection-on-child-page/#findComment-1301200 Share on other sites More sharing options...
chutchick Posted December 24, 2011 Author Share Posted December 24, 2011 Ive got it down to: if($_SESSION["ledger"]) { $led = $_SESSION["ledger"]; $sql = mysql_query("SELECT * FROM employee_works WHERE employee_id = $led"); while($row = mysql_fetch_array($sql)) <--this is line 113 { echo "<tr>"; echo "<td align='center' width='300'>" . $row['employee_work_des'] . "</td>"; echo "<td align='center' width='300'>" . $row['employee_work_time'] . "</td>"; echo"</tr>"; } echo "</table>"; its giving an error: Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in C:\xampp\htdocs\beta\function\ledger.php on line 113 Quote Link to comment https://forums.phpfreaks.com/topic/253809-display-query-based-off-selection-on-child-page/#findComment-1301202 Share on other sites More sharing options...
PFMaBiSmAd Posted December 25, 2011 Share Posted December 25, 2011 That error means that code is not the actual code that is producing that error. string given ^^^ Means that the variable or literal value you supplied to the mysql_fetch_array() statement is a string. The posted code would have supplied a result resource if the query executed without any errors or a boolean false value if the query failed to execute due to an error. The only way the posted code could have supplied a string to the mysql_fetch_array() statement would be if there was a statement like - $sql = "a statement producing a string";, either somewhere between the mysql_query() statement and the start of the while(){} loop or somewhere in the actual code inside the while(){} loop. Quote Link to comment https://forums.phpfreaks.com/topic/253809-display-query-based-off-selection-on-child-page/#findComment-1301283 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.