Page 1 of 1

Problem selecting photos

Posted: Mon Sep 17, 2007 10:27 am
by cs1h
pickle | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,

I have a search script for my databases and I want it to be able to get a certain picture from a folder on the server that is relevent to its country and type. For example if someone selects germany and news it should gather the germanynews.png pic. 

This is my script so far, 

[syntax="php"]<?


mysql_connect("localhost","xxx","yyy"); 


mysql_select_db("real") or die("Unable to select database"); 

$keywords = preg_split("/[\s,]+/", trim($_POST['keyword']));
$sql = "SELECT * FROM items WHERE country='" . mysql_real_escape_string($_POST['menuFilesDMA']) . "' AND type='" . mysql_real_escape_string($_POST['Type']) . "' AND Abstract LIKE '%$keyword%'";

$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);
if($num_rows == 0) {
echo "No results please try a different <a href=asearch.html>search</a>.";
} else {
while($row = mysql_fetch_array($result)) {
echo "<img src=http://www.myroho.com/searchthumbs/$Country$Type.png> <br>"; // <---I want this line to get the picture--->
echo "<b>Name:</b> ".$row['name'] . "<br> "; 
echo "<b>Email:</b> ".$row['Email'] . " <br>"; 
echo "<b>Country:</b> ".$row['Country'] . "<br> "; 
echo "<b>Type:</b> ".$row['Type'] . " <br>";
echo "<b>Title:</b> ".$row['Title'] . "<br> "; 
echo "<b>Abstract:</b> ".$row['Abstract'] . " <br>"; 
echo "<b>Article:</b> ".$row['Article'] . " <hr>"; 
}
}
?> 

If any one can help me work out how to do this it would be much appriciated.

Cheers
Colin


pickle | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Sep 17, 2007 10:59 am
by pickle
You haven't really described what your problem is. Yes we know what you're trying to do, but what have you tried that is currently causing you a problem?

You don't have any variable $keyword, like in your query - you're setting $keywords.

I've also removed your database credentials from your post.

Posted: Mon Sep 17, 2007 11:17 am
by cs1h
my problem is with the line

Code: Select all

echo "<img src=http://www.myroho.com/searchthumbs/$Country$Type.png> <br>";
I don't know how to phrase it so that it will take the information about the country and type and match it up so that it selects the right picture from my server. All the pictures that it has to choose from have a name that consists of the country and type i.e. italynews.png, i need to be able to select them from the search results.

Cheers,
Colin

Posted: Mon Sep 17, 2007 11:22 am
by pickle
You're never setting the $Country or $Type variables. I imagine you're missing these lines:

Code: Select all

$Country = $row['country'];
$Type = $row['type'];

Posted: Mon Sep 17, 2007 11:44 am
by cs1h
cheers that works great,

thanks
colin