View Full Version : Need some PHP expertise!
NovoOrganics
08-20-2006, 11:03 AM
Hi all,
Why doesn't this work?
<?php
$A = 'Nikki Brown';
if ("$OWNER_NAME = $A")
rewardpic = "starLVL1.jpg"
?>
<p><img name="rewardpic" src="" width="32" height="32" alt=""></p>
Regards,
Ian
You need:
if ("$OWNER_NAME == $A")
rewardpic = "startLVL1.jpg";
-Tom
NovoOrganics
08-20-2006, 09:21 PM
Sorry but that didn't work.
What im trying to do is make a little PHP code that when a user logs in a different picture is placed in the image holder.
Can someone help or show me code to do this?
Ian
lwyau
08-21-2006, 12:09 AM
<?php
$A = 'Nikki Brown';
if ("$OWNER_NAME == $A")
$rewardpic = "images/starLVL1.jpg"
echo "<p><img src=\"".$rewardpic."\" width=\"32\" height=\"32\" alt=\"\"></p>";
?>
You need the full path of the image and it is case sensitive. In the case of my calendar, I need to reference the image like this:
<img src='http://www.coolchangemusic.com/images/SmMPLogo.jpg'>
in order for it to display.
Hope this helps.
-Tom
NovoOrganics
08-22-2006, 04:35 AM
sorry, but i have used the other code and inserted the whole URL and still the page is just blank.
Not sure what im doing wrong
Ian
Try commenting out " if ("$OWNER_NAME == $A") and see if the code works. If it does, then $OWNER_NAME isn't defined, and if it doesn't then the problem is with the echo line or the pathing of the image.
This code works:
<?php
$A = 'Nikki Brown';
//if ("$OWNER_NAME == $A")
$rewardpic = "http://www.coolchangemusic.com/images/SmMPLogo.jpg";
echo "<p><img src=\"".$rewardpic."\" width=\"32\" height=\"32\" alt=\"\"></p>";
?>
-Tom
NovoOrganics
08-22-2006, 09:01 PM
Hey,
Yeah thats the problem, but $OWNER_NAME has worked for me before in other scripts. like Hello $OWNER_NAME as a welcome why not this script?
how can i define it in this script that im doing now?
Ian
Ian-
Add a line to echo $OWNER_NAME and see what it shows you. It could be that you need to do a mysql query or add an include statement to pull in the session variable. Based on what you've shown me in this post, I'm not sure wher you're getting $OWNER_NAME from?
-Tom
NovoOrganics
08-23-2006, 08:55 PM
The $OWNER_NAME is a variable that mike has been talking to me about and i have used it alot. all it does is prints the name of the person who has logged in. So for what i have used it before is created a welcome note. ie
<?php
echo "Welcome $OWNER_NAME!"
?>
which prints Welcome Ian Briggs! when they log in.
Now what im tying to do is assign the users with a picture. so if the $OWNER_NAME is "Ian Briggs" then put ian.jpg on the page or if $OWNER_NAME = "Tom" then put tom.jpg on the page.
For some reason i cannot get this to work.
Ian
Ian-
Not to get fancy on you, but eventually, you should do a mysql to search for $OWNER_NAME and return the resulting picture file. You don't want to hard-code all of the names. Did you try to echo $OWNER_NAME to see exactly what that variable is holding? If the IF statement is failing, then your problem is with this variable. Also, the == would make the variable have to match exactly (case, length, etc.). Maybe you should drop back to a single =. If you still can't get it to work, PM me and I'll take a look at it.
Let me know.
-Tom
NovoOrganics
08-30-2006, 12:09 AM
Yeah i have done almost everying.
I have tried one or two = and nothing. the echo $OWNER_NAME puts the owners name on the screen which is correct like if I logged in then echo $OWNER_NAME prints Ian Briggs on the screen.
How would you go about doing the mySQL database?
tell you what, i'll make you a login for my site: http://www.novoorganics.com
Username: tom
password: tom
so you can see what im trying to do. As i have it now, i have users being redirected to there own page. so if i have 30 users i need to create 30 pages because a picture i use (the star rewards, which you will see) is different for every user.
Creating a page for every user is going to be long and hard and not really the best way to do it but if i can get code that will place a different determined picture for each user then i will only need to create one user page for all users to be redirected to.
hope you can figure something out for me
Ian
Ian-
So I get this straight, you just want to show 1,2 or 3 stars based on the user login? If that's the case, it would be easier to just take over an unused field in the sec_users table and populate it with a number. Then you would just write a select...case statement and put it in a php file on the page.
If you want to send me the specifics of what you need, then I'll give you a hand.
-Tom
NovoOrganics
08-31-2006, 12:45 AM
Thats exactly what i want to do.
How would i go about doing that? i dont have much PHP knowledge.
Ian
Ian-
I sent you an email.
-Tom
Here's the completed code. Maybe it will help someone else. The script as written looks for the number 0-5 in the BADDRESS field of the sec_user table and displays a picture based on the value.
-Tom
<?php
// $BADDRESS2{0} returns the first character of the field
switch ($BADDRESS2{0}) {
case "5":
$rewardpic = "starLVL5.jpg";
break;
case "4":
$rewardpic = "starLVL4.jpg";
break;
case "3":
$rewardpic = "starLVL3.jpg";
break;
case "2":
$rewardpic = "starLVL2.jpg";
break;
case "1":
$rewardpic = "starLVL1.jpg";
break;
default: // otherwise
$rewardpic = "starLVL0.jpg";
}
echo "<p><img src='http://www.novoorganics.com/images/".$rewardpic."'></p>";
?>
vBulletin® v3.7.2, Copyright ©2000-2008, Jelsoft Enterprises Ltd.