corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » Geek Day » MYSQL Problem(s) » Post Reply

Post Reply
Who Can Post? All users can post new topics and all users can reply.
Icon:
Formatting Mode:
Normal
Advanced
Help

Insert Bold text Insert Italicized text Insert Underlined text Insert Centered text Insert a Hyperlink Insert Email Hyperlink Insert an Image Insert Code Formatted text Insert Quoted text
Message:
HTML is Off
Smilies are On
BB Code is On
[img] Code is On
Post Options: Disable smileys?
Turn BBCode off?
Receive email notification of new replies?

Ian

posted on 14th Jan 07 at 14:21

The ASP.net bindings are just a simple way of doing it for you, same theory as you still need to get the data back to the client, just .net will automate the development process. PHP you are pretty much on your own.


liamC

posted on 14th Jan 07 at 12:18

Had a rethink on these drop down boxes and I think I'm going to do it a different way...

The company is only local so the chances of them having every single make and model car in stock is very very minimal, so ideally I need a list of makes taken from the make table that the company only has in stock, and from there the second drop down will list the models of each make that there is in stock.

Think that will be better...it's just implementing it all which is the fun!


James

posted on 14th Jan 07 at 02:48

quote:
Originally posted by Ian
Have a look how they do it. AJAX is the best approach but also the most difficult.

Dunno about PHP but in ASP.Net I would only bind data to the second dropdown (model), when the make drop down list changes, that way you can pass the make into the parameter and bind the model dropdown list to Select * From TABLE Where Make = Value passed in from first dropdown.


Ian

posted on 13th Jan 07 at 22:58

It needs two fields - the primary key integer which goes inside the value attribute of the option tag, and the name which gets displayed on the list.

The select should be more like

SELECT fldID, fldMAKE FROM tblMAKE ORDER BY fldMAKE asc


liamC

posted on 13th Jan 07 at 22:20

quote:
Originally posted by liamC
Can't get this drop down working to save my life :(

My data is coming from the table tblMAKE
The data I want listed is in the field fldMAKE

Would this be right?

code:
echo "<select name=\"Make\"><option value=\"0\">No make specified</option>";
$makequery = $db->query("SELECT fldMAKE FROM tblMAKE ORDER BY name ASC");
while($fldMAKE = $db->fetch_array($makequery)) {
echo " <option value=\"$fldMAKE[id]\">$fldMAKE[name]</option>";
}
echo "</select>";


Ian

posted on 13th Jan 07 at 22:05

Have a look how they do it. AJAX is the best approach but also the most difficult.


liamC

posted on 13th Jan 07 at 21:34

quote:
Originally posted by Ian

Your biggest problem is prohibiting the user from selecting a Ford Polo.


How would you suggest getting around this mate?

Obviously I want it so that when you choose a Ford it only lists Ford models etc, just like the Auto Trader site...


liamC

posted on 13th Jan 07 at 21:16

Yeah I changed to PHP mate but the 2 problems were as above.

I'll keep trying. Cheers


Ian

posted on 13th Jan 07 at 21:14

Thats PHP not HTML. Try it in code view.

Personally I would copy a page you already have working that has selects on and paste that code in.


liamC

posted on 13th Jan 07 at 21:01

Having trouble getting this drop down working. The first echo and the "; dont get recognised within the code by Dreamweaver. I presume that's Dreamweaver being it's normal self?

Also, how would I connect to the database so it gives me the list of results from the drop down?

Cheers for your help BTW.

[Edited on 13-01-2007 by liamC]


Ian

posted on 13th Jan 07 at 20:57

Yeah, make and model are normalised as they should be.

Your biggest problem is prohibiting the user from selecting a Ford Polo.


liamC

posted on 13th Jan 07 at 20:06

Well basically I have a make table and a model table and I am busy populating the model table bevause as you say it's massive!

I have an ID column for each make in the make table; 1 = Alfa Romeo, 2 = Audi etc, then I also have an ID column in the model table 1 = 146, 2 = 156 if you catch my drift...


Ian

posted on 13th Jan 07 at 20:06

Yeah the pages that your dropdowns appear on will have to be a PHP page so you can run the database queries on it.


liamC

posted on 13th Jan 07 at 20:04

Many thanks, I'll give it a go.

Does that code go into the on the drop down box?

Basically I have an *.HTML page with all the fields to input data, then when I click 'add vehicle' it then takes me to the PHP page with all the required info to insert the data into the table.

Will I have to make the *.HTML page into a PHP one in this case?


Ian

posted on 13th Jan 07 at 20:02

They will be two separate dropdowns though. If you want to have so you select Vauxhall then only get Vauxhall cars on the other list you'll either need to repopulate the list using AJAX (nifty but difficult), or reload the page (clunky and slow) or put the model on another page further through the application.

A problem though - model table must be quite big? Not a problem if you can WHERE on the make, but you can't do this unless the user has selected one. Need to think about how that is going to behave first before you can program it.

[Edited on 13-01-2007 by Ian]


Ian

posted on 13th Jan 07 at 20:00

So you want to fill the dropdown boxes with stuff from the database?

Easy enough, obviously you'll have to play about with the table and field names.

echo "<select name=\"make\"><option value=\"0\">No make specified</option>";
$makequery = $db->query("SELECT * FROM makestable ORDER BY name ASC");
while($make = $db->fetch_array($makequery)) {
echo " <option value=\"$make[id]\">$make[name]</option>";
}
echo "</select>";


liamC

posted on 13th Jan 07 at 19:56

You're a star mate! Working spot on, thanks alot. :D:D

One more thing which I dunno if you can help with or whether it is easy.

Basically the database is for a car company.

This section is for the staff to add new vehicles to the database for sale.

Ideally I need 2 drop down boxes for the make and model(I have 2 other tables, one for make, and one for model) where the user can choose the make and model from the menu.


Ian

posted on 13th Jan 07 at 19:51

The Extra colum needs auto_increment flag, just hadn't been set up right. Also when you're inserting, use something like

INSERT INTO tblGMD VALUES ('', '47', '23'.... etc. so the auto_increment puts the value in the first field without you supplying anything.


Ian

posted on 13th Jan 07 at 19:49

ALTER TABLE tblGMD CHANGE fldID fldID INT(15) UNSIGNED NOT NULL AUTO_INCREMENT;


liamC

posted on 13th Jan 07 at 19:42


Ian

posted on 13th Jan 07 at 19:38

Run that command.


liamC

posted on 13th Jan 07 at 19:32

Yeah I have an auto incremement key (called fldID) which I want it to give it an automatic ID to each row but I can't get it generating its own ID.

I take it that this is the problem?

[Edited on 13-01-2007 by liamC]


Ian

posted on 13th Jan 07 at 19:29

Do you have an auto_increment primary key? Show me the output to:

SHOW FIELDS FROM tablename;


liamC

posted on 13th Jan 07 at 19:22

Made a mysql database with tables etc which is all fine and up and running.

Made an HTML/PHP page to input data into the database and I inputted one row into the table with about 8 fields with no bother whatsoever...yay!:D ....BUT now it won't let me add anything else to the database other than one row! :boggle: I can delete the one row of data I have in and add another one with no bother...but I can't add anymore than one! :|

Any ideas? Maybe just a quick option I haven't enabled/disabled? :boggle: