Jump to content

Search database and display


moisesbr

Recommended Posts

Hi

I 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.

Thanks

Moises


// Make a MySQL Connection
mysql_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

... 
Link to comment
Share on other sites

 
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 by davidannis
Link to comment
Share on other sites

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 .

Link to comment
Share on other sites

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 by davidannis
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.