Page 1 of 1
Replacing "Something" with SessionId
Posted: Thu Mar 18, 2004 10:03 am
by amit_tgo
Hello,
I have a slight problem.
I shall explain the same with a example.
Say for example I have a value in a particular field of my database
"Hello Something How are you"
I can manage to print this value on the page without any problem.
The user has logged in and he receives the message "Hello Something How are you"
I wish to Replace the text "Something" with his login sessionid
<?echo "$userid";?> this helps me print the userid of the person logged in on the page.
However, i am clueless on how i could replace some text that am fetching from the database and then replacing the same to get the logged in userid.
Help Please
Regards
Amit
Posted: Thu Mar 18, 2004 10:08 am
by markl999
Tried
http://php.net/str_replace ?
Though i'm not sure why you're not just doing, echo 'Hello '.$userid.'. How are you?';
Posted: Thu Mar 18, 2004 10:15 am
by amit_tgo
Hello Mark,
Thanks i saw the url and its of help, However am a total fool when it comes to php. The application am building is actually a code i found somewhere and am trying to modify the same
So i cant really figure out what to do. Could you provide me with a example that i would require. I can then make the neccessary changes to the script.
Sorry for the trouble
Regards
Amit
Posted: Thu Mar 18, 2004 10:18 am
by markl999
Code: Select all
<?php
$thetext = 'Hello Something, How are you';
$userid = 'Fred';
echo str_replace('Something', $userid, $thetext);
//this outputs Hello Fred, How are you
?>
Hello Mark
Posted: Thu Mar 18, 2004 10:27 am
by amit_tgo
Thanks,
But am a touch confused, the text "Hello Something How are you" is coming in from the database and printing on the page.
Will this still work with the same?
Do i need to just copy paste this code?
or is there someway to implement it
Thanks Again
Amit
Posted: Thu Mar 18, 2004 10:34 am
by markl999
Well without seeing your exact code, it's hard to say exactly what you need to do. But the theory is the same. Maybe post the bit of code that does the "printing on the page" ?
Posted: Thu Mar 18, 2004 10:44 am
by amit_tgo
<?
mysql_connect($server, $db_user, $db_pass)
or die ("Database CONNECT Error (line 18)");
$result75 = mysql_db_query($database, "select * from interactive where progid='$progid'and id =
'$id'")
or die ("Database INSERT Error line 19");
if (mysql_num_rows($result75))
{
print "<font face=arial><TABLE width=100% align=center>";
while ($qry = mysql_fetch_array($result75))
{
print "<tr><td>";
print "<textarea name = domain2 cols=60 rows=5>";
print $qry[text];
print "</textarea>";
}
print "</TABLE>";
print "</tr></td>";
print "<br><br>";
} } }
?>
That's the part
Thanks & Regards
Amit
Posted: Thu Mar 18, 2004 10:47 am
by markl999
Well, the only place i can see it going is :
print $qry[text];
So try replacing that with :
echo str_replace('Something', $userid, $qry['text']);
But i'm still not 100% sure which vars ar what, eg where $userid comes from etc..but that looks like the place to be doing it.
Posted: Thu Mar 18, 2004 11:03 am
by amit_tgo
ThankYou ThankYou ThankYou
is all i can say - You've solved my problem in 10 mins - something i took a weird 11 hours
Thanks Again Markl999
May God Bless
Regards
Amit