Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1188 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

relations database

Thread title: relations database
     
    Thread tools Search this thread Display Modes  
Prev Previous Post   Next Post Next
04-20-2011, 06:44 PM
#1
pinzdesign.com is offline pinzdesign.com
Status: I'm new around here
Join date: Feb 2011
Location: Copenhagen/DK
Expertise: php
Software: Paint
 
Posts: 15
iTrader: 0 / 0%
 

pinzdesign.com is on a distinguished road

  Old  relations database

i have made a small system where registered users may add places through the city's downtown and actually give them thumbs up or down, like video rating on youtube.
The conditions:
- a registered user may add as many places as they want
- a registered user may vote for each/any place only once - by giving a thumb up or down...
I have performed it with help of explode()
1.I created a cell in users table called "voted_for"
2.when users votes for some place he:
a.explode() the "voted_for" string,using | as separator
b.compare each chunk with the id of the place - if it exists within the results of exploded "voted_for" - forbid user to vote again
if it's not -do the voting and adds that place's id to his "voted_for" with a |

I did get everything to work properly, thus question is - how to make this work with relations db?

Here is the code:
Code:
if(isset($_REQUEST['sted'])) {
	$sted = $_REQUEST['sted'];
	$kanlide = $_REQUEST['kanlide'];
	$get_places_que = mysql_query("SELECT * FROM users WHERE id='$sid'");
	$places_array = mysql_fetch_array($get_places_que);
	$all_places = $places_array['votedfor'];
	$place = explode("|", $all_places);
	$bedom = "yes";
	for($i = 0; $i <= count($place); $i++) {
		if($place["$i"] == $sted) { 
			echo "<span>Du har bedømt den valgte forslag.</span>";
			$bedom = "no";
			}
		}
	if($bedom == "yes" && $kanlide == "yes") {
			$get_yes_votes = mysql_query("SELECT * FROM steder WHERE id='$sted'");
			$yes_votes_array = mysql_fetch_array($get_yes_votes);
			$newrate = $yes_votes_array['sted_good'] + 1;
			$addvote = $all_places."|$sted";
			$place_que = mysql_query("UPDATE steder SET sted_good='$newrate' WHERE id='$sted'");
			$user_que = mysql_query("UPDATE users SET votedfor='$addvote' WHERE id='$sid'");
			}
	elseif($bedom == "yes" && $kanlide == "no") { 
			$get_no_votes = mysql_query("SELECT * FROM steder WHERE id='$sted'");
			$no_votes_array = mysql_fetch_array($get_no_votes);
			$newrate = $no_votes_array['sted_bad'] + 1;
			$addvote = $all_places."|$sted";
			$place_que = mysql_query("UPDATE steder SET sted_bad='$newrate' WHERE id='$sted'");
			$user_que = mysql_query("UPDATE users SET votedfor='$addvote' WHERE id='$sid'");
			}
}

     


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed