redarrow Posted February 25, 2008 Share Posted February 25, 2008 does this code seem workable cheers.... <?php $x=$_POST['x']; $database_links=array("google","msn","yahoo","phpfreaks"); foreach($database_links as $x){ echo "<br><a href='http://$x.com'>$x</a><br>"; switch($x){ case(google); $x=$x[0]; $sql; break; case(msn); $x=$x[1]; $sql; break; case(yahoo); $x=$x[2]; $sql; break; case(phpfreaks); $x=$x[3]; $sql; break; } $sql="UPDATE counter set count=count+1 WHERE x='$x'"; $res=mysql_query($sql)or die(mysql_error()); } } ?> Quote Link to comment Share on other sites More sharing options...
Orio Posted February 25, 2008 Share Posted February 25, 2008 This code is messed up. I don't think it will do what you expect it to do. What exactly do you want it to do? Increase a counter to the link selected via a form and to echo it's link? Orio. Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 25, 2008 Author Share Posted February 25, 2008 this should work........ <?php //database connection $x=$_POST['x']; // post x $database_links=array("google","msn","yahoo","phpfreaks"); //make array foreach($database_links as $x){ //loop array echo "<br><a href='http://$x.com'>$x</a><br>";// use array info switch($x){ // create a switch for varable x case(google); // if google goto google in the database and update database with a added 1 $x=$x[0]; database($x); break; case(msn); // if msn goto msn in the database and update database with a added 1 $x=$x[1]; database($x); break; case(yahoo); // if yahoo goto yahoo in the database and update database with a added 1 $x=$x[2]; database($x); break; case(phpfreaks); // if phpfreaks goto phpfreaks in the database and update database with a added 1 $x=$x[3]; database($x); break; } } function database($x){ $sql="UPDATE counter set count=count+1 WHERE x='$x'"; $res=mysql_query($sql)or die(mysql_error()); } ?> Quote Link to comment Share on other sites More sharing options...
Orio Posted February 25, 2008 Share Posted February 25, 2008 First of all, after each case should come ":" and not a semicolon. Second, you are using $x twice - to get the post data, and as the value in the foreach. Could lead to unexpected results. Third, your script updates every single one of the sites (because you go over all of the sites) - you are not using the given post data (that's because you used twice $x and that got you confused). I think what you meant to do is: <?php $x = $_POST['x']; $database_links = array("google", "msn", "yahoo", "phpfreaks"); if(in_array($x, database_links)) { echo "<br><a href='http://www.{$x}.com'>{$x}</a><br>"; database($x); } function database($x) { $sql="UPDATE counter set count=count+1 WHERE x='$x'"; $res=mysql_query($sql)or die(mysql_error()); } ?> Orio. 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.