Author Topic: Noob needs help with forms  (Read 424 times)

0 Members and 1 Guest are viewing this topic.

Offline KingSpongoTopic starter

  • Irregular
  • Posts: 15
    • View Profile
Noob needs help with forms
« on: January 27, 2010, 12:49:45 PM »
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  :)

Offline KingSpongoTopic starter

  • Irregular
  • Posts: 15
    • View Profile
Re: Noob needs help with forms
« Reply #1 on: February 09, 2010, 09:39:10 AM »
Bump. 

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

I want to make a page similar to this drawing:


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

Offline Sherryar

  • Irregular
  • Posts: 6
    • View Profile
Re: Noob needs help with forms
« Reply #2 on: February 09, 2010, 10:37:06 AM »
$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($rMYSQLI_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?
« Last Edit: February 09, 2010, 10:37:58 AM by Sherryar »

Offline KingSpongoTopic starter

  • Irregular
  • Posts: 15
    • View Profile
Re: Noob needs help with forms
« Reply #3 on: February 09, 2010, 12:09:03 PM »
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.


Offline KingSpongoTopic starter

  • Irregular
  • Posts: 15
    • View Profile
Re: Noob needs help with forms
« Reply #4 on: February 09, 2010, 02:52:50 PM »
I've been looking everywhere and cant find anything that can help. Would this be better if it was in the mysql forum?

Offline Hussam

  • Enthusiast
  • Posts: 63
  • Gender: Male
  • Available for projects in PHP, Flash, and Cakephp.
    • View Profile
    • My Personal Page, as sexy and small as possible!
Re: Noob needs help with forms
« Reply #5 on: February 09, 2010, 08:41:04 PM »
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!
« Last Edit: February 09, 2010, 08:41:35 PM by Hussam »
A lie can travel halfway around the world while the truth is putting on its shoes.

http://tutorialtip.com/About_Me/

Offline redarrow

  • Freak!
  • Posts: 8,150
  • Gender: Male
  • PHP IS FOR LIFE!
    • View Profile
    • my free dating site (a blind php programmer!)
Re: Noob needs help with forms
« Reply #6 on: February 09, 2010, 08:46:51 PM »
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.ath.cx/paypal_info/paypal1_info.inc