Here's my code snippet.
if(preg_match("/^[ a-zA-Z1-42]+/", $_POST['name'])){
$name=$_POST['name'];
$namer=$name;
$result = mysql_query("select `resource` from resources where `resource_id` =" .$namer. "ORDER BY `resource_id` ASC ");
echo "<br/>The following nations have " .$namer. " as a resource\n";
//-query the database table
$sql="SELECT id, nation_id, ruler, resource1, resource2 FROM TS1 WHERE resource1 LIKE '%" . $name . "%' OR resource2 LIKE '%" . $name ."%'";
//-run the query against the mysql query function
$result=mysql_query($sql);
//-create while loop and loop through result set
while($row=mysql_fetch_array($result)){
$ID=$row['id'];
$Ruler=$row['ruler'];
//-display the result of the array
echo "<ul>\n";
echo "<li>" . "<a href=\"searcher.php?id=$ID\">" .$Ruler. "</a></li>\n";
echo "</ul>";
}
}
else{
echo "<p>Please enter a search query</p>";
}
}
}
Basically I have a number that's posted from a form field from another page to this page. It displays correctly on the results page but what i'm trying to do now is get that number to change based on the query at the top '' $result = mysql_query("select `resource` from resources where `resource_id` =" .$namer. "ORDER BY `resource_id` ASC "); "
So if the number 3 (which is in the `resource_id` column) was posted it will display a result (which is in the `resource` column).
But it just seems that the query isn't going through and it continues to display the 3 which was originally posted instead of changing 3 to a number in the database.
I was thinking of performing a while loop so it just just displays the result of the query.. something like this:
$name=$_POST['name'];
$namer=$name;
$result = mysql_query("select `resource` from resources where `resource_id` =" .$namer. "ORDER BY `resource_id` ASC ");
while($row = mysql_fetch_array($result))
{
echo "<br/>The following nations have " . $row['resource'] . " as a resource\n";
}
But that seems to have more problems as it doesn't display anything at all, not even the original number I had.
I don't think it's a big problem.. Maybe something i've just overlooked?