J4B Posted March 19, 2009 Share Posted March 19, 2009 I'm full of questions! Thats how I learn best. how would I add something to the end of the information? for example: name--movie--rating john--matrix--5 and then he adds jumper to his list, how would I make it as follows: john--matrix,jumper--5,3 Link to comment https://forums.phpfreaks.com/topic/150205-adding-to-the-end-of-a-cell/ Share on other sites More sharing options...
rhodesa Posted March 19, 2009 Share Posted March 19, 2009 how is this information stored? if it's in a database, you should have a separate table with an entry for each person's movie rating...so: user_id | movie_id | rating 123 456 5 123 789 3 so john, with the user id of 123 has two moving ratings...one for the matrix with movie id 456 and one for jumper with the movie id of 789 Link to comment https://forums.phpfreaks.com/topic/150205-adding-to-the-end-of-a-cell/#findComment-788818 Share on other sites More sharing options...
Zhadus Posted March 19, 2009 Share Posted March 19, 2009 There are really multiple ways of doing it. I would recommend storing the values themselves in an array. For example: $userInfo['john'] = array(array('matrix', 5), array('jumper', 3)); this way, you get this as the output: echo $userInfo['john'][0][0]; // Returns matrix echo $userInfo['john'][0][1]; // Returns 5 echo $userInfo['john'][1][0]; // Returns Jumper echo $userInfo['john'][1][1]; // Returns 3 Otherwise you can use explode() for the info. And in what you need, and implode. $string = 'john--matrix--5'; $values = explode('--', $string); $values[0] // now holds 'john' $values[1] // now holds 'matrix' $values[2] // now holds 5 $values[1] .= ',jumper'; $values[2] .= ',3'; $string = implode('--', $values); Or you could do it the easy way like rhodesa Link to comment https://forums.phpfreaks.com/topic/150205-adding-to-the-end-of-a-cell/#findComment-788821 Share on other sites More sharing options...
J4B Posted March 19, 2009 Author Share Posted March 19, 2009 how is this information stored? if it's in a database, you should have a separate table with an entry for each person's movie rating...so: user_id | movie_id | rating 123 456 5 123 789 3 so john, with the user id of 123 has two moving ratings...one for the matrix with movie id 456 and one for jumper with the movie id of 789 I've got them in a table right now as follows: ID--username--password--movies--rating 2--name-------1234--matrix--5 I'm no good with database, but I'm alright with php which is why I'm asking so many questions. So if I where to make a separate table for each, would I need to do this: user | movie | rating 123 matrix 5 123 jumper 3 234 matrix 5 234 jumper 3 and also, to get all the movies they have and their ratings would I do this: mysql_query("SELECT movie,rating FROM members WHERE user = '$myuser'") Link to comment https://forums.phpfreaks.com/topic/150205-adding-to-the-end-of-a-cell/#findComment-788825 Share on other sites More sharing options...
rhodesa Posted March 19, 2009 Share Posted March 19, 2009 kind of...your members table should have member info...ID, username, password...then have a member_movies table with UserId, movie, rating. personally, i would have a movies table too...but that is up to you. then, to get the movies for a user: mysql_query("SELECT movie,rating FROM member_movies WHERE user = '$myuser'") Link to comment https://forums.phpfreaks.com/topic/150205-adding-to-the-end-of-a-cell/#findComment-788829 Share on other sites More sharing options...
J4B Posted March 19, 2009 Author Share Posted March 19, 2009 Right now I have 2 tables: Members: ID--username--password--movies--ratings movies: num--title--rating and your saying I should have 3? Members: ID--username--password watched: ID--movies--ratings movies: num--title--rating is that right? Link to comment https://forums.phpfreaks.com/topic/150205-adding-to-the-end-of-a-cell/#findComment-788904 Share on other sites More sharing options...
rhodesa Posted March 19, 2009 Share Posted March 19, 2009 yes...but let's just make sure you get the watched table right...i would call the columns: watched: user_id--movie_num--rating user_id -> the ID from Members for that user movie_num -> the number of the movie being rated rating -> the rating for that move so, in this table, a row represents A movie rated by A user. so if you have 3 users, and each user has watched 3 movies, there would be 9 records. make sense? Link to comment https://forums.phpfreaks.com/topic/150205-adding-to-the-end-of-a-cell/#findComment-788916 Share on other sites More sharing options...
J4B Posted March 19, 2009 Author Share Posted March 19, 2009 Ya, thats how I understood it. Thanks. I'll mark solved in just a second after I make sure I've got it. Link to comment https://forums.phpfreaks.com/topic/150205-adding-to-the-end-of-a-cell/#findComment-788925 Share on other sites More sharing options...
J4B Posted March 19, 2009 Author Share Posted March 19, 2009 Ok, So I've got this now, but Its not working quite right. $c = mysql_connect($cms['db']['host'], $cms['db']['user'], $cms['db']['pass']); mysql_select_db($cms['db']['name'], $c); $myid = mysql_query("SELECT ID FROM members WHERE username = '$myusername' and password='$mypassword'"); echo('a'.$myid.'a'); $check = mysql_query("SELECT * FROM movie WHERE num = '$imdb'"); $check2 = mysql_num_rows($check); if($check2 != '0') { die("That movie already exists!"); } $insert_movie = mysql_query("INSERT INTO movie (num, title, rating) VALUES ('$imdb', '$title', '$rate,')"); $insert_movie1 = mysql_query("INSERT INTO members_movies (ID, movie, rating) VALUES ('$myID', '$IMDB', '$rate,')"); echo($title); if($insert_movie AND $insert_movie1) { echo(" Added!"); } else { echo("<p class='b01'>Failed!</p>"); } Link to comment https://forums.phpfreaks.com/topic/150205-adding-to-the-end-of-a-cell/#findComment-788941 Share on other sites More sharing options...
rhodesa Posted March 20, 2009 Share Posted March 20, 2009 what is the difference between what it is doing and what you expect it to do? Link to comment https://forums.phpfreaks.com/topic/150205-adding-to-the-end-of-a-cell/#findComment-789051 Share on other sites More sharing options...
J4B Posted March 20, 2009 Author Share Posted March 20, 2009 It doesn't add anything to the movie table. it also only adds the rating to the members_movies table. Link to comment https://forums.phpfreaks.com/topic/150205-adding-to-the-end-of-a-cell/#findComment-789054 Share on other sites More sharing options...
rhodesa Posted March 20, 2009 Share Posted March 20, 2009 well...let's add some debugging...wherever you have a: mysql_query(...); change it to: mysql_query(...) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/150205-adding-to-the-end-of-a-cell/#findComment-789059 Share on other sites More sharing options...
redarrow Posted March 20, 2009 Share Posted March 20, 2009 where the full code mate and add the mysql_error() function ok. Link to comment https://forums.phpfreaks.com/topic/150205-adding-to-the-end-of-a-cell/#findComment-789123 Share on other sites More sharing options...
J4B Posted March 20, 2009 Author Share Posted March 20, 2009 So here is my updated script: //database connect $c = mysql_connect($cms['db']['host'], $cms['db']['user'], $cms['db']['pass']); mysql_select_db($cms['db']['name'], $c); $myid = mysql_query("SELECT id FROM members WHERE username = '$myusername' and password = '$mypassword'"); //is the movie in the database $check = mysql_query("SELECT * FROM movie WHERE num = '$imdb'"); $check2 = mysql_num_rows($check); if($check2 != '0') { die("That movie already exists!"); } //put the info in! $insert_movie = mysql_query("INSERT INTO movie (num, title, total, num_rated) VALUES ('$imdb', '$title', '$rate', '1' )") or die(mysql_error()); $insert_movie1 = mysql_query("INSERT INTO members_movies (ID, movie, rating) VALUES ('$myID', '$IMDB', '$rate')") or die(mysql_error()); echo($title); if($insert_movie AND $insert_movie1) { echo(" added!"); } else { echo(" was not added!"); } and everything works now EXCEPT for it doesn't put anything into the members_movies table in the ID or movie columns. Also, I do not get any errors. I don't think the $myid is actually getting my id number. Link to comment https://forums.phpfreaks.com/topic/150205-adding-to-the-end-of-a-cell/#findComment-789125 Share on other sites More sharing options...
redarrow Posted March 20, 2009 Share Posted March 20, 2009 $myid needs a array name example $myid['myid'] $myid <<< is the array name ['myid']<<< is inside of $myid array, from the database field named myid. so $user_id=$myid['myid'] // that will work. Link to comment https://forums.phpfreaks.com/topic/150205-adding-to-the-end-of-a-cell/#findComment-789175 Share on other sites More sharing options...
rhodesa Posted March 20, 2009 Share Posted March 20, 2009 ah...ok...let's talk about the movies table more. does this list not exist already? aka, does the person select a movie from a list? or do they just type in a movie name? if user1 and user2 both put in a rating for the matrix, will there be one entry or two in the movies table? also, try changing this: $myid = mysql_query("SELECT ID FROM members WHERE username = '$myusername' and password='$mypassword'"); to: list($myid) = mysql_fetch_array(mysql_query("SELECT ID FROM members WHERE username = '$myusername' and password='$mypassword'")); Link to comment https://forums.phpfreaks.com/topic/150205-adding-to-the-end-of-a-cell/#findComment-789344 Share on other sites More sharing options...
J4B Posted March 20, 2009 Author Share Posted March 20, 2009 Currently the way it works, the person just copy pastes an IMDB link into the field and selects a rating from a drop down (1-5). Then I get all the information I need from IMDB. This is the page to add a movie not already in my database, I don't have the page to add one already in my database yet. also, try changing this: $myid = mysql_query("SELECT ID FROM members WHERE username = '$myusername' and password='$mypassword'"); to: list($myid) = mysql_fetch_array(mysql_query("SELECT ID FROM members WHERE username = '$myusername' and password='$mypassword'")); That didn't work $myid needs a array name example $myid['myid'] $myid <<< is the array name ['myid']<<< is inside of $myid array, from the database field named myid. so $user_id=$myid['myid'] // that will work. Trying now. Alright, Either I did it wrong, or it just didn't work. here is the entire page. <? session_start(); if(!session_is_registered(myusername)){ header("location:login.php"); } ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Movies</title> <link href="style.css" rel="stylesheet" type="text/css" /> <link rel="shortcut icon" href="images/favicon.ico" /> </head> <body> <?php // Database $cms['db']['host'] = 'localhost'; // Database Host $cms['db']['user'] = 'root'; // Database User $cms['db']['pass'] = 'root'; // Database Pass $cms['db']['name'] = 'movies'; // Database Name $cms['site']['title'] = 'Movie Database'; // Site Title //database connect ?> <div id="main"> <div class="container"> <div id="header"> <ul id="menu"> <li><a href="Add.php">Add a Movie</a></li> <li><a href="Top.php">Top Movies</a></li> <li><a href="logout.php">Logout</a></li> </ul> <div id="logo"> <h1>Movies</h1> <small>A Collection Of Movies</small> </div> <div id="block_featured" class="block"> <span class="block_inside"> <div class="image_block"> <img src="images/sample_feature.jpg" /> </div> <div class="text_block"> <form action="?op=submit" method="post"> <div align="center"><br /> <h2><span class="b01"><a href="/movies/index.php"> Adding Movies </span></a></br></br><P></h2> IMDB Link: <input name="imdb" type="text" class="liteoption" id="imdb" size="20" maxlength="36" /><P> Rating: <select name="rate"> <option value="0">haven't seen</option> <option value="5">Must See</option> <option value="4">Should See</option> <option value="3">Your Choice</option> <option value="2">Shouldn't See</option> <option value="1">Don't See</option> </select><P> <input name="submit" type="submit" class="liteoption" value="submit" /> </div> </form> <?php if(isset($_POST['submit'])) { $myusername = $_SESSION["myusername"]; //getting title $imdb = $_POST['imdb']; $imdb1 = '1'; $imdb2 = $imdb1.$imdb.$imdb1; $imdb1 = str_replace('1', "'", $imdb2); $imdb_content = get_data($imdb); $title = get_match('/<title>(.*)<\/title>/isU',$imdb_content); $image = get_match('"/rg/action-box-title/primary-photo/media/(.*)"',$imdb_content); //getting other info $rate = $_POST['rate']; $array = explode('/tt', $imdb); $imdb = $array[1]; $imdb = str_replace('/', "", $imdb); $array1 = explode('images/M/', $image); $image = $array1[1]; $image = str_replace('" /> " border="0"></body></html>', "", $image); $image = str_replace('.jpg" />', "", $image); $imageURL = "http://ia.media-imdb.com/images/M/" . $image; $im = imagecreatefromjpeg($imageURL); // Attempt to open if (!$im) { // See if it failed // exit("nothing happened"); $im = imagecreatetruecolor($Width, $Hight); // Create a black image $bgc = imagecolorallocate($im, 135, 206, 250); $tc = imagecolorallocate($im, 255, 255, 255); imagefilledrectangle($im, 0, 0, $Width, $Hight, $bgc); // Output an errmsg // imagestring($im, 5, 5, 5, "Error loading Satellite Map", $tc); } imagejpeg($im,'covers/'.$imdb.'.jpg',100); imagedestroy($im); //database connect $c = mysql_connect($cms['db']['host'], $cms['db']['user'], $cms['db']['pass']); mysql_select_db($cms['db']['name'], $c); $user_id=$myid['myid']; list($myid) = mysql_fetch_array(mysql_query("SELECT ID FROM members WHERE username = '$myusername' and password='$mypassword'")); //is the movie in the database $check = mysql_query("SELECT * FROM movie WHERE num = '$imdb'"); $check2 = mysql_num_rows($check); if($check2 != '0') { die("That movie already exists!"); } //put the info in! $insert_movie = mysql_query("INSERT INTO movie (num, title, total, num_rated) VALUES ('$imdb', '$title', '$rate', '1' )") or die(mysql_error()); $insert_movie1 = mysql_query("INSERT INTO members_movies (ID, movie, rating) VALUES ('$myID', '$IMDB', '$rate')") or die(mysql_error()); echo($title); if($insert_movie AND $insert_movie1) { echo(" added!"); } else { echo(" was not added!"); } /* echo "<br><IMG SRC='$imageURL' >"; */ } function get_data($url) { $ch = curl_init(); $timeout = 5; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); $data = curl_exec($ch); curl_close($ch); return $data; } function get_match($regex,$content) { preg_match($regex,$content,$matches); return $matches[1]; } ?> </div> </span> </div> </div> </div> </div> <div id="footer"> <div class="container"> <div class="footer_column long"> <h3><!--Designed by Collis Ta’eed, do with this as you please--></h3> <p><!--You can read a photoshop tutorial for creating the design at <a href="http://psdtuts.com">PSDTUTS</a>, You can read a PS->HTML tutorial for creating the site at <a href="http://nettuts.com">NETTUTS</a> and you can learn how to turn the HTML into a Wordpress theme in the upcoming book <a href="http://freelanceswitch.com/book">How to be a Rockstar Wordpress Designer</a>--></p> </div> <div class="footer_column"> <h3>More Links</h3> <ul> <li><a href="http://PlaceHolder.com">PlaceHolder</a></li> <li><a href="http://PlaceHolder.net">PlaceHolder</a></li> <li><a href="http://PlaceHolder.net">PlaceHolder</a></li> <li><a href="http://PlaceHolder.com">PlaceHolder</a></li> <li><a href="http://PlaceHolder.com">PlaceHolder</a></li> </ul> </div> <div class="footer_column"> <h3>RSS</h3> <ul> <li><a href="">RSS Feed</a></li> </ul> </div> </div> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/150205-adding-to-the-end-of-a-cell/#findComment-789609 Share on other sites More sharing options...
J4B Posted March 24, 2009 Author Share Posted March 24, 2009 anybody? Link to comment https://forums.phpfreaks.com/topic/150205-adding-to-the-end-of-a-cell/#findComment-793094 Share on other sites More sharing options...
J4B Posted March 25, 2009 Author Share Posted March 25, 2009 bump Link to comment https://forums.phpfreaks.com/topic/150205-adding-to-the-end-of-a-cell/#findComment-793319 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.