Jump to content

Have a simple "select" function on summary page-need suggestions for detail page


SarahJ

Recommended Posts

Hi there!

 

I'm really new to PHP - trying to learn and develop simultaneously, so I'd like to apologize ahead of time for any terminology errors or obvious mistakes...

 

To the point:

- I'm using an html form that asks users to select a state so they can filter information by their state

- The form action opens a PHP script that selects all the records in a specified table that match the state and then echos a few of the record fields for each in a summary "quick description" list.

 

So far, the script works perfectly.

 

What I *really* want to do (and can't figure out how) is include a link within the summary description to a new page with all of the details from the record...

 

I don't have a problem inserting a simple link within the description of each record to a new page, but I have no idea how to pass the new detail page the right record.

 

ANY help would be seriously appreciated!

 

My code, for the summary page, if it helps:

 

 $sql = "select * from MY_TABLE where STATE = '".$state."'";
$result = mysql_query($sql) or die(mysql_error());

  $num_results = mysql_num_rows($result);
  echo "<p>Number of results found: ".$num_results."</p>";

  for ($i=0; $i <$num_results; $i++) {
     $row = mysql_fetch_assoc($result);
     echo "<p><strong>Name: </strong>";
     echo htmlspecialchars(stripslashes($row['NAME']));
     echo "<strong><br />Organization: </strong>";
     echo stripslashes($row['COMPANY_NAME']);
  echo "<strong><br />Metro Area: </strong>";
     echo stripslashes($row['METRO_AREA']);
     echo "<br /><br /><small>";
     echo stripslashes($row['SUMMARY']);
     echo "</small></p><hr width=\"80%\" align=\"center\">";
  }

Perhaps I am reading what you want to do the wrong way but one way to pass a variable inside a link is e.g.

 

echo "<a href=\"MyNewPage?VariableName=$VariableValue\"">Click here to see all States</a>"

 

Collect the variable value on the new page with e.g.

 

$MyNewVar=$_GET[VariableName]

 

Hope this helps

p.s. you can add other variables and values after the first one using the & symbol before each one

 

Hi Riparian!

 

Thanks so much for the response!  I really appreciate it - and that was definitely new information for me.  I think my next question is that I want it to grab the variable from the values of the loop it's currently in, and I'm not sure how to do that.

 

For example,

$sql = "select * from MY_TABLE where STATE = '".$state."'";
$result = mysql_query($sql) or die(mysql_error());

  $num_results = mysql_num_rows($result);
  echo "<p>Number of results found: ".$num_results."</p>";

  for ($i=0; $i <$num_results; $i++) {
     $row = mysql_fetch_assoc($result);
     echo "<p><strong>Name: </strong>";
     echo htmlspecialchars(stripslashes($row['NAME']));


    echo "  (<a href=\"tddetails.php?TID=$row['PRIKEY']\">more information</a>)<strong><br />Organization: </strong>";


     echo stripslashes($row['COMPANY_NAME']);
  echo "<strong><br />Metro Area: </strong>";
     echo stripslashes($row['METRO_AREA']);
     echo "<br /><br /><small>";
     echo stripslashes($row['SUMMARY']);
     echo "</small></p><hr width=\"80%\" align=\"center\">";
  }

 

I'm not sure if it's really obvious in that, or not, but I want to make sure that when that loop finishes and there's twenty records being shown on the page, the link that gets clicked passes the info for the one record where they clicked it...

 

I thought I might be able to assign the variable a value based on the $row variable I had been using in the loop (so that it takes it from the respective row), but it didn't like my syntax, so I think I'm trying to do it the wrong way.

 

Any chance someone could correct the syntax to accomplish what I'm trying to do?

 

Thanks so much, again!

-SarahJ

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.