simcoweb Posted August 28, 2006 Share Posted August 28, 2006 Ok, here's what I have. A list of lots available for purchase. Each lot has an ID#. The database has 4 fields:unitlocationviewsales_priceI'm using this code to display the results of the query in a simple table layout:[code]$sql=("SELECT * FROM phase_one");$results=mysql_query($sql);$row = mysql_fetch_row($results);$num_rows = mysql_num_rows($results);if ($num_rows == 0) {echo "<font class='bodytext'><center>We are sorry. The lot information is unavailable at this time.<br /> Please contact us for details on available lots.<br />";} else {echo "<table width='650' border='0'>\n";echo "<th>Unit No.</th><th>Location</th><th>View</th><th>Sale Price</th>";while ($a_row = mysql_fetch_row( $results )) {echo "<tr>\n";foreach ($a_row as $field)print "\t<td><center>$field</td>\n";print "</tr>\n";} }print "</table>\n";[/code]What I want to do is have a 5th column in the results that has a 'Contact' link pointing to contact.php that would then have the lot # pre-populated in the RE: field of the form. I've tinkered with this and have come to the conclusion that I can't do it using this type of 'foreach' method. Or, can I? Would I need to switch from mysql_fetch_row to mysql_fetch_array then extract the array to set field variables and lay out the HTML manually and insert the $vars into the respective <td>'s? A little help with this one, puhleeeeeeez :) Link to comment https://forums.phpfreaks.com/topic/18951-how-would-i-pass-a-field-from-results-to-a-contact-form/ Share on other sites More sharing options...
hitman6003 Posted August 28, 2006 Share Posted August 28, 2006 [quote]I've tinkered with this and have come to the conclusion that I can't do it using this type of 'foreach' method. Or, can I? Would I need to switch from mysql_fetch_row to mysql_fetch_array then extract the array to set field variables and lay out the HTML manually and insert the $vars into the respective <td>'s? [/quote]I have no idea what that means.Anyway, you should pass the id in the url...[code]<?php$sql=("SELECT * FROM phase_one");$results=mysql_query($sql);$row = mysql_fetch_row($results);$num_rows = mysql_num_rows($results);if ($num_rows == 0) { echo " <font class='bodytext'> <center>We are sorry. The lot information is unavailable at this time.<br /> Please contact us for details on available lots.<br />";} else { echo " <table width='650' border='0'> <tr> <th>Unit No.</th> <th>Location</th> <th>View</th> <th>Sale Price</th> <th> </th> <tr>"; while ($a_row = mysql_fetch_row( $results )) { echo " <tr> <td style=\"text-align: center;\">" . $a_row['unitid'] . "</td> <td style=\"text-align: center;\">" . $a_row['location'] . "</td> <td style=\"text-align: center;\">" . $a_row['View'] . "</td> <td style=\"text-align: center;\">" . $a_row['price'] . "</td> <td style=\"text-align: center;\"><a href=\"contact.php?id=" . $a_row['unitid'] . "\">Contact</a></td> </tr>"; }print "</table>\n";?>[/code]Then on the contact.php, use $_GET['id'] to retrieve the number from the URL. Link to comment https://forums.phpfreaks.com/topic/18951-how-would-i-pass-a-field-from-results-to-a-contact-form/#findComment-81875 Share on other sites More sharing options...
simcoweb Posted August 28, 2006 Author Share Posted August 28, 2006 Ok, thanks for that suggestion. I used your code and now the results don't display. Just blanks below the headings. Here's a view:http://www.highlandbluffsresort.com/phase-one-test.phpIt should look like this previous version (the results, not the entire page):http://www.highlandbluffsresort.com/phase-one.phpThere's no errors when using your code but no results display. Ideas? Link to comment https://forums.phpfreaks.com/topic/18951-how-would-i-pass-a-field-from-results-to-a-contact-form/#findComment-81919 Share on other sites More sharing options...
hitman6003 Posted August 28, 2006 Share Posted August 28, 2006 change:[code]while ($a_row = mysql_fetch_row( $results )) {[/code]to:[code]while ($a_row = mysql_fetch_array( $results )) {[/code] Link to comment https://forums.phpfreaks.com/topic/18951-how-would-i-pass-a-field-from-results-to-a-contact-form/#findComment-81928 Share on other sites More sharing options...
simcoweb Posted August 29, 2006 Author Share Posted August 29, 2006 Learning every day :)Thanks, works now! Link to comment https://forums.phpfreaks.com/topic/18951-how-would-i-pass-a-field-from-results-to-a-contact-form/#findComment-82280 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.