Problem selecting photos

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cs1h
Forum Newbie
Posts: 13
Joined: Fri Aug 31, 2007 11:39 am

Problem selecting photos

Post 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]
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
cs1h
Forum Newbie
Posts: 13
Joined: Fri Aug 31, 2007 11:39 am

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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'];
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
cs1h
Forum Newbie
Posts: 13
Joined: Fri Aug 31, 2007 11:39 am

Post by cs1h »

cheers that works great,

thanks
colin
Post Reply