Hello,

im unsure how to fetch a database row that includes php,

i have a row in my database that displays a marquee saying 'welcome $username'

i have connected to the database but the php on page shows 'welcome $username'
how would i get it to state the username instaed of $username

$query = mysql_query("SELECT * FROM marquees");
$results = mysql_fetch_array($results);

$home = $results['home'];

echo $home;

Recommended Answers

All 7 Replies

$query = mysql_query("SELECT * FROM marquees");
while($results = mysql_fetch_array($query)){
 
$home = $results['home'];
 
echo $home;
}

This will echo each result from your database query.

i have tried that but all i get is $username not the persons username.

Member Avatar for diafol
echo 'welcome $username'; //gives the literal $username
//use double quotes to parse the variable:

echo "welcome $username";

im my database is

welcome $username

when the user logs in i want to be able to show the messge from database but with the users username in the place of $username

Member Avatar for diafol

You've got 'welcome $username' as data in your DB??

OKay, use str_replace().

You've got 'welcome $username' as data in your DB??

OKay, use str_replace().

Woow, guess who's back :D

As far as I understand, you have the word $username stored in your database?

Then it will print $username since it is just text.

You need the get the actual user name from the session.

Do I miss anything here?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.