Jump to content

passing variable to sql help


kulmu

Recommended Posts

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=1234

4321 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

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 present
if (mysql_num_rows($sql_result) > 0)
{
    // iterate through resultset
    // print
while ($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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.