Jump to content

How would I pass a field from results to a contact form?


simcoweb

Recommended Posts

Ok, here's what I have. A list of lots available for purchase. Each lot has an ID#. The database has 4 fields:

unit
location
view
sales_price

I'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
Share on other sites

[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>&nbsp;</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
Share on other sites

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

It should look like this previous version (the results, not the entire page):

http://www.highlandbluffsresort.com/phase-one.php

There's no errors when using your code but no results display. Ideas?
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.