Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

New Code for viewing prices


Babysweet

Recommended Posts

I am not a great php writer so if you can lead me to the right direction I would appriciate it.

 

This is what I am trying to do:

 

By the time I finish I will have near a thousand products listed. I need a simple way to view and edit prices of all the products.

 

I have the view down. here is its code:

 

<?php
// Make a MySQL Connection
mysql_connect("localhost", "myusername", "mypassword") or die(mysql_error());
mysql_select_db("mydatabase") or die(mysql_error());

// Get all the data from the "products " table
$result = mysql_query("SELECT * FROM products ") 
or die(mysql_error()); 

echo "<table border='1'>";
echo "<tr> <td>Product ID</td> <td>Product Model</td> <td>Product Price</td> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>"; 
echo $row['products_id'];
echo "</td><td>"; 
echo $row['products_model'];
echo "</td><td>"; 
echo $row['products_price'];
echo "</td></tr>"; 
} 
echo "</table>";

?>

Now this works fine I am able to view all the products and there prices in a condenced page.

 

I want to be able to edit individually and an option to effect all prices by a percentage.

 

I know I will need a text field, submit button, and I know the sql code to make edits.

which is:

UPDATE products SET products_price='20.00' WHERE products_id='1';

 

my problem is putting it all together.

 

I know its wrong to ask you to write my code, so I am going to try my best here to put everything together, but I know it won't work, because I simply don't know enough.

 

 

 

<?php
// Make a MySQL Connection
mysql_connect("localhost", "myusername", "mypassword") or die(mysql_error());
mysql_select_db("mydatabase") or die(mysql_error());

// Get all the data from the "products " table
$result = mysql_query("SELECT * FROM products ") 
or die(mysql_error()); 

echo "<table border='1'>";
echo "<tr> <td>Product ID</td> <td>Product Model</td> <td>Product Price</td> <td>Change price</td><td>submit change</td></tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>"; 
echo $row['products_id'];
echo "</td><td>"; 
echo $row['products_model'];
echo "</td><td>"; 
echo $row['products_price'];
echo "</td><td>";
echo"<form action="changeprice.php" method="post"><input type="text" name="productprice">';
echo"</td><td>";
echo"<input type="Submit"></form>";

echo"</td></tr>"; 
} 
echo "</table>";

?>

 

The code in the changeprice.php would have the sql query with the new variables but I am simply lost on how to do that.

 

am I even on the right track?

 

thanks

Joe

Sincerely,

Joseph Seabert

Link to comment
Share on other sites

Well I had and I did see that but the problem with that is its too much. I didn't want all that. just what I asked for. I only wanted a page that was simple and didn't require modifying the database or other files. Just something simply viewed the fields I stated, and allowed the ability to change them. that's ok, I'll figure it out. thanks for your reply.

Joe

Sincerely,

Joseph Seabert

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...