How would one use the mysql/php $list['key'] inside a php echo i.e
echo "<p> My Text . $list[''] . </p>";
Thanks In Advance
How would one use the mysql/php $list['key'] inside a php echo i.e
echo "<p> My Text . $list[''] . </p>";
Thanks In Advance
It is as simple as that:
echo "<p> My Text $list[index] </p>";
N. b.: you do not use single quotes ('
) for the index as you usually would, like in $a=$list['index'];
, since the whole thing is already enclosed in double quotes ("
).
Correction: Just found out, with indices like 'a b' you still do need the quotes! (Thanks, Jon!)
Edit: (response to comment)
That is a competely different thing! Use
list($var1,$var2) = mysql_fetch_assoc($result);
instead. The list()
-construct (is it a function?!?) extracts the values out of the assigned array (in your case the result of your mysql_fetch_assoc()
-function). Assuming, that your result set returns values for two columns (otherwise you will have to supply more variables in list()
). And then place the variables into your text like
echo "<p> My Text $var1 and somewhere maybe also $var2 ... </p>";
Still, since you are using mysql_fetch_assoc($result)
you could do
$z=mysql_fetch_assoc($result);
echo "<p> My Text $z[field1] and somewhere maybe also $z[field2] ... </p>";
with field1
and field2
being the actual column names from your MySQL table.
It is customary on this site now, to also warn you of the dangers of still using the deprecated mysql_*
functions. You should change to the more secure and modern versions of mysqli_*
...