Jump to content

Noob needs help with forms


KingSpongo

Recommended Posts

Hey all,

 

I'm trying to make a system where registered users are allowed to select products from a database. So far I have made a working registration form and populated the tables inside the mySQL database. There is the customer and the product tables which have fields like customer_No, customer_Name, product_No, product_Name etc. I have also made queries to show all the products in a ordered list within IE. What I want to do is be able to query all the products and allow a user to select them so when a customer looks at the products it will show a name next to it. e.g.:

 

(Product No)1(Product)Car(Product Description)Blue 4x4(Customer Name)John

 

I want the system to show all the products and if a customer is using any of them. Is there a tutorial out there that can help me because I'm having no luck finding what I need. I appreciate any help.

 

Thanks  :)

 

Link to comment
Share on other sites

  • 2 weeks later...

Bump. 

 

I think my question wasn't clear on what i want to do  :-\

 

I want to make a page similar to this drawing:

examplexj.jpg

 

I want the page to list all the products in the mysql database and allow the user to select one so it shows the customers name next to it like in the image. Can anyone recommend a tutorial that can help me achieve this?

 

Thank you for your help

Link to comment
Share on other sites

$q = "SELECT product_id, product_name, product_desc, product_cust FROM tblProducts ORDER BY product_id ASC";

$r = @mysqli_query ($dbc, $q);  // $dbc is your database details, you will need to define this somewhere, maybe seperate file //

$num = @mysqli_num_rows($r); // this will count the number of rows in your products table //

if ($num > 0) { // if there are more than 0 rows it will tell user how many rows there are //

echo "<p>There are currently $num products.</p>\n";

echo '<table align="center" cellspacing="3" cellpadding="3" width="85%">

<tr>

<td align="left"><b>Product ID</b></td>

<td align="left"><b>Product Name</b></td>

<td align="left"><b>Product Description</b></td>

<td align="left"><b>Username</b></td>

</tr>';

while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {

echo '<tr>

<td align="left">' . $row['product_id'] . '</td>

<td align="left">' . $row['product_name'] . '</td>

<td align="left">' . $row['product_desc'] . '</td>

<td align="left">' . $row['product_cust'] . '</td>

</tr>';

}

echo '</table>';

mysqli_free_result ($r);

} else {

echo '<p>There are currently no products.</p>'; // otherwise it will tell the user there are no products in the table //

}

 

Is this what you want?

Link to comment
Share on other sites

Thank you for the reply Sherryar. I need the page to show every product in the table (which is always going to have products inside).

 

What I want to do is click on a product and put my username next to it like in row 2 of my drawing. So when someone opens the page they will see that I have that certain product.

 

Basically the page will show all the products in the table and who has them.

 

 

Link to comment
Share on other sites

ok, I think this is a database question, but anyway:

 

to show all products and the features simply you can use this simple query:

 

$query = "SELECT * FROM products"

 

To select only the products that a certain customer is using then you basically mean by that:

each customer can select many product(s)

each product can be selected by many customer(s)

 

here you need to add another table named customer_product that has two fields:

customer_id

product_id

they have the id's of the customers and the products attached to each other and attach the other two tables to them in your queries.

the table should look like this after inserting some records:

customer_id: 2  4  5    2

product_id:  5  1  2    1

 

means the customer number 2 took the products number 5 and 1

the product number 1 was taken by the customers numbered 2 and 4

 

I don't really know any tutorial that explains this, but I think I explained it clearly, if not then let me know what is hard to understand and I will explain it to you.

 

Good luck!

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.