8 Replies - 782 Views - Last Post: 29 March 2012 - 02:52 PM Rate Topic: -----

#1 Coolest_gal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 14-January 09

Adding a html form to a table

Posted 23 March 2012 - 12:18 PM

Hi!

I want to display "Add to cart button" under the name and price cells. Is it possible to place it in a table or through some other wa to have the button under each item rather than having them all together on top. Here is the code
 <html>
<head>
<title> product</title>
</head>
<body>
<?php
$hostname = "shopbyclickorg.ipagemysql.com";
	$username = "shopbyclickorg";
	$password = "******";
	if(!($link = mysql_connect($hostname,$username,$password)))
	      die("Could not connect to database.");
	$databasename = "e_commercedb";
	if(!(mysql_select_db($databasename,$link)))
	      die("Could not open table.");
$result =mysql_query( 'SELECT * FROM product');
 Print "<table border cellpadding=3>"; 
 
while ($row = mysql_fetch_array( $result ))  {
	 Print "<tr>"; 
	 Print "<th>Name:</th> <td>".$row['PName'] . "</td> "; 
	 Print "<th>price:</th> <td>".$row['Pprice'] . " </td></tr>";
?>

<form method="post" action="https://www.paypal.com/cgi-bin/webscr" target="_blank">
<input type="hidden" name="business" value="rubayya_abbasi@yahoo.com">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="add" value="1">
<input type="hidden" name="item_name" value="<?php echo $row['PName'] ?>" />
<input type="hidden" name="item_number" value="<?php echo $row['PID'] ?>" />
<input type="hidden" name="amount" value="<?php echo $row['Pprice'] ?>" />
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="return" value="http://www.shopbyclick.org"> 
<input type="image" src="images/addcart.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
</form> 
</br>
<?php
}
?>

</body>
</html>

The output that I m getting is in the attached file.

Is This A Good Question/Topic? 0
  • +

Replies To: Adding a html form to a table

#2 Coolest_gal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 14-January 09

Re: Adding a html form to a table

Posted 24 March 2012 - 09:03 AM

hello?
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5667
  • View blog
  • Posts: 22,509
  • Joined: 23-August 08

Re: Adding a html form to a table

Posted 24 March 2012 - 10:20 AM

Quote

The output that I m getting is in the attached file.


Uh, no it's not, because there IS no attached file.
Was This Post Helpful? 0
  • +
  • -

#4 Coolest_gal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 14-January 09

Re: Adding a html form to a table

Posted 25 March 2012 - 09:30 AM

Oops! Sorry! Let me attach again

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5667
  • View blog
  • Posts: 22,509
  • Joined: 23-August 08

Re: Adding a html form to a table

Posted 25 March 2012 - 09:54 AM

Do a View Source in your browser on your page. Look at the HTML, does it look right? I'm assuming you know HTML if you're designing a shopping site.
Was This Post Helpful? 0
  • +
  • -

#6 Slice  Icon User is offline

  • D.I.C Addict


Reputation: 196
  • View blog
  • Posts: 591
  • Joined: 24-November 08

Re: Adding a html form to a table

Posted 25 March 2012 - 12:15 PM

Ok here is an example that should work:

<?php
$hostname = "shopbyclickorg.ipagemysql.com";
	$username = "shopbyclickorg";
	$password = "******";
	if(!($link = mysql_connect($hostname,$username,$password)))
	      die("Could not connect to database.");
	$databasename = "e_commercedb";
	if(!(mysql_select_db($databasename,$link)))
	      die("Could not open table.");
$result =mysql_query( 'SELECT * FROM product');
 Print "<table border cellpadding=3>"; 
 
while ($row = mysql_fetch_array( $result ))
{
?>
<form method="post" action="https://www.paypal.com/cgi-bin/webscr" target="_blank">
	<tr> 
		<th>Name:</th> 
		<td><?php echo $row['Pname']; ?></td>
		<th>price:</th> 
		<td><?php echo $row['Pprice']; ?></td>
	</tr>
	<tr>
		<td colspan="4" align="right">
			<input type="hidden" name="business" value="rubayya_abbasi@yahoo.com">
			<input type="hidden" name="cmd" value="_cart">
			<input type="hidden" name="add" value="1">
			<input type="hidden" name="item_name" value="<?php echo $row['PName'] ?>" />
			<input type="hidden" name="item_number" value="<?php echo $row['PID'] ?>" />
			<input type="hidden" name="amount" value="<?php echo $row['Pprice'] ?>" />
			<input type="hidden" name="quantity" value="1">
			<input type="hidden" name="return" value="http://www.shopbyclick.org"> 
			<input type="image" src="images/addcart.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
		</td>
	</tr>
</form> 
</br>
<?php
}
?>
</table>
</body>



