PHP - Mysql Architecture
Hello, I have a table with people and some details insde. So, my question is if my MySQL architecture down below is good or not. Should I devide the table into two tables and kept only p_id, p_name and p_slug inside my table (people_tbl). Thank you!
p = person
people_tbl +------+---------+---------+---------------+-------------+-------------------+-----------+------------+---------+ | p_id | p_name | p_title | p_description | p_seo_title | p_seo_description | p_country | p_category | p_slug | +------+---------+---------+---------------+-------------+-------------------+-----------+------------+---------+ | 1 | John Li | title | johns bio | 70 charsets | 170 charsets | Germany | 1 | john-li | | 2 | Bob Stu | title | bobs bio | 70 charsets | 170 charsets | Italy | 2 | bob-stu | +------+---------+---------+---------------+-------------+-------------------+-----------+------------+---------+ Edited February 16, 2020 by mactron Similar TutorialsThis topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=318519.0 good evening folks, i have a question regarding the foreach syntax when needing to access something say 3 levels deep into the json architecture here's the example I'm trying to accomplish but when echoing it's not returning the value i need from 3 levels deep. I believe i just don't understand the correct syntax so here's the example any help would he sincerely appreciated.
https://pastebin.com/mEBiMUW5 create table mimi (mimiId int(11) not null, mimiBody varchar(255) ); <?php //connecting to database include_once ('conn.php'); $sql ="SELECT mimiId, mimiBody FROM mimi"; $result = mysqli_query($conn, $sql ); $mimi = mysqli_fetch_assoc($result); $mimiId ='<span>No: '.$mimi['mimiId'].'</span>'; $mimiBody ='<p class="leading text-justify">'.$mimi['mimiBody'].'</p>'; ?> //what is next? i want to download pdf or text document after clicking button or link how to do that Hello everyone, Sorry if this has been answered but if it has I can't find it anywhere. So, from the begining then. Lets say I had a member table and in it I wanted to store what their top 3 interests are. Their$ row has all the usual things to identify them userID and password etc.. and I had a further 3 columns which were labled top3_1 top3_2 & top3_3 to put each of their interests in from a post form. If instead I wanted to store this data as a PHP Array instead (using 1 column instead of 3) is there a way to store it as readable data when you open the PHPmyadmin? At the moment all it says is array and when I call it back to the browser (say on a page where they could review and update their interests) it displays 'a' as top3_01 'r' as top3_02 and 'r' as top3_03 (in each putting what would be 'array' as it appears in the table if there were 5 results. Does anyone know what I mean? For example - If we had a form which collected the top 3 interests to put in a table called users, Code: [Select] <form action="back_to_same_page_for_processing.php" method="post" enctype="multipart/form-data"> <input name="top3_01" type="text" value="enter interest number 1 here" /> <input name="top3_02" type="text" value="enter interest number 2 here" /> <input name="top3_03" type="text" value="enter interest number 3 here" /> <input type="submit" name="update_button" value=" Save and Update! " /> </form> // If my quick code example for this form is not correct dont worry its not the point im getting at :) And they put 'bowling' in top3_01, 'running' in top3_02 and 'diving' in top3_03 and we catch that on the same page with some PHP at the top --> Code: [Select] if (isset($_POST)['update_button']) { $top3_01 = $_POST['top3_01']; // i.e, 'bowling' changing POST vars to local vars $top3_02 = $_POST['top3_02']; // i.e, 'running' $top3_03 = $_POST['top3_03']; // i.e, 'diving' With me so far? If I had a table which had 3 columns (1 for each interest) I could put something like - Code: [Select] include('connect_msql.php'); mysql_query("Select * FROM users WHERE id='$id' AND blah blah blah"); mysql_query("UPDATE users SET top3_01='$top3_01', top3_02='$top3_02', top3_03='$top3_03' WHERE id='$id'"); And hopefully if ive got it right, it will put them each in their own little column. Easy enough huh? But heres the thing, I want to put all these into an array to be stored in the 1 column (say called 'top3') and whats more have them clearly readable in PHPmyadmin and editable from there yet still be able to be called back an rendered on page when requested. Continuing the example then, assuming ive changed the table for the 'top3' column instead of individual colums, I could put something like this - Code: [Select] if (isset($_POST)['update_button']) { $top3_01 = $_POST['top3_01']; // i.e, 'bowling' changing POST vars to local vars $top3_02 = $_POST['top3_02']; // i.e, 'running' $top3_03 = $_POST['top3_03']; // i.e, 'diving' $top3_array = array($top3_01,$top3_02,$top3_03); include('connect_msql.php'); mysql_query("UPDATE members SET top3='$top3_array' WHERE id='$id' AND blah blah blah"); But it will appear in the column as 'Array' and when its called for using a query it will render the literal string. a r r in each field instead. Now I know you can use the 'serialize()' & 'unserialize()' funtcions but it makes the entry in the database practically unreadable. Is there a way to make it readable and editable without having to create a content management system? If so please let me know and I'll be your friend forever, lol, ok maybe not but I'd really appreciate the help anyways. The other thing is, If you can do this or something like it, how am I to add entries to that array to go back into the data base? I hope ive explained myself enough here, but if not say so and I'll have another go. Thanks very much people, L-PLate (P.s if I sort this out on my own ill post it all here) I have following piece of code below, and I would like to be able to express it pure SQL, something that could go into a .sql file :
$request_string='SELECT topic_forum_id FROM topic_table WHERE topic_id= 2014'; $query=database->prepare($request_string); $query->execute(); $data=$query->fetch(); $query->closeCursor(); $forum=$data['topic_forum_id']; $request_string='INSERT INTO post_table (post_topic,post_forum) VALUES (2014,:forum)'; $query=database->prepare($request_string); $query->bindValue(':forum',$forum,PDO::PARAM_INT); $query->execute(); $data=$query->fetch(); $query->closeCursor();Is it possible ? So i have this php as shown below. It should make a list of comments with comment replies below their comment respectively. The problem is that it only goes through and shows 1 comment and all the comment replies for that one comment. It should be showing all comments i have in the db for that article. If i remove the second while then it shows all the comments correctly but no comment replies then... How do i get this script to loop through the db for every comment but also loop through every comment reply for that $row[id]? If anyone has a better / more efficient way of what I am trying to do, please explain or show example (i am open to anything)... Code: [Select] // what article are we showing? $article_to_show_id = $_GET['article_id']; $active_is_set_text = "1"; // Active Column text that makes it okay to show // Finding the article $search_for_article = mysql_query("SELECT * FROM articles WHERE id = '$article_to_show_id' AND active = '$active_is_set_text'"); while($row = mysql_fetch_array($search_for_article)) { // format the last updated date right $update_date_edit = $row[update_date]; $update_date_edit = date('F j, Y \a\t h:ia', $update_date_edit); $row[update_date] = $update_date_edit; // format the submit updat date right $submit_date_edit = $row[submit_date]; $submit_date_edit = date('F j, Y \a\t h:ia', $submit_date_edit); $row[submit_date] = $submit_date_edit; echo ' <div> ', $row[title] ,' </div> <div> by: ', $row[author] ,' on ', $row[submit_date] ,' </div> <div> ', $row[content] ,' </div> <div> Last Updated: ', $row[update_date] ,' </div> <form action="article_reply.php" method="post"> <input type="hidden" name="article_id" value="', $row[id] ,'" /> <button name="article_reply" type="submit" value="submit">Reply</button> </form> '; } $comment_count = 0; $comment_reply_count = 0; // Finding all of the comments $search_for_article = mysql_query("SELECT * FROM article_comments WHERE article_id = '$article_to_show_id' AND reply_id = '0'"); while($row_comment = mysql_fetch_array($search_for_article)) { // format the submit updat date right $comment_date_edit = $row_comment[comment_date]; $comment_date_edit = date('F j, Y \a\t h:ia', $comment_date_edit); $row_comment[comment_date] = $comment_date_edit; echo ' <br> <br> COMMENT:<br> <div> By: ', $row_comment[username] ,' on ', $row_comment[comment_date] ,' </div> <div> ', $row_comment[comment] ,' </div> '; $comment_count++; // Finding all of the comment replies if any $search_for_article = mysql_query("SELECT * FROM article_comments WHERE article_id = '$article_to_show_id' AND reply_id = '$row_comment[id]'"); while($row_two = mysql_fetch_array($search_for_article)) { // format the submit updat date right $comment_date_edit = $row_two[comment_date]; $comment_date_edit = date('F j, Y \a\t h:ia', $comment_date_edit); $row_two[comment_date] = $comment_date_edit; echo ' <br> <br> COMMENT REPLY:<br> <div> By: ', $row_two[username] ,' on ', $row_two[comment_date] ,' </div> <div> ', $row_two[comment] ,' </div> '; $comment_reply_count++; } } Need some help I have 2 tables in a database and I need to search the first table and use the results from that search, to search another table, can this be done? and if it can how would you recommend that I go about it? Thanks For Your Help Guys! hello every one
I have some queries in mysql command..
I have a table schema like this
id | name | url | img1 | img2 | img3 | img4|
I want to randomly rotate the image by specific id....
suppose the select the id = 1, then the four images will be rotated randomly for with the tha id (i.e id = 1)
Any help wil greatly appreciated
Thank u.....
I'm having trouble working out a mysql query. I have two tables called "content" and "providers". Content Table content_id content_provider 1 Provider 1 2 Provider 2 3 Provider 1 Providers Table provider_name provider_url Provider 1 www.provider1.com Provider 2 www.provider2.com What I want to do is to select all of the information in the "providers" table but also to perform a count on the "content" table to get the number of content for each provider. So in this case it would show all of the information for provider 1 and also show that provider 1 has 2 pieces of content because they have 2 entries in the "content" table. I am able to get these results as two separate queries but I was wondering if it was possible to do it in one query. Thanks for any help. Hi im having problems with this can any one point me the right way please Code: [Select] if(isset($_GET['pageID'])){ $id = $_GET['pageID']; } ?> <?php if(isset($_POST['submit'])){ $title = $_POST['title']; $keywords = $_POST['keywords']; $description = $_POST['description']; $menu = $_POST['menu']; $content = $_POST['content']; $query = mysql_query("UPDATE 'page' SET title='$title', keywords='$keywords', description='$description', menu='$menu', content='$content' WHERE 'pageID'= $id"); } ?> I am having a problem with my PHP/MySQL coding and I can not figure out what I am doing wrong. I have two tables in a database. One called EmployeeInfo and another called Absence. In the Employee Info table, I have two employees, Derek and Adrian. In the Absence table, I have two records, One for Derek and Adrian. Goal: Using PHP/MySQL, I want to call upon an employee using a form and display that person's absence. The form pulls up correctly. If I do NOT put a WHERE clause into my SQL statement, it pulls up all the absences perfectly fine. Once I put in the WHERE = EmployeeInfo.Name = 'NameSelect' then it fails every time. Here is my SQL Coding: $result = mysql_query("SELECT * FROM Absence LEFT JOIN EmployeeInfo ON(Absence.Account = EmployeeInfo.Account) WHERE EmployeeInfo.Name='NameSelect'"); Any help is greatly appreciated. I have a CVS file with about 1000 entries which I need to input into a MySQL database. Each line in the file has 5 fields but I am only interested in the first two. These are the description and name. I'm sure I can do this directly with MySQL but I need to use PHP anyway because there is actually other things I need to do with the data. I don't need to go into details because I already have that sorted. I just need to know how to open the CVS file and make a mysql insert loop with the data. Thanks Hello i want to create a comment function to my website, but im not sure which way to do it. The thing is that i have post.php script that insert a new row in my table "content" and i want 1 separate comment function for each row (that symbols a link on my website). I was thinking that i could add a new table each time a new row(link) is created on my website just by modifying post.php to create new table. But will this be the most officiant way of making a comment function or will it burden my server and slow'en it? Hi in new to php with a work colleague we have been designing a php/mysql reporting system for the school i work at but need a help with a bug teachers can update reports when they do the code pouplates the textareas with what is in the DB they can then make changes no problem but if two do it at the same time or one opens a reports goes makes a tea another opens the same report makes a changes updates report lets say Science then and then the other teacher comes bak makes a change to Maths it rewights the old science over the top of the new one the othe teacher did a little while ago In short can you make a php statment that onchange of textarea then include into the mysql update query if no change the dont include that in the mysql update query hello i am making a online cook for people to register and make and online cookbook on there account i want them to be able to add recipes and be able to see them on there file, i know how it would connect to the database and how to send the information but what tables would i use and what fields? this is my basic site now www.lachlanmcgrath.net, if you can help please reply here or even e-mail me at lmcgr44@me.com thank-you for your help This is my first time really working with more than 1 or two tables in a mysql database and I'd like to know what is the best way to go about querying my data so that i'm doing it in at least a somewhat efficient manner that the way I am currently doing it. First I will list my Tables and pastebin the Table creation code so you can get an idea of what I'm working with. Graff_Users, Drawings, Drawings_Stamps, Stamps, Packages Ok, those are the tables, the Graff_Users is the main table. The way I've got things setup is that I first do a query on the Graff_Users table for any uid that I want to lookup data for. Then, based on whether the artist column is equal to 1 will determine if there are Drawings to fetch, at least that is how I've been doing it and I dont feel like redesigning something that works so well for me right now. so everything is fine when artist=0 or null or anything but 1. But my trouble starts if artist=1, then I have to query a whole lot of data here, let me explain it. Ok, if artist=1, currently, I query the Drawings table to find any drawings where the house_owner_id is equal to the uid of the User. This leads me to a list of Drawings rows. Next, I check which of those rows has stamps_used=1 for each Drawing and gather up a list of id's of the Drawings that have that set to 1. Once I have the list of id's of the Drawings, I query the Drawings_Stamps table for rows where the drawings_id is equal to any of those id's. Then once I have that, I use the stamp_id's from those and do another query on the Stamps table to get all of the stamps matching those id's. Then each Stamp also contains an author_id so I gather those id's up and do another query back on the Graff_Users table to get the first_name,last_name and picture. Once I have all of that data in various array throughout my script, i create a new array and start putting the pieces back togather from the various arrays until I am left with an array that looks like this one here(JSON used for visualization here) Code: [Select] { "request_type": 1, "target_uid": "1234567", "data": { "id": "277", "uid": "1234567", "first_name": "Jeremy", "last_name": "Canada", "picture": "http://www.pictures.com/mypic.png", "signed_up": "2010-10-29 03:47:09", "selected_house": "10", "mp3": "1", "emblem_id": "2", "artistData": [ { "id": "210", "artist_id": "1234567", "house_owner_id": "1234567", "anonymous": null, "stamps_used": "1", "timestamp": "2010-09-23 00:52:42", "note": "wanna dance?", "first_name": "Jeremy", "last_name": "Canada", "picture": "http://blahblah.com/picture.png", "stampsArray": [ { "id": "250", "name": "", "author_id": "654321", "created": "2010-09-23 23:40:22", "keywords_id": null, "packages_id": "27", "public": "1", "package_category_id": "0", "filename": "drawingitems\/663231980_1285285221_445643.png", "number_of_users": "0", "description": "just another stamp my friend", "rating": "0", "thumbs_up": "0", "thumbs_down": "0", "first_name": "Cat Man", "last_name": "Blues", "picture": "http:\/\/pic.com\/_q.jpg", "packageData": { "id": "27", "name": "Circles Of cool", "description": null, "total_stamps": "6", "number_of_users": "0", "rating": "0", "thumbs_up": "0", "thumbs_down": "0" } }, { "id": "249", "name": "", "author_id": "1680999989", "created": "2010-09-23 23:38:28", "keywords_id": null, "packages_id": "26", "public": "1", "package_category_id": "0", "filename": "drawingitems\/663231980_1285285108_441450.png", "number_of_users": "0", "description": null, "rating": "0", "thumbs_up": "0", "thumbs_down": "0", "first_name": "Raymond", "last_name": "Coldstar", "picture": null, "packageData": { "id": "26", "name": "The nice pics pack", "description": "description of the package would go here", "total_stamps": "123", "number_of_users": "234", "rating": "3", "thumbs_up": "2", "thumbs_down": "7" } } ] }, { "id": "212", "artist_id": "4", "house_owner_id": "1234567", "anonymous": "0", "stamps_used": "1", "timestamp": "2010-07-09 03:45:59", "note": "shake it baby", "stampsArray": [ { "id": "248", "name": "flying stick man 1", "author_id": "663231980", "created": "2010-09-23 23:37:08", "keywords_id": "6", "packages_id": "26", "public": "1", "package_category_id": "0", "filename": "drawingitems\/663231980_1285285027_288422.png", "number_of_users": "1200", "description": "stamp description would go here", "rating": "6734", "thumbs_up": "18", "thumbs_down": "22", "first_name": "Gary", "last_name": "Hoss", "picture": "http:\/\/profiles.com\/63231980_1168_q.jpg", "packageData": { "id": "26", "name": "The nice pics pack", "description": "description of the package would go here", "total_stamps": "6546345", "number_of_users": "234", "rating": "3", "thumbs_up": "2", "thumbs_down": "7" } }, { "id": "249", "name": "", "author_id": "1680999989", "created": "2010-09-23 23:38:28", "keywords_id": null, "packages_id": "26", "public": "1", "package_category_id": "0", "filename": "drawingitems\/663231980_1285285108_441450.png", "number_of_users": "0", "description": null, "rating": "0", "thumbs_up": "0", "thumbs_down": "0", "first_name": "Raymond", "last_name": "Blues Brutha", "picture": null, "packageData": { "id": "26", "name": "The nice pics pack", "description": "description of the package would go here", "total_stamps": "6543534", "number_of_users": "234", "rating": "3", "thumbs_up": "2", "thumbs_down": "7" } } ] }, { "id": "221", "artist_id": "663231980", "house_owner_id": "1234567", "anonymous": null, "stamps_used": null, "timestamp": "2010-09-13 07:35:25", "note": "hi jeremy", "first_name": "Coolio", "last_name": "Stars", "picture": "http:\/\/nowhere.com\/1980_1168_q.jpg" }, { "id": "227", "artist_id": "4321", "house_owner_id": "1234567", "anonymous": null, "stamps_used": null, "timestamp": "2010-09-24 01:24:19", "note": "" } ] } } I got a new laptop running Windows 7 and wanted to develop some PHP coding for test purposes.
I want the data I test to go into MySQL.
What do I need to do and where can I get the appropriate downloads to get started with the most basic of set-ups?
I am creating a website for university coursework.
<input name="submit" type="submit" class="submit_btn float_l" id="submit" formaction="add-contactme.php" value="Send" />
The above code is from my html for contact.html if that is correct. I am using a form and then a submit button.
I keep getting
Notice: Undefined index: name in C:\xampp\htdocs\hometown\hometown\add-contactme.php on line 11 Notice: Undefined index: email in C:\xampp\htdocs\hometown\hometown\add-contactme.php on line 12 Notice: Undefined index: phoneno in C:\xampp\htdocs\hometown\hometown\add-contactme.php on line 13 Notice: Undefined index: comments in C:\xampp\htdocs\hometown\hometown\add-contactme.php on line 14 Also if anyone could help me I would like to create a delete button after a person has added the values into the sql table, basically to the last row inputted into the database. I want to avoid using delete from contactme where name ='chris'; $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="contactme"; // Table name mysql_connect ("$host", "$username", "$password") or die ("cannot connect server "); mysql_select_db ("$db_name") or die ("cannot select DB"); $name = $_POST["name"]; $email = $_POST["email"]; $phoneno = $_POST["phoneno"]; $comments = $_POST["comments"]; $sql="INSERT INTO $tbl_name VALUES ('$name', '$email', '$phoneno''$comments')"; $result=mysql_query($sql); if($result){ echo "Successful" . " "; echo "view-contactme.php"; // link to view contact me page } mysql_close(); ?> Edited by G3NERALCHRIS, 20 November 2014 - 09:04 AM. Hey Guys I need some help, I have these two tables: (vouchers) (login) I also, have this page. (redeem.php) What i need, is when a user types in a voucher code, i adds 100 credits to there user account. My Logged in Session is currently: Quote $username = $_SESSION['loggedinsuccesfully']; Also, when the voucher has been used, the status of the voucher needs to change to 1 (means it cant be used again) If anyone can offer me this code, i will appreciate it. Thanks again fCooper94 |