CoffeeOD Posted April 13, 2009 Share Posted April 13, 2009 Howdy, topic might be abit confusing but could not think anything better. I would need some method to change query when link is clicked, example I have now $sql = "SELECT id, img, name, level, speed, cost, type, avb FROM $tbl_name WHERE class='example' AND type='common' ORDER BY level LIMIT $start, $limit"; and this will print those information like <?php while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td class='sisa2'><img src=\"../inc/img.php?". $row['img'] . "\">"; echo "<td class='sisa2'><b><span>". $row['name'] . "</span></b></td>"; echo "<td class='sisa2'>" . $row['level'] . "</td>"; echo "<td class='sisa2'>" . $row['type'] . "</td>"; echo "<td class='sisa2'>" . $row['attpow'] . "</td>"; echo "<td class='sisa2'>" . $row['speed'] . "</td>"; echo "<td class='sisa2'>" . $row['avb'] . "</td>"; echo "<td class='sisa2'>" . $row['cost'] . "</td>"; echo "</tr>"; } ?> When link is clicked in navigation, it would change where values and print them in same page replacing previous "example" and "common" values like: WHERE class='example' AND type='special' and print them in same table depending link clicked. Hopefully this was not too confusing, quite new to this mysql & php so Im not best explaining these stuff I did read something about using GET -function and so on, but I never could get it working. Quote Link to comment https://forums.phpfreaks.com/topic/153940-solved-change-mysql-query-by-clicking-link/ Share on other sites More sharing options...
mandred Posted April 14, 2009 Share Posted April 14, 2009 Use a link such as http://www.mysite.com/page.php?value=whateverhere Then declare a safe variable, i.e. $value = mysql_real_escape_string($_GET['value']) Query the database rows whose field value is $value. I.e. "SELECT * FROM table WHERE field='$value'" Quote Link to comment https://forums.phpfreaks.com/topic/153940-solved-change-mysql-query-by-clicking-link/#findComment-809082 Share on other sites More sharing options...
Maq Posted April 14, 2009 Share Posted April 14, 2009 Here's an example for passing variables to the same page and changing the query. You can substitute your link in for the $_SERVER['PHP_SELF'], this means that it's passing it to the current URL. You should also call [man]mysql_real_escape_string()[/man] on your values if they're involved in the query, to prevent SQL injection. $start = 0; $limit = 5; $common = isset($_GET['common']) ? $_GET['common'] : 1; $example = isset($_GET['example']) ? $_GET['example'] : 1; $sql = "SELECT id, img, name, level, speed, cost, type, avb FROM $tbl_name WHERE class='$example' AND type='$common' ORDER BY level LIMIT $start, $limit"; echo "Query=> " . $sql; echo " example 123 common 456"; echo " example abc common efg"; Quote Link to comment https://forums.phpfreaks.com/topic/153940-solved-change-mysql-query-by-clicking-link/#findComment-809084 Share on other sites More sharing options...
CoffeeOD Posted April 18, 2009 Author Share Posted April 18, 2009 Thanks for advices, I got it working with mandred example and by doing that I actually learned abit more about where´s AND and OR functions, thanks alot to both of you guy, this topic can be marked as "solved" now. Quote Link to comment https://forums.phpfreaks.com/topic/153940-solved-change-mysql-query-by-clicking-link/#findComment-813451 Share on other sites More sharing options...
Maq Posted April 19, 2009 Share Posted April 19, 2009 thanks alot to both of you guy, this topic can be marked as "solved" now. That's something that you're supposed to do, the tab labeled [sOLVED]. I'll do it this time. Quote Link to comment https://forums.phpfreaks.com/topic/153940-solved-change-mysql-query-by-clicking-link/#findComment-813979 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.