Start New Discussion within our Web Development Community


I have variables set in the head of the page as they are used for other parts of the page.

I have a problem where by I am trying to get the variable to echo out in the result.

I have tried several ways but either ther eis an error or the variable $txt2 does not show in the page.

Its working in the query but not in the result

Hope you can help

$result = mysql_query("SELECT * FROM table1, table2 Where field1 = '$txt2' and field2 = table1.field2") or trigger_error(mysql_error().$sql);
while($row = mysql_fetch_array($result)){

echo '<li>

                                  <h2><a href="' . $row['$txt2'] . '/' . $row['$txt2'] . '.php">' . $row['title'] . '</a></h2>

Insead of:

<h2><a href="' . $row['$txt2'] . '/' . $row['$txt2'] . '.php">' . $row['title'] . '</a></h2>


<h2><a href="' . $row['txt2'] . '/' . $row['txt2'] . '.php">' . $row['title'] . '</a></h2>

I don't understand the purpose of '$txt2' etc here, in this context.

If I read this correctly, you already returned a value for $txt2, When making the call to your database, you now need to echo out the field values -

//You had this -
<h2><a href="' . $row['$txt2'] . '/' . $row['$txt2'] . '.php">' . $row['title'] . '</a></h2>

//Try this
<h2><a href="' . $row['field1'] . '/' . $row['field1'] . '.php">' . $row['title'] . '</a></h2>

@mpc123 - What is '$txt'? I don't understand, it's probably your query that is the fault here, not returning any data.

Hi Thanks for your reply

I also need to echo out a points the value of $txt2


As per first post I have a variable in my head that is used for the rest of the page

<?php $txt2 = "whatever"?>

then that is echoed out throughout the page where required.

Here I have a problem getting that to echo in the first post code


Hi Sorry looking at it you are correct, I simply need to take the info from the table rather than the variable, Silly me :)

Thanks for your replies guys, sorry:)

This question has already been answered. Start a new discussion instead.