I have a problem with the search bar. I have recipes in one table and the products in those recipes are in another table. There is a Pivot Table between them and when I add or edit it works fine but the search does not work for me by the name of the product (but by the title or content of the recipe it searches for me) and throws me an error. Below gives table models, migrations and controllers. Anyone have an idea why it's not working properly? I've run out of ideas
enter image description here
enter image description here
enter image description here
enter image description here
enter image description here
enter image description here
enter image description here
Help with solving of this issue
Related
I'm designing a site where comments can be added in reply to an initial post and each comment can have attached images (and likely will given the type of content). I'm wondering how I will grab the proper comment ID to insert it into a MySQL DB column in the image table.
So far the db has a table for the initial post with serial as the primary key, the db also has an image table with id as the primary and columns for various attributes of the image as well as a column for the serial of the post images belong to (serial comes from the serial of the item the post is about), I plan to also add a column to that table for the comment ID which will be filled with the ID of the comment they belong to if they don't just belong to the initial post. I'd like to add comments in their own table with ID, info, date and title.
What I'm unsure of is when inserting a comment with attached image, how do I grab the comment ID to insert into the image table comment ID column? Or is there a better way to approach the issue?
Thanks in advance for any advice.
I write script and form for comment for my movie website but I don't know how to store each comment in his table column in database for specyfic movie.
for example,
I have to movies on this image http://prntscr.com/65wilp
So, I want when I post comment on movie 95ers Time Runners 2013 to store that comment in column for that movie, and comment for Guardians of the Galaxy 2014
in his column.
Thanks
You need more database tables. Learn more about relationships. You need two tables. Movie_table and comments_table. The relationships between two is 1:N.
This says, The ONE movie has a MANY comments.
Try put hidden input to the comment form named movie_id. If you list movies from Movie_table you can fill this input with a correct ID of movie row. Next, if you send the comment, you know the id of movie and you can make the relation of comment to movie (via foreign keys).
this can help you to make tables http://www.databaseprimer.com/pages/relationship_1tox/
and this can make you get more skills https://howtoprogramwithjava.com/database-relationships-one-to-many/
I am new to cakephp 2.x and I am have troubles figuring out how to print a value.
I have the following database relationship.
Table: Customer
id
Table: FavoriteColor
id
customer_id
color_id
Table: Color
id
name
Oh a customer page, I am displaying the customer info with all there relationships.
I am getting the list of customer's favorite color just fine. But I have the color_id being displayed but i would like to have the color Name displayed in the view.
The view has the following line:
echo $favoriteColor['color_id'];
I would like to display the color.name field ? (I am sure this has been asked 100 times.)
Do this:
debug($favoriteColor);
then, take a screenshot of the results, and post it in your question.
Likely, the solution is to do something like:
$favoriteColor['Color']['name']
But you'll have to make sure that your associations are set up correctly when you fetch $favoriteColor.
Suppose a table for products in database. Now product has an "image" field where i will place the image name "image.jpg". Now i want to display more than one images of same product. image1.jpg, image2.jpg , image3.jpg.How can i add these records into that product table in single field and how to implement it in PHP to display those images. And the same scenario in terms of size of product i.e medium, large, extra large etc.
I will assume you have already weighed the pros and cons of storing a file name instead of storing a BLOB.
This sounds like a 1-to-many relationship. You will want a table that holds -- at a minimum -- the file name and a foreign key (FK) for the product table. Then you can have multiple images pointing to the same product FK. After that, in order to get the image for a single product, you would just do a query such as:
SELECT img.fileName
FROM image_table AS img
JOIN product_table prod ON prod.id = img.prod_id
WHERE prod.id = ID_THAT_YOU_WANT
I'm ignoring issues with SQL injection, but you shouldn't. Don't just append the ID to the query.
I'm building an app where each user can have multiple profiles. Users can upload multiple photos for each profile, etc.
The folder structure will be something like
public_html/
upload/
user-123/
profile-199/
profile-321/
images/
123423.png
I'm going to have a one to many relationship between each profile and each photo, but I'm trying to see how I should flag a photo as special and the users "profile photo".
My proposed table structure is something like this
id
profile_id
filename (or maybe extension only, since filename will most likely just be the primary id for that photo)
profile (boolean field of whether this a profile pic or not)
date_added
How should I treat special images, like profile pictures?
Edit: Sorry if I wasnt clear. I want each user to be able to have multiple profiles, each profile to have many photos. Just like for Facebook, you can have many photos, but only one profile pic at any time.
That would work but it would have a problem that more than one photo could be marked as a profile photo unless you take special care to prevent this.
An alternative design is to have a table with columns user_id and special_photo_id where the photo_id is a foreign key into the photos table. This has a slightly different issue: now it is possible to have a special photo that doesn't belong to the user.
You could have a field in your users table(where its username and other info is stored) with a profile_id field init pointing to the profiles table. That way you get one possibility for the profile and away to identify it.
Thinking about it that will only work if you do have a users table and a separated profiles table.
How about the image table looks like this:
id
profile_id
filename
date_added
and add the column 'profile_image_id' in the profile table? This will be your special image's id.
I imagine you are going to have a lot more non-special images than special. So, most of the time the field 'profile(boolean)' that you proposed will be 0.
Edit: I believe #Iznogood is saying the same thing.