moisesbr Posted July 26, 2013 Share Posted July 26, 2013 HiI am trying the code below and managed to display a unique record.But, if I found more than one record, how can I display them by lines.Also if possible, how can I insert a link in everyline to go to that record.ThanksMoises// Make a MySQL Connectionmysql_connect("localhost", "database_monitor", 'password') or die(mysql_error());mysql_select_db("monitorr_acrisoft") or die(mysql_error());$result = mysql_query("SELECT * FROM prova WHERE ID= '$protocolo'") or die (mysql_error());$mem_row = mysql_fetch_array( $result );$count = mysql_num_rows($result);if($count >= 1) ....// display: Nome, city, code... Quote Link to comment https://forums.phpfreaks.com/topic/280548-search-database-and-display/ Share on other sites More sharing options...
.josh Posted July 26, 2013 Share Posted July 26, 2013 while ( $mem_row = mysql_fetch_array( $result ) ) { // .. } Quote Link to comment https://forums.phpfreaks.com/topic/280548-search-database-and-display/#findComment-1442309 Share on other sites More sharing options...
davidannis Posted July 26, 2013 Share Posted July 26, 2013 (edited) while ( $mem_row = mysql_fetch_array( $result ) ) { echo "<a href=\"linktodisplayhere.php?record={$mem_row['id_field_name']}\">{$mem_row['Nome']},</a> {$mem_row['city']}, {$mem_row['code']}"; } to elaborate on Josh's answer and show how to link to a program to display the full record. Edited July 26, 2013 by davidannis Quote Link to comment https://forums.phpfreaks.com/topic/280548-search-database-and-display/#findComment-1442313 Share on other sites More sharing options...
moisesbr Posted July 26, 2013 Author Share Posted July 26, 2013 Thank you. It works fine listing data !But instead of linking to a page "linktodisplayhere.php" it would like just to click over a line and show details of that record. I mean, after click on a line, going to a second page and show: (Nome, city, code, and more fields I want) of that ID . Quote Link to comment https://forums.phpfreaks.com/topic/280548-search-database-and-display/#findComment-1442317 Share on other sites More sharing options...
davidannis Posted July 26, 2013 Share Posted July 26, 2013 (edited) Thank you. It works fine listing data ! But instead of linking to a page "linktodisplayhere.php" it would like just to click over a line and show details of that record. I mean, after click on a line, going to a second page and show: (Nome, city, code, and more fields I want) of that ID . So you write a script called linktodisplay.php that does this: mysql_connect("localhost", "database_monitor", 'password') or die(mysql_error()); mysql_select_db("monitorr_acrisoft") or die(mysql_error()); $id=mysql_real_escape_stirng($_GET['id']); $result = mysql_query("SELECT * FROM prova WHERE ID= '$id'") or die (mysql_error()); ($mem_row = mysql_fetch_array( $result )){ echo "All of the info you want to echo"; } Edited July 26, 2013 by davidannis Quote Link to comment https://forums.phpfreaks.com/topic/280548-search-database-and-display/#findComment-1442327 Share on other sites More sharing options...
davidannis Posted July 26, 2013 Share Posted July 26, 2013 If you want the results on the same page, not a new page then you need to use javascript and hide/show a div. Quote Link to comment https://forums.phpfreaks.com/topic/280548-search-database-and-display/#findComment-1442328 Share on other sites More sharing options...
moisesbr Posted July 26, 2013 Author Share Posted July 26, 2013 Ok, now I start to comprehend it. I learnt a bit of it this stuff using "post" it the past. What is the difference of get/post ? Is there one which of them which is safer or more recommended ? Quote Link to comment https://forums.phpfreaks.com/topic/280548-search-database-and-display/#findComment-1442333 Share on other sites More sharing options...
KevinM1 Posted July 26, 2013 Share Posted July 26, 2013 Ok, now I start to comprehend it. I learnt a bit of it this stuff using "post" it the past. What is the difference of get/post ? Is there one which of them which is safer or more recommended ? Easiest way to think of it: Use GET to retrieve information Use POST to insert/update/delete information Under the hood they both operate similarly in that they send key/value pairs to the server. The differences being that GET's pairs are visible right in the browser's address bar whereas POST sends them behind the scenes, and you can generally send more information with POST. But, really, GET and POST are verbs. Use them as they would be used in English, and you'll be all set. Quote Link to comment https://forums.phpfreaks.com/topic/280548-search-database-and-display/#findComment-1442335 Share on other sites More sharing options...
davidannis Posted July 27, 2013 Share Posted July 27, 2013 KevinM1 is right. Generally, the GET method should be used when the data is not changed (just a query and display) and POST used when the data is changed (records added, etc.) The reason it matters is that browsers will ask if a user is sure they want to resubmit if a POST is used and the user goes back in history but often just send the request again for a GET. It is explained in more detail here. You should still check for double submissions if they would cause a problem because the browser does not prevent them even with a POST. This article gives a good explanation of the differences with more detail including situations in which you may want to break the general rule. Quote Link to comment https://forums.phpfreaks.com/topic/280548-search-database-and-display/#findComment-1442355 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.