Need help with PHP code to populate a database table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nfdan
Forum Newbie
Posts: 3
Joined: Fri Sep 21, 2007 10:02 am

Need help with PHP code to populate a database table

Post by nfdan »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi. I have a mysql table that looks like this:

[syntax="sql"]
CREATE TABLE `jos_vm_coupons` (
  `coupon_id` int(16) NOT NULL auto_increment,
  `coupon_code` varchar(32) NOT NULL default '',
  `percent_or_total` enum('percent','total') NOT NULL default 'percent',
  `coupon_type` enum('gift','permanent') NOT NULL default 'gift',
  `coupon_value` decimal(12,2) NOT NULL default '0.00',
  PRIMARY KEY  (`coupon_id`)
) 
Its a table that stores unique coupon codes to be used for Joomla's Virtuemart online store. I need to add something like 4000 permanent coupons and dont want to do this manually.

Can someone provide me with a sample script I can use in PHP that will insert new coupons with the coupon code starting at 0001 up to 4000?

any help would be appreciated.


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You hopefully already have the data needed for the fields, so the PHP isn't really complicated.. simply a loop with an INSERT query really. We can't provided much if we don't know what data you have and don't have, nor is it generally our policy to simply write the code for someone. Where's the learning in doing so?

We'll gladly help you write it, however.
nfdan
Forum Newbie
Posts: 3
Joined: Fri Sep 21, 2007 10:02 am

Post by nfdan »

thanks.

the data would be as follows:

coupon id=1
coupon_code=0001
percent_or_total=total
coupon_type=permanent
coupon_value=0.00


coupon_id and coupon_code would increment by one up until 4000 and the other values stay the same throughout.



I also actually have an excel spreadsheet with all the data already if that is easier. I evenetually want to add a completely new field in this table for "name" and then populate each coupon_id with a name from the excel spreadsheet
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What's the point of having database records to cover them if they are all the same (excluding the coupon code)? They could be done programmatically.. or by some other means, but 4000 records of the same just feels way off..
nfdan
Forum Newbie
Posts: 3
Joined: Fri Sep 21, 2007 10:02 am

Post by nfdan »

We are giving out one coupon code each to 4000 different organizations and each purchase they make they enter the code. Using this to track certain types of orders for affiliates.

Each purchase made by one orginization uses the same code every time. the back end of e0-commerce virtuemart i can list all the coupons and how many times they were used etc.

The backend pulls the coupon codes and stats from the database
Post Reply