jd2007 Posted July 17, 2007 Share Posted July 17, 2007 <?php $db=mysql_connect("localhost", "root") or die(mysql_error()); mysql_select_db(database); for ($id=1; $id<some code; $id++) { $query="SELECT name, worked, notworked, romno FROM games WHERE id='$id'"; $result=mysql_query($query); $row = mysql_fetch_row($result); $total=$row[2]+$row[3]; echo "<span class=''><pre> $row[1] <a href='deletegames.php'>[x]</a> <a href='editgames.php'>[-]</a> $row[4] This link worked for $row[2] out of $total people. DID THIS LINK WORK FOR YOU ?</pre></span>"; echo "<br>"; } ?> the above lists all games which is in a database (in admin view)... the x link is used to delete a game and [-] edit is used to edit a game...what i want now is...if admin clicks delete for a particular game...deletegames.php sends a query to database and deletes that game ? will php know for which game the delete link was clicked ? if it doesn't know, what to do ? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 17, 2007 Share Posted July 17, 2007 Yes. You pass a variable in the URL string. Fore example: <a href="yourpage.php?yourvar=somevalue&foo=bar&id=5">your link</a> yourpage.php: <?php $yourvar = $_GET['yourvar'];//contains somevalue $foo = $_GET['foo']; //contains bar $id = $_GET['id'];//contains 5; ?> As you can see, you separate the differant variables in the URL with an ampersand(&) Quote Link to comment Share on other sites More sharing options...
jd2007 Posted July 17, 2007 Author Share Posted July 17, 2007 thanks ! this is code for worked.php: <?php $id = $_GET["var"]; $db=mysql_connect("localhost", "root") or die(mysql_error()); mysql_select_db("ndsrom"); $query="SELECT worked FROM games WHERE id='$id'"; $result=mysql_query($query); $a = mysql_fetch_row($result); $a[0]++; $query2="UPDATE games SET worked = '$a[0]' WHERE id = '$id'"; $result2=mysql_query($query2); if ($result2) { include("index.php"); } else { include("index.php"); } ?> u see when index.php is displayed , on the url on the address bar still displayed, so when anyone hits refresh, it repeats worked.php which i don't want...i only want worked.php to execute when a user clicks yes... Quote Link to comment Share on other sites More sharing options...
jd2007 Posted July 17, 2007 Author Share Posted July 17, 2007 never mind, i solved it...thank you... Quote Link to comment Share on other sites More sharing options...
jd2007 Posted July 17, 2007 Author Share Posted July 17, 2007 what i did was make to user click a link to go home...but if i use the code worked.php above, it doesn't make the $_id increase by 2. see $_id in my first post for this thread...pls help ? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 17, 2007 Share Posted July 17, 2007 Im not really sure if this is exactly what your question is, since im a little confused by that. However, when you are adding to a field in the database, there is no need to retreive the value first. You can do: <?php mysql_query("UPDATE `games` SET `worked` = `worked` + '1' WHERE id = '$id'") or die(mysql_error()); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.