php mysql one to many relationship or something else? - php

I am trying to figure out what to do from here. I am using mysql for my database.
In my form from mysql I wish to have the possibility for people to upload from 1 to many images that can be queried along with the data submitted in the form. I am not asking for someone to write me the code, but to point me in the right direction of what type of solution I can use or what I can read on to learn to get this done.
User example here:
1. a registered user is filling out a form for example a car for sale ad.
2. user wishes to upload images relating to that car sale ad.
3.if the user fills out the car for sale form and clicks submit/next.How to display the form the user just clicked submit in the next page to appear,so the user can add images there/here?
I hope someone can point me in the right direction or can give me their input on what else I can read on to do this.
Thank you in advance

Personally when I start having to get into complex HABTM relationships and the what I want to use an ORM. I personally use CakePHP's. It has a very robust relational mapping system (HasMany, HasOne, BelongsTo, HasAndBelongsToMany) which is a bit of a pain to learn to do in SQL your self.
If you don't have access to a server with the right php modules 3.0 can be a pain to install, but 2.0 has a really nice RubyOnRails style ActiveRecord system too.

Related

PHP - Insert as draft

I'm building a CRM and I have a list of customers.
When I create a customer, I usually insert it as a draft as soon as the user clicks on "Insert button". Why? Because I want the user to be able to insert photos and documents on the insertion form. This way, I have the customer ID already and I can process the upload using that ID.
The problem here is that we can have multiple drafts at a certain moment.
My question is: is there any better method to do this? Without creating the draft? For instance, using a temp folder where the photos and documents are temporarily saved?
EDIT:
the issue woth having multiple drafts is that at certain point will may have a lot of trash.
I mean, this works for me ok? And it's a solution I have, I just wanted to know if there's a better solution instead of using drafts.
It depends on what exactly you are using to save the customer in the database.
If you are using an ORM such as Eloquent or Doctrine you just need to have the correct relationships between Entities and you won't need to save the Customer as draft, you can just flush all of the information at once.
If you aren't using an ORM, you can still do it in one request, just insert the Customer record first and get the last inserted ID , for example if using PDO, you can use PDO::lastInsertId https://www.php.net/manual/en/pdo.lastinsertid.php .
After you have the ID just set it to the other columns where you need it.

Best way to get data from non-admins internal to an organization in Wordpress

Here's the scenario:
I want to display a music playlist for each DJ at a radio station on my Wordpress site, but I don't want to have to enter that data in (Each song, artist, album, etc), in a specific custom post type or something like that.
I want each DJ to have access to a form where they can enter the playlist data in, and I can use that data. I was thinking of making a little webpage form that they can access, and then I query the database to get all that stuff, but I imagine that maybe there is an easier way using Wordpress.
The thing is, I don't want to give each DJ admin access to make posts with those custom fields filled in, so I'm not sure if there's a way to do that.
Maybe a page on the website that is password protected to fill out the form, and then I can use that data in a different page on the site? (Password protected so I'm only receiving data from actual DJs, not random people or bots.)
Sorry if this is an ignorant question, or if I'm unclear.
I searched a little bit, and couldn't find much.
Thanks in advance for ideas and insight!
You need to decide your method for doing this and try it out, when you run into a problem then you post here. It sounds like you know what you need. You're looking for a password protected form (which will check against a database) and pages based on a query to the database. This can be done in PHP or you might be able to find a Wordpress plugin to help you out.
Maybe start by making the PHP form. Then you could add the password protection. After you have that working you could make the PHP page that would query the information submitted. Take it one step at a time. It'll be much easier for people to help you if you're troubleshooting a specific issue rather than trying to figure out the logistics of how the whole system will work.

Tag-like skills in a user profile with a HABTM relationship

In the web application I'm building a user has a profile where they can list their skills. I would like the kind of functionality StackOverflow has when making posts, where you can type tags into the tag input and select ones that already exist, and create them if they don't already exist.
At the moment, I've got a select box appearing on the page with with the id of the users current skills as values. I'm achieving this by doing:
// ProfilesController.php
$skills = $this->Profile->ProfilesSkill->find('list');
// edit.ctp
<?php echo $this->Form->input('Skill', array('value' => $skills)); ?>
I've got no idea how to progress further, though. First of all, the name field for the skills should be shown instead of their id, which I'm confused about because by Cake's convention it will use the name field by default, even though it's not. And secondly when I enter my skills into my profile Cake should automatically make all the required entries in the profiles_skills table. How can I make that work?
The solution is pretty straight forward, though it's pretty much work.
First you'll need a Tag-System. You could build one on your own (like any habtm-relation), or use a plugin like https://github.com/CakeDC/tags
For the second part, the function is called "Autocomplete". It's basically a ajax call every time you enter a letter in a form field. There are a bunch of tutorials out there, e.g: http://blogfreakz.com/cakephp/cakephp-jquery-autocomplete-tutorial/
Hope this points you in the right direction

symfony2 forms and many-to-many relations

I thought I'd see if anyone could point me in the right direction here - I have a users table and a contents table, and I want to keep track of what user is authorized to edit what content.
Thinking in a relational database way, a many-to-many relation table is the solution, adding rows of user_id & content_id for each authorization.
Many users can be authorized to edit a content piece, and a user is also of course able to have access to more than one content piece.
Now, the biggest issue I see (being a Symfony2 novice) is the admin form where an admin must be able to set these permissions, preferrably with a list of contents and checkboxes next to them, and have the form processor take care of the adding/deleting rows to that relationsl table.
Is the collection form field the right way to go here?
Any help is much appreciated.
I think the Doctrine2 documentation on Many-to-Many relations already gives you an answer on that question how to map the data.
The form issue is already explained in another SO question.

Insert and select from MySQL database

Every user that signs up for the site is given a user id (stored in the database as User_ID), I am using userCake for the login/user management system just to clarify.
I am quite new to MySQL and PHP. I am trying to create a way so that a user can input a link into a form (I have the form created) and then it saves that to the database (new table?). How would I go about;
Creating the table structure for that.?
Posting the URL to the database.?
Retrieving all of the links associated with the User ID.?
Displaying all the users links in a list (a list just for testing)?
I have looked around for some time but can't seem to find anything that helps. All help is greatly appreciated.
i think maybe http://www.sitepoint.com/getting-started-mysql/
other resources are available, I tried "beginning database driven php website" in fav search engine and there is tons and tons of the stuff, i dont think the actual teaching etc can be done in a single post on SO and maybe you should learn to create tables, and query them with a query tool. once you got that you can then do your first php hello world app. create a hello world form then finally hook up database and start then looking at DB security etc.

Categories