1,105,254 Community Members

Variable in mysql_fetch_array

Member Avatar
mpc123
Junior Poster
160 posts since Aug 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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>';
Member Avatar
phorce
Veteran Poster
1,005 posts since Jul 2011
Reputation Points: 105 [?]
Q&As Helped to Solve: 133 [?]
Skill Endorsements: 29 [?]
Featured
 
0
 

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.

Member Avatar
mpc123
Junior Poster
160 posts since Aug 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks for your reply but that option does not work either

Member Avatar
AndreRet
Industrious Poster
4,492 posts since Jan 2008
Reputation Points: 362 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 24 [?]
 
0
 

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>
Member Avatar
phorce
Veteran Poster
1,005 posts since Jul 2011
Reputation Points: 105 [?]
Q&As Helped to Solve: 133 [?]
Skill Endorsements: 29 [?]
Featured
 
0
 

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

Member Avatar
mpc123
Junior Poster
160 posts since Aug 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi Thanks for your reply

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

Thanks

Member Avatar
mpc123
Junior Poster
160 posts since Aug 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
mpc123
Junior Poster
160 posts since Aug 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Question Answered as of 1 Year Ago by phorce and AndreRet
Member Avatar
AndreRet
Industrious Poster
4,492 posts since Jan 2008
Reputation Points: 362 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 24 [?]
 
0
 

:) Only a pleasure. Happy coding.

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article