supermerc Posted April 16, 2007 Share Posted April 16, 2007 Hey I have a rating system but I want to make it universal, my rating system is in a different table than my stuff that is being rated so I want to know how I would do to get the table from which the art or w/e comes from so that i can enter that in the database. Link to comment https://forums.phpfreaks.com/topic/47321-how-to-get-from-which-table-something-comes-from/ Share on other sites More sharing options...
AndyB Posted April 17, 2007 Share Posted April 17, 2007 You need the table that the art or whatever comes from before you display it, don't you? Pass the table name to the rating system script using a hidden form input. Link to comment https://forums.phpfreaks.com/topic/47321-how-to-get-from-which-table-something-comes-from/#findComment-230849 Share on other sites More sharing options...
supermerc Posted April 17, 2007 Author Share Posted April 17, 2007 I dont understand what you mean Link to comment https://forums.phpfreaks.com/topic/47321-how-to-get-from-which-table-something-comes-from/#findComment-230850 Share on other sites More sharing options...
AndyB Posted April 17, 2007 Share Posted April 17, 2007 explain how you get 'the art or whatever' to be displayed ... does the information come from a table in a database? Link to comment https://forums.phpfreaks.com/topic/47321-how-to-get-from-which-table-something-comes-from/#findComment-230963 Share on other sites More sharing options...
supermerc Posted April 17, 2007 Author Share Posted April 17, 2007 ya I save the path in the database and stuff Link to comment https://forums.phpfreaks.com/topic/47321-how-to-get-from-which-table-something-comes-from/#findComment-231097 Share on other sites More sharing options...
Anzeo Posted April 17, 2007 Share Posted April 17, 2007 show us the code of your table so that we can help you. If you're using a form you can use, as AndyB said, the hidden type input. Link to comment https://forums.phpfreaks.com/topic/47321-how-to-get-from-which-table-something-comes-from/#findComment-231121 Share on other sites More sharing options...
supermerc Posted April 17, 2007 Author Share Posted April 17, 2007 I dont understand what you mean by the code of my table Link to comment https://forums.phpfreaks.com/topic/47321-how-to-get-from-which-table-something-comes-from/#findComment-231669 Share on other sites More sharing options...
AndyB Posted April 17, 2007 Share Posted April 17, 2007 I dont understand what you mean by the code of my table Then I think we're going to have real problems in helping you. How about you post the php script that displays the 'art or whatever' it is that gets drawn from the database abd displayed for rating. Post a chunk that includes your database connection (w/o password), your database table selection, the database query you use to retrieve information, how those data are processed through to the actual display of the 'art or whatever'. That'll be a start. If you're feeling brave, post the code for the form you use for letting a visitor add a rating. Then we'll really be getting somewhere. Link to comment https://forums.phpfreaks.com/topic/47321-how-to-get-from-which-table-something-comes-from/#findComment-231692 Share on other sites More sharing options...
supermerc Posted April 17, 2007 Author Share Posted April 17, 2007 OK the is the view_art.php <?php require("config.php"); require("functions.php"); //echo some styles to spice it up... echo " <style> body { background: #FFFFFF; font-family: Verdana, Arial; font-weight: bold; font-size: 9px; color: #00000; } .register_box { border: 1px solid #323232; background: #202020; font-family: Verdana, Arial; font-weight: bold; font-size: 9px; color: #FFFFFF; } </style> "; // if the variable member_id has been set, or there is a value assigned to it... if(isset($_GET['member_id'])) { $member_id = (INT)$_GET['member_id']; $member_info = mysql_query("SELECT * FROM gallery WHERE id = '$member_id' LIMIT 1"); if(mysql_num_rows($member_info) > 0) { // we can go ahead and assign it to an array because this user exists $profile_info = mysql_fetch_assoc($member_info); include 'rateview.php'; echo " <h1>$profile_info[name]</h1> "; include'star_rating.php'; echo" <img src='$profile_info[path]'><br /><br /> <br /><b>Description: </b>$profile_info[description]</p> <br /> "; } else { echo "That member does not exist, or is not activated yet!"; } } else { echo "There was no member ID to view a profile for!"; } ?> <title><?=$profile_info[name]?> by: <?=$profile_info[username]?></title> Now this is the rating script <link href="star_rating.css" rel="stylesheet" type="text/css" /> <?php include'config.php'; $id=(INT)$_GET['member_id']; $tableName="ratings"; $sql = "SELECT username FROM gallery WHERE id = $id"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $gallery = mysql_fetch_assoc($result); $which_user = $gallery['username'];//how many votes total } } $one="1"; $rating_posted=$_GET['vote'];//pased variable by the the stars value $sql = "SELECT total_votes, total_value, used_ips FROM $tableName WHERE which_id = $id"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $numbers = mysql_fetch_assoc($result); $checkIP = unserialize($numbers['used_ips']); $count = $numbers['total_votes'];//how many votes total $current_rating = $numbers['total_value'];//total number of rating added together and stored $sum = $rating_posted+$current_rating;// add together the current vote value and the total vote value $tense = ($count==1) ? "vote" : "votes";//plural form votes/vote } else { } } else { echo "Query failed<br />$sql<br />". mysql_error(); } $voted=@mysql_fetch_assoc(@mysql_query("SELECT * FROM $tableName WHERE used_ips LIKE '%".serialize($_SERVER['REMOTE_ADDR'])."%' AND which_id='$id' ")); //Pattern match ip:suggested by Bramus! http://www.bram.us/ - this variable searches through the previous ip address that have voted and returns true or false if($voted){ echo "<div class=\"rating\">". "<ul class=\"star-rating\">". "<li class=\"current-rating\" style=\"width:". @number_format($current_rating/$count,2)*30 ."px;\">Current rating.</li>". "<li class=\"one-star\"></li>". "<li class=\"two-stars\" ></li>". "<li class=\"three-stars\"></li>". "<li class=\"four-stars\"></li>". "<li class=\"five-stars\"></li>". "</ul>". "<p>Rating: <strong>".@number_format($current_rating/$count,2)."</strong> <br />You have previously voted.</p></div>";//show the current value of the vote with the current numbers }else{ if(isset($_GET['vote'])){ if($sum==0){ $added=0;//checking to see if the first vote has been tallied }else{ $added=$count+1;//increment the current number of votes } if(is_array($checkIP)){ array_push($checkIP,$_SERVER['REMOTE_ADDR']);//if it is an array i.e. already has entries the push in another value }else{ $checkIP=array($_SERVER['REMOTE_ADDR']);//for the first entry } $insert=serialize($checkIP); $query = mysql_query("select * from ratings where which_id=$id"); $num = mysql_num_rows($query); if ($num != 1) { mysql_query("INSERT INTO ratings(total_votes, total_value, used_ips, which_id, which_user) VALUES ('".$one."','".$rating_posted."','".$insert."', '{$id}', '{$which_user}')"); } else { mysql_query("UPDATE $tableName SET total_votes='".$added."', total_value='".$sum."', used_ips='".$insert."' WHERE which_id='{$id}'"); } if (@number_format($sum/$added,2) == 0) { echo "<div class=\"rating\"><p>Rating: <strong>".$rating_posted."</strong> <span>Thank you for your vote!</span></p></div>"; } else{ echo "<div class=\"rating\"><p>Rating: <strong>".@number_format($sum/$added,2)."</strong> <span>Thank you for your vote!</span></p></div>";//show the updated value of the vote } }else{ ?> <div class="rating"> <ul class="star-rating"> <li class="current-rating" style="width:<?php echo @number_format($current_rating/$count,2)*30 ?>px;">Current rating</li> <li><a href="<?php echo $_SERVER['PHP_SELF'] . "?" .$_GET['section'] . "member_id=" . (INT)$_GET['member_id'] . "&vote=1";?>" title="Rate this 1 star out of 5" class="one-star">1</a></li> <li><a href="<?php echo $_SERVER['PHP_SELF'] . "?" .$_GET['section'] . "member_id=" . (INT)$_GET['member_id'] . "&vote=2";?>" title="Rate this 2 stars out of 5" class="two-stars" >2</a></li> <li><a href="<?php echo $_SERVER['PHP_SELF'] . "?" .$_GET['section'] . "member_id=" . (INT)$_GET['member_id'] . "&vote=3";?>" title="Rate this 3 stars out of 5" class="three-stars" >3</a></li> <li><a href="<?php echo $_SERVER['PHP_SELF'] . "?" .$_GET['section'] . "member_id=" . (INT)$_GET['member_id'] . "&vote=4";?>" title="Rate this 4 stars out of 5" class="four-stars" >4</a></li> <li><a href="<?php echo $_SERVER['PHP_SELF'] . "?" .$_GET['section'] . "member_id=" . (INT)$_GET['member_id'] . "&vote=5";?>" title="Rate this 5 stars out of 5" class="five-stars" >5</a></li> </ul> <?php echo "<p>Rating: <strong>".@number_format($sum/$count,2)."</strong> </p></div>";//show the current updated value of the vote } // end isset get vote } //end voted true, false ?> Link to comment https://forums.phpfreaks.com/topic/47321-how-to-get-from-which-table-something-comes-from/#findComment-231712 Share on other sites More sharing options...
AndyB Posted April 18, 2007 Share Posted April 18, 2007 and which bit of art.php is the bit that chooses a specific 'art or whatever'? and which bit of the rating script is where I'd click to vote? Link to comment https://forums.phpfreaks.com/topic/47321-how-to-get-from-which-table-something-comes-from/#findComment-231763 Share on other sites More sharing options...
supermerc Posted April 18, 2007 Author Share Posted April 18, 2007 well for your first question, $member_id = (INT)$_GET['member_id']; gets the art that was clicked and for your second question you would click one of the stars, <li><a href="<?php echo $_SERVER['PHP_SELF'] . "?" .$_GET['section'] . "member_id=" . (INT)$_GET['member_id'] . "&vote=1";?>" title="Rate this 1 star out of 5" class="one-star">1</a></li> <li><a href="<?php echo $_SERVER['PHP_SELF'] . "?" .$_GET['section'] . "member_id=" . (INT)$_GET['member_id'] . "&vote=2";?>" title="Rate this 2 stars out of 5" class="two-stars" >2</a></li> <li><a href="<?php echo $_SERVER['PHP_SELF'] . "?" .$_GET['section'] . "member_id=" . (INT)$_GET['member_id'] . "&vote=3";?>" title="Rate this 3 stars out of 5" class="three-stars" >3</a></li> <li><a href="<?php echo $_SERVER['PHP_SELF'] . "?" .$_GET['section'] . "member_id=" . (INT)$_GET['member_id'] . "&vote=4";?>" title="Rate this 4 stars out of 5" class="four-stars" >4</a></li> <li><a href="<?php echo $_SERVER['PHP_SELF'] . "?" .$_GET['section'] . "member_id=" . (INT)$_GET['member_id'] . "&vote=5";?>" title="Rate this 5 stars out of 5" class="five-stars" >5</a></li> </ul> Link to comment https://forums.phpfreaks.com/topic/47321-how-to-get-from-which-table-something-comes-from/#findComment-231790 Share on other sites More sharing options...
AndyB Posted April 18, 2007 Share Posted April 18, 2007 Unless I'm completely missing the point to all this, when you click a star there are TWO variables passed with the link - member_id (which is apparently what you keep referring to as 'art or whatever') and the vote value. Retrieve the member_id from the passed $_GET array the same way as you retrieved vote from it. Link to comment https://forums.phpfreaks.com/topic/47321-how-to-get-from-which-table-something-comes-from/#findComment-231795 Share on other sites More sharing options...
supermerc Posted April 18, 2007 Author Share Posted April 18, 2007 when I vote It takes the ID of the art and puts it in the database with how with vote and stuff, but I want to also know from what table that art is, even though I know which one, I want to script to detect what table what you are rating comes from Link to comment https://forums.phpfreaks.com/topic/47321-how-to-get-from-which-table-something-comes-from/#findComment-231796 Share on other sites More sharing options...
supermerc Posted April 18, 2007 Author Share Posted April 18, 2007 bump Link to comment https://forums.phpfreaks.com/topic/47321-how-to-get-from-which-table-something-comes-from/#findComment-232008 Share on other sites More sharing options...
Anzeo Posted April 18, 2007 Share Posted April 18, 2007 I assume you also want to put the table where your vote came from in your DB? then I would use the input hidden type, you can store a specific value in it and you can retrieve it with a $_GET Link to comment https://forums.phpfreaks.com/topic/47321-how-to-get-from-which-table-something-comes-from/#findComment-232019 Share on other sites More sharing options...
AndyB Posted April 18, 2007 Share Posted April 18, 2007 I'm going to make one last attempt to understand this. If you have code that displays something you want people to rate, then you MUST know what database table that thing is in or you will not be able to display it. Thus, what you need to do is provide that table information as one of the variables passed along when a star is clicked. For example, as html: <a href="rating.php?member_id=6&vote=4&table=elephants">4 stars</a> rating.php can now retrieve the values of member_id, vote, and table from the $_GET array. Link to comment https://forums.phpfreaks.com/topic/47321-how-to-get-from-which-table-something-comes-from/#findComment-232027 Share on other sites More sharing options...
supermerc Posted April 18, 2007 Author Share Posted April 18, 2007 but how do i put in the table name so I can get it in my voting url like u did Link to comment https://forums.phpfreaks.com/topic/47321-how-to-get-from-which-table-something-comes-from/#findComment-232642 Share on other sites More sharing options...
AndyB Posted April 18, 2007 Share Posted April 18, 2007 but how do i put in the table name so I can get it in my voting url like u did Sigh. Please identify the specific line in your script where the table name from which the 'thing' comes is identified. If you can't tell us that, then this whole thread has run its course and might as well be closed. Link to comment https://forums.phpfreaks.com/topic/47321-how-to-get-from-which-table-something-comes-from/#findComment-232696 Share on other sites More sharing options...
supermerc Posted April 18, 2007 Author Share Posted April 18, 2007 $member_info = mysql_query("SELECT * FROM gallery WHERE id = '$member_id' LIMIT 1"); ? Link to comment https://forums.phpfreaks.com/topic/47321-how-to-get-from-which-table-something-comes-from/#findComment-232723 Share on other sites More sharing options...
AndyB Posted April 18, 2007 Share Posted April 18, 2007 One line example: <li><a href="<?php echo $_SERVER['PHP_SELF'] . "?" .$_GET['section'] . "member_id=" . (INT)$_GET['member_id'] . "&vote=1&tablename=gallery;?>" title="Rate this 1 star out of 5" class="one-star">1[/url]</li> Link to comment https://forums.phpfreaks.com/topic/47321-how-to-get-from-which-table-something-comes-from/#findComment-232733 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.