kulmu Posted January 9, 2007 Share Posted January 9, 2007 Being brand new to PHP I am trying to put together a simple script that will allow users to select "this or that" by simply clicking on an image link. The URL format I was thinking would work is:vote.php?winner=4321&loser=12344321 and 1234 would be the id's of each available link that would update the database by 1 in the win or loss column. So far I know to add this would be:add($row_name['wins'], 1)How do I assign this variable and allow it to pass to mysql? I assume it would be something like:Code:$winner = add($random_rows[1]['wins'], 1)How can I pass that to the db though? Hope this question makes sense. Link to comment https://forums.phpfreaks.com/topic/33407-passing-variable-to-sql-help/ Share on other sites More sharing options...
Jessica Posted January 9, 2007 Share Posted January 9, 2007 I would do$sql = "UPDATE this SET wins = wins+1 WHERE id = 4321";$sql = "UPDATE this SET loss = loss+1 WHERE id = 1234"; Link to comment https://forums.phpfreaks.com/topic/33407-passing-variable-to-sql-help/#findComment-156247 Share on other sites More sharing options...
kulmu Posted January 9, 2007 Author Share Posted January 9, 2007 Thanks that worked! Now the next question though. I am generating random id's from the database by using:[code]$sql = "SELECT id, name, wins FROM users ORDER BY rand() LIMIT 2";$sql_result = mysql_query($sql);// if records presentif (mysql_num_rows($sql_result) > 0){ // iterate through resultset // printwhile ($row = mysql_fetch_array($sql_result)) { $random_rows[] = $row;} [/code]How do carry the variables from the previous page to the current? Meaning if I click a link how do I take the previous pages randoms and apply them onto the new page? Basically I want to be able to display the results of the previous poll while displaying a new poll. I guess basically I am having a tough time trying to figure out how to set the vote.php?winner=1234&loser=4321 variable within the url and take those results and pass them onto the next page. I know if this was a form I could use the $_POST data to accomplish this. Instead I just want the link to pass the data. This make any sense?Thanks again for the help. Link to comment https://forums.phpfreaks.com/topic/33407-passing-variable-to-sql-help/#findComment-156745 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.