Jump to content


Photo

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


  • Please log in to reply
4 replies to this topic

#1 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 28 August 2006 - 10:09 PM

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:

$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";

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 :)

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 28 August 2006 - 10:16 PM

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?


I have no idea what that means.

Anyway, you should pass the id in the url...

<?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";

?>

Then on the contact.php, use $_GET['id'] to retrieve the number from the URL.

#3 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 28 August 2006 - 11:08 PM

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.highlandb...se-one-test.php

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

http://www.highlandb...m/phase-one.php

There's no errors when using your code but no results display. Ideas?

#4 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 28 August 2006 - 11:17 PM

change:

while ($a_row = mysql_fetch_row( $results )) {

to:

while ($a_row = mysql_fetch_array( $results )) {


#5 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 29 August 2006 - 03:55 PM

Learning every day  :)

Thanks, works now!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users