galone Posted May 15, 2007 Share Posted May 15, 2007 I have a table, and I want to insert the data: Name Type (so that's Name, then two spaces, then type) However, my table has more than two kinds of data (such as id auto increment, location, etc) ... but I want it to autoincrement for id, and leave the other values blank. What's the best way to do this? here's an example: CREATE TABLE `people` ( `id` int(3) NOT NULL auto_increment, `name` var(50) NOT NULL. `type` varchar(100) NOT NULL, `location` varchar(500) NOT NULL, And I have the following data: Albert Cool Joanne Lazy Jim Bored So: insert into `people` (x, albert, cool, blank) ... etc. So in the end, I want to convert Albert Cool into the insert into, then process it into the database with x increasing everytime for the person, however leaving location blank. I'm sorry if it confuses you. How would I do this? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/51428-help-inserting-data-into-table/ Share on other sites More sharing options...
bubblegum.anarchy Posted May 15, 2007 Share Posted May 15, 2007 Any fields that will potentially be left blank should be declared as NULL i.e.: CREATE TABLE `people` ( `id` int(3) NOT NULL auto_increment, `name` var(50) NOT NULL. `type` varchar(100) NOT NULL, `location` varchar(255) NULL DEFAULT NULL ); The following insert would set location to NULL and id to the next auto_increment value: INSERT INTO people (name, type) VALUES ('Albert', 'Cool'); NOTE: I am pretty sure that varchar has a max length of 255 - varchar(500) is likely to be trimmed anyway but is also misleading. Quote Link to comment https://forums.phpfreaks.com/topic/51428-help-inserting-data-into-table/#findComment-253311 Share on other sites More sharing options...
galone Posted May 15, 2007 Author Share Posted May 15, 2007 Thanks. Also, how would I arrange them in alphanumeric order? Like for example: $result = mysql_query("SELECT id, name, category, description, website, contact, email, moment FROM clubs"); echo '<TABLE border="1"><TR><TH>Club<TH>Category<TH>Website<TR>'; while ($row = mysql_fetch_array($result)) { echo '<TH><p align="left">', $row{'name'}; echo '</p><TD><p align="center">', $row{'category'}; echo '</p><TD>', $row{'website'}, '<TR>'; } echo '</TABLE>'; How would I make it so that once I make the Club/Category/Website clickable, it will go ascending? Then if clicked again, descending? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/51428-help-inserting-data-into-table/#findComment-253339 Share on other sites More sharing options...
bubblegum.anarchy Posted May 15, 2007 Share Posted May 15, 2007 By adding an ORDER BY clause... Quote Link to comment https://forums.phpfreaks.com/topic/51428-help-inserting-data-into-table/#findComment-253480 Share on other sites More sharing options...
galone Posted May 15, 2007 Author Share Posted May 15, 2007 Thanks. Also (sorry for the questions), basically all the names of the clubs are listed in a drop down that I made: $res=mysql_query("SELECT name FROM clubs ORDER BY name ASC"); if(mysql_num_rows($res)==0) echo "There is no data in table."; else for($i=0;$i<mysql_num_rows($res);$i++) { $row=mysql_fetch_assoc($res); echo"<option>$row[name]</option>"; Now, how do I make it so that echo "<input type=submit value=Edit>"; is added, it can trace the specific name and data, and make them into variables to show so you can edit them in textboxes? Some sort of query but I can't remember... Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/51428-help-inserting-data-into-table/#findComment-253808 Share on other sites More sharing options...
bubblegum.anarchy Posted May 16, 2007 Share Posted May 16, 2007 I do not understand your question, galone. Quote Link to comment https://forums.phpfreaks.com/topic/51428-help-inserting-data-into-table/#findComment-254213 Share on other sites More sharing options...
fenway Posted May 18, 2007 Share Posted May 18, 2007 Now, how do I make it so that echo "<input type=submit value=Edit>"; is added, it can trace the specific name and data, and make them into variables to show so you can edit them in textboxes? Some sort of query but I can't remember... Thanks again. This sounds like a PHP question. Quote Link to comment https://forums.phpfreaks.com/topic/51428-help-inserting-data-into-table/#findComment-256661 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.