PHP Help

v2^

v2^

Associate
Joined
21 Oct 2002
Posts
1,075
Hello all

The Property of $killers is Saloman in my database and this is the code i am using.

---


<?
$tech = "$killers";

if ($tech == "Saloman") {
?>
<img src="../killdb/killer-images/<? print mysql_result($result,0,"killers"); ?>.jpg" alt="<? print mysql_result($result,0,"killers"); ?>, Eve Online" width="80" height="80" style="border-style: solid; border-width: 1px; border-color: #ffffff;">
<?
}

else {
?>
<img src="../killdb/killer-images/Unknown.jpg" alt="<? print mysql_result($result,0,"killers"); ?>, Eve Online" width="80" height="80" style="border-style: solid; border-width: 1px; border-color: #ffffff;">
<?
}
?>

--

So if Tech = Saloman if will show his image if not it will shown another image but it will not work. What am i doing wrong :(

All help apreciated as im banging my head on the desk.

Thanks in advace.
 

v2^

v2^

Associate
OP
Joined
21 Oct 2002
Posts
1,075
Seft said:
what is the error?

EDIT could be first line, remove speech marks.

It shows the unknown image when it should show the Saloman Image.

I tried without the speech marks and its still the same :(
 
Soldato
Joined
18 Sep 2003
Posts
4,104
Location
Radlett
what url is it giving for the unknown image.

It would be a good idea to have some echos in the if loops to see if it's correctly choosing the first one.

Oh and print $tech too.
 

v2^

v2^

Associate
OP
Joined
21 Oct 2002
Posts
1,075
Seft said:
what url is it giving for the unknown image.

It would be a good idea to have some echos in the if loops to see if it's correctly choosing the first one.

Oh and print $tech too.

Ok i changed the print in the image url to $tech if thats what you meant, this is the page in question http://guc.webinventions.co.uk/killdb/killinfotest.php?id=2786

---

<?
$tech = $killers;

if ($tech == "Saloman") {
?>
<img src="../killdb/killer-images/<? print mysql_result($tech,0,"killers"); ?>.jpg" alt="<? print mysql_result($result,0,"killers"); ?>, Eve Online" width="80" height="80" style="border-style: solid; border-width: 1px; border-color: #ffffff;">
<?
}

else {
?>
<img src="../killdb/killer-images/Unknown.jpg" alt="<? print mysql_result($result,0,"killers"); ?>, Eve Online" width="80" height="80" style="border-style: solid; border-width: 1px; border-color: #ffffff;">
<?
}
?>
 
Last edited:

v2^

v2^

Associate
OP
Joined
21 Oct 2002
Posts
1,075
Beansprout said:
What's $killers?

There's also no point doing $tech = $killers, you're just creating another variable which adds to the confusion :)

Killers is a field in my database that stores the a persons name from a killmail in eve online. This one im testing has the property Saloman.
 
Soldato
Joined
18 Oct 2002
Posts
4,892
long shot but you could try doing a trim on $tech as some whitespaces might be playing with the if statement
 

v2^

v2^

Associate
OP
Joined
21 Oct 2002
Posts
1,075
Gman said:
long shot but you could try doing a trim on $tech as some whitespaces might be playing with the if statement

Any chance you could helkp me on that ;)

$tech = trim(substr((chr(13) ,""));

??
 
Soldato
Joined
18 Oct 2002
Posts
4,892
not 100% sure as i've been coding in .net and jsp and java for the past 6 months but.
if I remember correct its just:

$tech = trim($killers);

that should trim all leading and trailing white spaces, the way you where leading to was to split the string which you don't need here.
 

v2^

v2^

Associate
OP
Joined
21 Oct 2002
Posts
1,075
no joy :(

<?
$tech = "$killers";
$tech = trim($killers);

if ($tech == "Saloman") {
?>
<img src="../killdb/killer-images/<? print mysql_result($tech,0,"killers"); ?>.jpg" alt="<? print mysql_result($result,0,"killers"); ?>, Eve Online" width="80" height="80" style="border-style: solid; border-width: 1px; border-color: #ffffff;">
<?
}

else {
?>
<img src="../killdb/killer-images/Unknown.jpg" alt="<? print mysql_result($result,0,"killers"); ?>, Eve Online" width="80" height="80" style="border-style: solid; border-width: 1px; border-color: #ffffff;">
<?
}
?>
 
Soldato
Joined
18 Oct 2002
Posts
4,892
try this insted , see what gets printed to the screen with echo($teck) does it say Saloman exactly ? same case and everything ?

The main problem were haivng is where not sure what $killers actualy is, is it a string, an array etc.

<?
$tech = trim($killers);
echo($tech);
if ($tech == "Saloman") {
?>
<img src="../killdb/killer-images/<? print mysql_result($tech,0,"killers"); ?>.jpg" alt="<? print mysql_result($result,0,"killers"); ?>, Eve Online" width="80" height="80" style="border-style: solid; border-width: 1px; border-color: #ffffff;">
<?
}

else {
?>
<img src="../killdb/killer-images/Unknown.jpg" alt="<? print mysql_result($result,0,"killers"); ?>, Eve Online" width="80" height="80" style="border-style: solid; border-width: 1px; border-color: #ffffff;">
<?
}
?>
 
Last edited:
Soldato
Joined
18 Oct 2002
Posts
4,892
looks to me like its saloman with a lower case 's' and your compairing it against Saloman with an uppercase 'S'

try changing your database entry to a uppercase 'S' or change your if statement Saloman to a lowercase 's'
 

v2^

v2^

Associate
OP
Joined
21 Oct 2002
Posts
1,075
Gman said:
looks to me like its saloman with a lower case 's' and your compairing it against Saloman with an uppercase 'S'

try changing your database entry to a uppercase 'S' or change your if statement Saloman to a lowercase 's'

Awesome it works a treat :)

Thanks so much for the help.
 

v2^

v2^

Associate
OP
Joined
21 Oct 2002
Posts
1,075
Im back !

Hehe

So if i want multiple do i do it like this if ($tech == "'saloman','v2gbr'")

?
 
Associate
Joined
16 May 2005
Posts
680
It sounds like you're hard coding in some stuff that should probably be done a different way.

Are they individual entries or will you have a set list of names that people reach? Might be worth having a killers_table with killer_id and killer_image and just give the user a killer_id in their db.

Anyway, if you want to do ORs in the if do
if($tech == "saloman" || $tech == "v2gbr")

If you're using different images
if($tech == "saloman")
{
//saloman image
}
elseif($tech == "v2gbr")
{
//v2gbr image
}
else
{
//default image
}
 
Man of Honour
Joined
31 Jan 2004
Posts
16,335
Location
Plymouth
Killers is a field in my database that stores the a persons name from a killmail in eve online. This one im testing has the property Saloman.
I'm fairly sure I knew that - my point was what is actually in it because it might not always be what you expect, case sensitivity in point:)

var_dump() is very useful, as is tracing through the code from the start - "where does that variable come from? what created it? did I make a typo? am I sure?"

We're all humans and we make mistakes. Our brains re-interpret things, skip over similar characters, adjust based on past experiences, and so on.

Computers don't. They run, like clockwork, totally regularly and totally correctly. That's what's frustrating - they do what they're told, but we tell them the wrong things :p

Glad it's working now though :)
 
Back
Top Bottom