Jump to content

Help inserting data into table


galone

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/51428-help-inserting-data-into-table/
Share on other sites

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.

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.

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.

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.

Archived

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

×
×
  • 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.