html - PHP unknown column number
I have a small issue I ran into and would like to figure out the logic behind it. On my website, I have a form where admin will submit various info regarding a user, including some links. Now, I have no idea how many links there will be, maybe 5, maybe 35. Point is I don't know the upper limit, so how would I go about making that form? Here's an idea that might work:
Once add customer form is open, I'll have the admin type in the number of links for submission; Based on that number, input fields would be created; PHP will then check if columns already exist, if not, it will create & submit them; Display page for customer will then select * from data and display it accordingly;
Here's what I don't know how to pull off here: How do I create X input fields based on number X? How do I make php add columns like this: Link1, Link1status (predefined), Link2, Link2status (predefined). etc? How do I make the display page for customer echo only the number of links present in a similar fashion: Link1: $Link1 Link1status: $Link1status etc.
I'm not looking for you to write the code for me, I'm just having issues with logic where I need to create html based on some number.
Thank you for your help! Best Fisher
Just have a button to "add another link":
Then you can pull the data from all link fields.
You can make two separate tables, one with the users, one with all links.
Example: you have the user 'John Doe' with three properties, let's say hair color (brown), length (180 cm) and weight (80 kg), you get this:
You can apply this on your system. If you want to get all links of an user, just search in the 'links' table with the 'user_id'.
To make a form for the insertion of this records, use a table with one starting row and a hidden row with empty inputs. A user can add more rows with inputs to add links (you can use jQuery's
clone()function to copy the hidden row with empty inputs). You can use
name=array(with the inputs) to get an array result after POST.
explodefunction to get the links before add them to the database or whatever you want to do with them.