Seperating into another <tr> tag starts another row, to stop it all being printed outside of the table.
Was This Post Helpful? 0
  • +
  • -

#7 Coolest_gal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 14-January 09

Re: Adding a html form to a table

Posted 29 March 2012 - 08:36 AM

View PostSlice, on 25 March 2012 - 01:15 PM, said:

Ok here is an example that should work:

<?php
$hostname = "shopbyclickorg.ipagemysql.com";
	$username = "shopbyclickorg";
	$password = "******";
	if(!($link = mysql_connect($hostname,$username,$password)))
	      die("Could not connect to database.");
	$databasename = "e_commercedb";
	if(!(mysql_select_db($databasename,$link)))
	      die("Could not open table.");
$result =mysql_query( 'SELECT * FROM product');
 Print "<table border cellpadding=3>"; 
 
while ($row = mysql_fetch_array( $result ))
{
?>
<form method="post" action="https://www.paypal.com/cgi-bin/webscr" target="_blank">
	<tr> 
		<th>Name:</th> 
		<td><?php echo $row['Pname']; ?></td>
		<th>price:</th> 
		<td><?php echo $row['Pprice']; ?></td>
	</tr>
	<tr>
		<td colspan="4" align="right">
			<input type="hidden" name="business" value="rubayya_abbasi@yahoo.com">
			<input type="hidden" name="cmd" value="_cart">
			<input type="hidden" name="add" value="1">
			<input type="hidden" name="item_name" value="<?php echo $row['PName'] ?>" />
			<input type="hidden" name="item_number" value="<?php echo $row['PID'] ?>" />
			<input type="hidden" name="amount" value="<?php echo $row['Pprice'] ?>" />
			<input type="hidden" name="quantity" value="1">
			<input type="hidden" name="return" value="http://www.shopbyclick.org"> 
			<input type="image" src="images/addcart.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
		</td>
	</tr>
</form> 
</br>
<?php
}
?>
</table>
</body>



Seperating into another <tr> tag starts another row, to stop it all being printed outside of the table.

Thanks, it worked! However, I was wrong in the question and forgot to mention that I want products displayed horizontally .Right now they are being displayed vertically . How could I do that?
Was This Post Helpful? 0
  • +
  • -

#8 Coolest_gal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 14-January 09

Re: Adding a html form to a table

Posted 29 March 2012 - 09:54 AM

I have created separate tables for each product. Just can't have them arranged horizontally.
 <?php
$hostname = "shopbyclickorg.ipagemysql.com";
	$username = "shopbyclickorg";
	$password = "******";
	if(!($link = mysql_connect($hostname,$username,$password)))
	      die("Could not connect to database.");
	$databasename = "e_commercedb";
	if(!(mysql_select_db($databasename,$link)))
	      die("Could not open table.");
$result =mysql_query( 'SELECT * FROM product');
while ($row = mysql_fetch_array( $result ))
{
Print "<table border cellpadding=3>"; 
?>
<form method="post" action="https://www.paypal.com/cgi-bin/webscr" target="_blank">

	<tr> 
		<th>Name:</th> 
		<td><?php echo $row['PName']; ?></td>
		<th>price:</th> 
		<td><?php echo $row['Pprice']; ?></td>
	</tr>
	<tr>
		<td colspan="4" align="right">
			<input type="hidden" name="business" value="rubayya_abbasi@yahoo.com">
			<input type="hidden" name="cmd" value="_cart">
			<input type="hidden" name="add" value="1">
			<input type="hidden" name="item_name" value="<?php echo $row['PName'] ?>" />
			<input type="hidden" name="item_number" value="<?php echo $row['PID'] ?>" />
			<input type="hidden" name="amount" value="<?php echo $row['Pprice'] ?>" />
			<input type="hidden" name="quantity" value="1">
			<input type="hidden" name="return" value="http://www.shopbyclick.org"> 
			<input type="image" src="images/addcart.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
		</td>
	</tr>
</form> 
<?php
}
?>
</table>
</body>



Was This Post Helpful? 0
  • +
  • -

#9 Slice  Icon User is offline

  • D.I.C Addict


Reputation: 196
  • View blog
  • Posts: 591
  • Joined: 24-November 08

Re: Adding a html form to a table

Posted 29 March 2012 - 02:52 PM

This is really just a html problem as php plays not part here.

Do a little reading up on tables to get the hang of the basics, as it's really simple.

if <tr> is a row , and <td> is a column, how would you rearrange it for a horizontal display?

Sorry but if I just gave you the code again, what would you learn? :)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1