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. 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. 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? 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); 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? 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? 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. 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? 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. Link to comment https://forums.phpfreaks.com/topic/229360-processing-and-displaying-data/#findComment-1181846 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.