Hi

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
Thanks

$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>
</div>
                              </li>';

Insead of:

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

Try:

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

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

Thanks for your reply but that option does not work either

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

Thanks

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

eg
<?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

Thanks

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:)

:) Only a pleasure. Happy coding.

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.