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!
<?php
//Default value of this var for now
$img = null;
// Check the value of the field you are checking
if ($row['face'] == 'pos') {
$img = 'smile';
} elseif ($row['face'] == 'neg') {
$img = 'sad';
}
if ($img) {
$fullimg = 'pathtoimage' . $img . '.png'; // You name the image you are using here, or above, whichever is easier
}
?>
This is probably more complex than you want, but really all you need to do is check the value of the row you are looking for and if it is one thing, do one thing with it and if it is another then do another with it.
Everah's code isn't something you can just drop into your script and it'll magically work. You need to think about what Everah's code is doing and apply the same principle to your own code. He showed you how to do it. You're the one who actually has to write the final code.
I would not have guessed that - if I knew what I was doing I wouldn't have asked for help.
You asked for help and you got help. Now you're asking for people to do the work for you. That's not what this forum is about. You need to put a little more effort in.
What you're trying to do is replace the text you have now, $row['face'], with an image. To do that you need to add the code for an HTML image tag with a source of either the happy face or the sad face. You need to figure out how to integrate Everah's code into your script so that instead of $row['face'] it outputs the $fullimg value.
You are trying to display an image, but you forgot (or just didnt know) to use the "img" HTML tag.
Developers on these forums are more than happy to help you go 90% of the way - so long as you show you are capable (or at least willing) to go the other 10%.
<?php
// Loop the result to build our output
while ($row = mysql_fetch_array($result)) {
// Starting with an image for the face field
$img = null;
// If the face is 'pos' show a smile, if it is 'neg' show a sad
if ($row['face'] == 'pos') {
$img = '<img src="images/smile.jpg" />';
} elseif ($row['face'] == 'neg') {
$img = '<img src="images/sad.jpg" />';
}
// Now build the table row using the face image instead of the face field value
echo '<tr><td align="center">' . $row['name'] . '</td><td align="left">' . $row['com'] . '</td><td align="center">' . $row['date']. '</td><td align="center">' . $img .'</td></tr>';
}
?>
The logic is very simple in this case: If the 'face' field is 'pos' show the HTML code for the smile image. If the 'face' is 'neg' show the HTML code for the sad image. If the 'face' field is neither of these show nothing. That is what I was getting at in the first snippet I offered.
Thank You All,
Your help was greatly appreciated, with the limited knowledge I have of php I spent most of yesterday trying to resolve this problem. And spent hours looking in books and on the web for a solution. Posting the question on the forum was not my first thought.
The code I was originally given sent me looking back through the books I have to find what was missing. Yes as pointed out I had missed something fundamental and it was through lack of knowledge; not because I just expect to come to the forum and get what I want.
With the knowledge you have yes this may have seemed very simple however I had tried every possible combination that I could think of to get this to work.
Once again thank you all for your help.
Try not to let us scare you away We are a rather friendly bunch. We just get a lot of people coming here asking us to write their code for them. We are not about that. We are about helping people become better at coding PHP. We will always offer to help you. We will almost never do anything for you.