Jump to content

Recommended Posts

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 :P

 

I did read something about using GET -function and so on, but I never could get it working.

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'"

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";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.