0

Hi..
I try to make a link while calling the data in php.
This is the code :

while ($row = mysql_fetch_array($subject_set)) {

                   echo <a href="example.php">$row["menu_name"]</a>;

                   $page_set = mysql_query("SELECT * FROM pages WHERE subject_id={$row["id"]}");
                     if (!$page_set) {
                        die ("Database query failed: " . mysql_error());
                        }

                    while ($page= mysql_fetch_array($page_set)) {
                        echo $page["menu_name"]."<br/>";
                        }

                  }

could someone fix this line for me ? :

echo <a href="example.php">$row["menu_name"]</a>;

because i keep getting this error :

Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\newcompany\content.php on line 38


Thank You..

Edited by samsons17: n/a

5
Contributors
13
Replies
15
Views
7 Years
Discussion Span
Last Post by Designer_101
-1

could someone fix this line for me ? :

PHP Syntax (Toggle Plain Text)

1.
echo <a href="example.php">$row["menu_name"]</a>;

Just use single quot after n before like this.

echo '<a href="example.php">$row["menu_name"]</a>';

I hope this will help you. :)

0

Echo statements must have quotes surrounding them as shown bellow.
Its best to use double quotes for the function if the subject inside has quotes aswell, these should be single.

Use this:

echo "<a href='example.php'>$row['menu_name']</a>";

Hope this helps

-1

designer's solution is correct, for more than one reason, importantly,,
php will parse dQuoted text for variables and replace them with the value echo "i want $breakfast"; will render as I want BACON single quotes wil not parse the variables and of course,,,
WoNt WoRk

Edited by almostbob: n/a

-1

designer's solution is correct, for more than one reason, importantly,,
php will parse dQuoted text for variables and replace them with the value
echo "i want $breakfast";
will render as
I want BACON
single quotes wil not parse the variables and of course,,,
WoNt WoRk

yes designer is rite but i was not wrong. as u told in your example.we can use this example with single quotes also.something like this.

$breakfast = 'BACON';
echo 'i want '.$breakfast;

its output will be same as you shown.

I want BACON

i hope you can understand my example also.

Thanks.

Votes + Comments
this is different code to your prior post
-1

reread My post, it states Designers code is correct and states the reason.
there is no statement that your code is wrong
that your second code sample is different, confirms the first sample is not appropriate for this task
single quotes are better for straight text, the php interpreter does not waste time looking for variables so they execute faster
however dQuoted text and variables is simpler , more intuitive, to read and lay out than:: open close variable open close variable open close variable open close;
with single quoted text

Edited by almostbob: n/a

0

Almost bob's correct about php interpreting the double quotes.

And yes pbcomput you're second answer is more appropriate for this topic.

Hope this all helps :)

0

peoples...Thank you so much for answering..
but i still got problem here :

1)First when i tried to use like what pbcomput told which is :

'<a href="example.php">$row["menu_name"]</a>';

I got this result :
$row["menu_name"] <----its not echo the data instead what code that i wrote.
History
Mission
$row["menu_name"] <----its not echo the data instead what code that i wrote.
consultation

2)Second,when i tried to code like what Designer_101 told which is :

echo "<a href='example.php'>$row['menu_name']</a>";

then,i got this error :
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs\newcompany\content.php on line 38

So,it seems that both of the solution are not working here.Why is that so?

Thank You for helping..

0

hi people,
I finally got the solution by my self..

I figure out that putting the curly braces will solve my problem which is :

echo "<a href='example.php'>{$row['menu_name']}</a>".;

but i myself do not know why this is working.Could you all figure it out for me?

Thank You :)

0

assuming that the error is line 38
It means that $row includes unescaped control characters that interfere with php
the database contents should
be sanitised before being added
checked on update
checked on extraction to prevent erroneous data and to prevent deliberate sql_injection

Edited by almostbob: n/a

0

Hi

I can't think why this wouldn't have worked but its perfectly correct code. It might have been something else in your document.

To explain your question about curly braces, they are simply doing the same as what expanding the function would do.
For example, this:

echo "<a href='example.php'>{$row['menu_name']}</a>";

In respect is the same as writing this:

echo "<a href='example.php'>".$row['menu_name']."</a>";

Hope this helps :)

0

owh 0kay....
even if i still could figure it out,but you all have make it clearer for me now..

Thank You Designer and all of you...
you all have helped a lot :)

but still if someone could figure it out,please reply it here..
Thanks..

0

No problem Samsons17, always good to help others as this forum has helped me so much in the past.

I think the problem wasn't so much to do with your echo statement but like almostbob suggested something previous in the rendering of your page.

Good luck! :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.