rpjd Posted March 2, 2011 Share Posted March 2, 2011 I have page1.php which has a post form and page2.php which display data/results. I have a seperate php script file which queries a database. Having completed the query and assuming a result, I would end up with something like while($result = mysql_fetch_assoc($query)) how do I get the data onto the display page. Looking at example approaches I found this using a go-between file <?PHP include_once(process.php; process($_POST); display_results; ?> would display_results be a form of redirect? If not? Any help appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/229360-processing-and-displaying-data/ Share on other sites More sharing options...
gizmola Posted March 2, 2011 Share Posted March 2, 2011 Your form is going to post to it's target, and that script will have the values from the form in the $_POST. Assuming you need to use the post in your query, your results script should just contain or include the query. There is no redirect or intermediary involved. Quote Link to comment https://forums.phpfreaks.com/topic/229360-processing-and-displaying-data/#findComment-1181776 Share on other sites More sharing options...
rpjd Posted March 2, 2011 Author Share Posted March 2, 2011 So if I have my query in a seperate file and end up with while($result = mysql_fetch_assoc($query)) {what happens here?} what happens next if re-direct is not involved? Quote Link to comment https://forums.phpfreaks.com/topic/229360-processing-and-displaying-data/#findComment-1181781 Share on other sites More sharing options...
gizmola Posted March 2, 2011 Share Posted March 2, 2011 That loop is going to fill $result as an array with one row of data. Usually you would output it in some way. For a really quick test: var_dump($result); Quote Link to comment https://forums.phpfreaks.com/topic/229360-processing-and-displaying-data/#findComment-1181782 Share on other sites More sharing options...
rpjd Posted March 2, 2011 Author Share Posted March 2, 2011 So how do I output it to page2.php? Quote Link to comment https://forums.phpfreaks.com/topic/229360-processing-and-displaying-data/#findComment-1181783 Share on other sites More sharing options...
rpjd Posted March 2, 2011 Author Share Posted March 2, 2011 I don't mind doing the data processing on the same page as the display page, but I don't want the servername, user and password visible? Can/should I have the connection details listed in another security file perhaps? Quote Link to comment https://forums.phpfreaks.com/topic/229360-processing-and-displaying-data/#findComment-1181815 Share on other sites More sharing options...
hoogie Posted March 2, 2011 Share Posted March 2, 2011 Yeah generally you put your database connection information in it's own script and include it when you need to connect. It also makes things a lot easier if the password to your database ever changes. Quote Link to comment https://forums.phpfreaks.com/topic/229360-processing-and-displaying-data/#findComment-1181841 Share on other sites More sharing options...
rpjd Posted March 2, 2011 Author Share Posted March 2, 2011 Ok. How and where exactly show this information be stored? Quote Link to comment https://forums.phpfreaks.com/topic/229360-processing-and-displaying-data/#findComment-1181844 Share on other sites More sharing options...
hoogie Posted March 2, 2011 Share Posted March 2, 2011 Just create a new .php file and put the connection information in there. For added security, you can save it outside your document root (more info on that here if you're interested: http://www.tuxradar.com/practicalphp/17/1/3). Then, when you need to run a query, just include that file before the query is run. Quote Link to comment https://forums.phpfreaks.com/topic/229360-processing-and-displaying-data/#findComment-1181846 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.