Infect Posted July 1, 2009 Share Posted July 1, 2009 OK i'm stumped here. I don't know much PHP so i need some help from all you smart coders out there 1. What i want to do, is send a customer to a URL, and on that URL, i just want it to print a single item from an array. Once that item has been printed, i want to move it to a different array (ie: from $itemsToPrint to $itemsNotToPrint). I have the array configured fine, the problem is i don't know how to figure out which items have been selected and i dont know how to move the selected items to another array. Apparently i also need to set up a MYSQL Database to keep track of what has and has not been selected and used. Unfortunately i'm not very familiar with MYSQL either, i pretty much just understand a bit of PHP MyAdmin... 2. Also, i want to make sure that each ip address can only do this once by giving them a cookie or something (so that they can't repeatedly steal more and more item codes by simply refreshing the page or something), or even better if i could do something with the url to make each item in the array have it's own url or be able to mask the real url. Any help would be greatly appreciated! Thanks, Infect Quote Link to comment Share on other sites More sharing options...
rhodesa Posted July 1, 2009 Share Posted July 1, 2009 Here is a great place to learn more about PHP: http://devzone.zend.com/node/view/id/627 Specifically the MySQL part: http://devzone.zend.com/node/view/id/641 You will want to have all the items in a table in your database. Then either assign them before the email is sent, or assign them as users visit the page. Quote Link to comment Share on other sites More sharing options...
btherl Posted July 1, 2009 Share Posted July 1, 2009 Infect, you'll need to get some experience with mysql first. Also your description is a bit too vague. Can you say what this is for? The best solution depends on the task. Quote Link to comment Share on other sites More sharing options...
Infect Posted July 1, 2009 Author Share Posted July 1, 2009 MMkay well the starting array contains lots of codes (ie: 1M0zzl2apr4 or something seemingly random like that) and i want the user to access the page, have it print just ONE of the codes in the array, and once that code has been printed, i want to move it to a different array (ie: From $itemsToPrint TO $itemsNotToPrint) Does that clarify a bit more? Quote Link to comment Share on other sites More sharing options...
btherl Posted July 1, 2009 Share Posted July 1, 2009 I think you could implement it something like this: CREATE TABLE item_codes ( id serial, code text ); CREATE TABLE ip_item_codes ( item_id bigint, ip text, date_fetched datetime ); "id" is an integer uniquely identifying each item. ip_item_codes records which items have been given to which ip address, and at what time. This is assuming you use ip address to uniquely identify your users (which is fraught with problems). Each time you give out an item you can store a row in ip_item_codes. Then you can refuse to give more items if that ip has a row in that table with date_fetched less than 24 hours ago. This is not an ideal solution but it's a start. This also allows you to check that someone has been given an item code when they try to use the item, as you can check in the ip_item_codes table. Quote Link to comment Share on other sites More sharing options...
Infect Posted July 1, 2009 Author Share Posted July 1, 2009 ok, well i created the table fine, now i've used this code: mysql_query("CREATE TABLE item_codes ( id serial, code text );"); while($row = $result) { echo "ID :{$row['id']} <br>" . "CODE : {$row['code']} <br>"; } and it won't echo what i want it do...obviously something wrong with my command but idk what it is? What i want to do now is just echo every single item in my table. Quote Link to comment Share on other sites More sharing options...
btherl Posted July 2, 2009 Share Posted July 2, 2009 This command is done once only, to create a place to store data (called a "table"): $sql = "CREATE TABLE item_codes ( id serial, code text )"; $result = mysql_query($sql); if (!$result) die("Query $sql failed: " . mysql_error()); Then this query is done each time you want to fetch data from the table $sql = "SELECT * FROM item_code"; $result = mysql_query($result); f (!$result) die("Query $sql failed: " . mysql_error()); while($row = mysql_fetch_array($result)) { echo "ID :{$row['id']} <br>" . "CODE : {$row['code']} <br>"; } But first you will need to add some data, otherwise you'll get nothing from that SELECT query: $sql = "INSERT INTO item_code (code) values ('foo')"; $result = mysql_query($result); if (!$result) die("Query $sql failed: " . mysql_error()); Once those ones are working you can add some more data and start looking at the "WHERE" clause from SELECT. Quote Link to comment Share on other sites More sharing options...
Infect Posted July 2, 2009 Author Share Posted July 2, 2009 ah ok great thx. So now i have the table built and everything is entered correctly. The problem now is, i want to only display one randomly from the list, and then once it's displayed, move it to a new table (table already created). How would i go about doing this? Quote Link to comment Share on other sites More sharing options...
btherl Posted July 2, 2009 Share Posted July 2, 2009 The easiest way to pick a random one is to generate a random number in php. You can find the highest code with "SELECT max(code) FROM item_codes", with the result being named "max". There's also a thread in the mysql subforum here about choosing random rows from mysql, but it's a little complex. Quote Link to comment 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.