Forum Moderators: coopster

Message Too Old, No Replies

Auto Fill information generated from a mysql table

         

Mckimson

10:52 pm on Jan 19, 2006 (gmt 0)

10+ Year Member



I have two tables, in one table I store information users put in through a form. These include name, email and star sign. The other table has pre written horoscope letters, one for each star sign. The letters look like this

Hi $name

Your Star Sign is $star_sign. Blah Blah Blah Blah Blah BlahBlah Blah Blah
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah BlahBlah Blah Blah
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah

Regards
Webmaster

I can link both tables through a join

$result= mysql_query("Select user.name , user.star_sign, horoscope.star_sign, horoscope.text from user, horoscope where user.star_sign=horoscope.star_sign");
$row = mysql_fetch_array($result);

$name= $row [name];
$star_sign= $row [star_sign];
$text = $row [text];

echo "$text";

The problem is that the ouput is
Hi $name

Your Star Sign is $star_sign . Blah Blah Blah Blah Blah BlahBlah Blah Blah
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah BlahBlah Blah Blah
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah

Regards
Webmaster

I would like it to fill in the various info so it looks like this. eg user = John star_sign= Pisces

Hi John.

Your Star Sign is Pisces.Blah Blah Blah Blah Blah BlahBlah Blah Blah
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah BlahBlah Blah Blah
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah

Regards
Webmaster

How can I get the letters in my table to be generated fully filled in. Is this possible? Any help would be greatly appreciated.

Regards
Mc Kimson

Mckimson

11:15 pm on Jan 19, 2006 (gmt 0)

10+ Year Member



Problem solved.

It was suggested I use the str_replace.

<?php
$result= mysql_query("Select user.name , user.star_sign, horoscope.star_sign, horoscope.text from user, horoscope where user.star_sign=horoscope.star_sign");
$row = mysql_fetch_array($result);

$name= $row [name];
$star_sign= $row [star_sign];
$text = str_replace(array('$name','$star_sign'),array($name,$star_sign),$row [text]);

echo $text;
?>

Thanks to Kenrbnsn

coopster

1:58 am on Jan 20, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, Mckimson.

And Kenrbnsn we hope to see you post here once in awhile, no sense *lurking* forever ;) We would love to see you posting at WebmasterWorld!

Thanks fellas -- coopster