Jump to content

[SOLVED] Echo WHERE IF


markvaughn2006

Recommended Posts

This one has really got me stumped...

I need to display everybody with the location =$userlocation and wanted_lvl=1. But.. I need to also somehow include an IF that will check a field from the mysql query against a field in the logged in users row..

 

So what this boils down to is I need to display everyone who's location equals $userlocation and wanted_lvl equals 1 but only show the people that who have less "stealth" than the logged in user has "vision". So it would show some people who have a lower stealth than your vision but it wouldn't show the people that have a higher stealth than your vision.

 

<?php

$result = mysql_query("SELECT user_name, location_message FROM users_tbl

WHERE location='$userlocation' AND wanted_lvl='1'")

  or die(mysql_error());

while ($row = mysql_fetch_array($result)) {

  echo '<form target="actions" method="post" action="includes/report.php"><input type="submit" value="Report" /><font color="red">'.$row['user_name'].'</font><input type="hidden" name="reported" value="'.$row['user_name'].'" /></form>';

  }

?>

 

 

Thanks for any help!! Sorry if this in the wrong forum, but it's more the php than the mysql i'm having a problem with

Link to comment
https://forums.phpfreaks.com/topic/178077-solved-echo-where-if/
Share on other sites

If I'm understanding your correctly this can all, and should all be done within the query itself.

 

eg.

 

$result = mysql_query("SELECT user_name, location_message FROM users_tbl
WHERE location='$userlocation' AND wanted_lvl='1' AND stealth < '$uservision'");

Where $uservision contains the vision value for the current user.

Link to comment
https://forums.phpfreaks.com/topic/178077-solved-echo-where-if/#findComment-938947
Share on other sites

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.