954,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help! echo herf variable, automatically link to the corresponding pages

Now i extract data from mysql database, and echo them in a table.

In the last column of each row, i made a link. It link to the corresponding page according to the value of first column in the row.

Now i can't get the solution and have some errors.

Here is my code:

<table id="t" border="1">
		<tr>
			<th>SUJET</th>
			<th>DATE</th>
			<th>NATURE</th>
			<th>ACTION</th>
			<th>NON DE DECIDEUR</th>
			<th>DETAIL</th>
		</tr>
	<?php
		$conn = mysql_connect("localhost","root","") or die("Sorry, can't connect: ".mysql_error());
		mysql_select_db($db);
		$query = "SELECT sujet, bdate, nature, adetail, decideur FROM besoin";
		$result = mysql_query($query, $conn) or die("Sorry, don't get result for error: ".mysql_error());
		while($row = mysql_fetch_assoc($result)){
			echo "<tr><td>".$row["sujet"]."</td>";
			echo "<td>".$row["bdate"]."</td>";
			echo "<td>".$row["nature"]."</td>";
			echo "<td>".$row["adetail"]."</td>";
			echo "<td>".$row["decideur"]."</td>";
			echo "<td><a href=\"$row[\"sujet\"].php\" alt='autosujet.php'>DETAIL</a></td>";
			echo "</tr>";
		}
	?>


Error:

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\CRM1.11\pages\pperso\bes\list.php on line 38
garcon1986
Light Poster
27 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

i know it's the problem of

echo "<td><a href=\"$row[\"sujet\"].php\" alt='autosujet.php'>DETAIL</a></td>";


.

But i can't solve it.

Welcome for any suggestions!!! Thanks.

garcon1986
Light Poster
27 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

i have changed the code to:

echo "<td><a href=\"".$row['sujet']."\" alt='autosujet.php'>DETAIL</a></td>";

Now it works like i can link it to variable $row['sujet']. But i want to link it to $row['sujet'].php.

Anyone has an idea???? Thanks in advance.

garcon1986
Light Poster
27 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

Now i extract data from mysql database, and echo them in a table.

In the last column of each row, i made a link. It link to the corresponding page according to the value of first column in the row.

Now i can't get the solution and have some errors.

Here is my code:

<table id="t" border="1">
		<tr>
			<th>SUJET</th>
			<th>DATE</th>
			<th>NATURE</th>
			<th>ACTION</th>
			<th>NON DE DECIDEUR</th>
			<th>DETAIL</th>
		</tr>
	<?php
		$conn = mysql_connect("localhost","root","") or die("Sorry, can't connect: ".mysql_error());
		mysql_select_db($db);
		$query = "SELECT sujet, bdate, nature, adetail, decideur FROM besoin";
		$result = mysql_query($query, $conn) or die("Sorry, don't get result for error: ".mysql_error());
		while($row = mysql_fetch_assoc($result)){
			echo "<tr><td>".$row["sujet"]."</td>";
			echo "<td>".$row["bdate"]."</td>";
			echo "<td>".$row["nature"]."</td>";
			echo "<td>".$row["adetail"]."</td>";
			echo "<td>".$row["decideur"]."</td>";
			echo "<td><a href=\"$row[\"sujet\"].php\" alt='autosujet.php'>DETAIL</a></td>";
			echo "</tr>";
		}
	?>

Error:

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\CRM1.11\pages\pperso\bes\list.php on line 38
<table id="t" border="1">
		<tr>
			<th>SUJET</th>
			<th>DATE</th>
			<th>NATURE</th>
			<th>ACTION</th>
			<th>NON DE DECIDEUR</th>
			<th>DETAIL</th>
		</tr>
	<?php
		$conn = mysql_connect("localhost","root","") or die("Sorry, can't connect: ".mysql_error());
		mysql_select_db($db);
		$query = "SELECT sujet, bdate, nature, adetail, decideur FROM besoin";
		$result = mysql_query($query, $conn) or die("Sorry, don't get result for error: ".mysql_error());
		while($row = mysql_fetch_assoc($result)){
			echo '<tr><td>'.$row["sujet"].'</td>';
			echo '<td>'.$row["bdate"].'</td>';
			echo '<td>'.$row["nature"].'</td>';
			echo '<td>'.$row["adetail"].'</td>';
			echo '<td>'.$row["decideur"].'</td>';
			echo '<td><a href="'.$row['sujet'].'".php" alt="autosujet.php">DETAIL</a></td>';
			echo '</tr>';
		}
	?>
alagirinetaxis
Newbie Poster
15 posts since Oct 2009
Reputation Points: 10
Solved Threads: 3
 

Hi Use This

<table id="t" border="1">
		<tr>
			<th>SUJET</th>
			<th>DATE</th>
			<th>NATURE</th>
			<th>ACTION</th>
			<th>NON DE DECIDEUR</th>
			<th>DETAIL</th>
		</tr>
	<?php
		$conn = mysql_connect("localhost","root","") or die("Sorry, can't connect: ".mysql_error());
		mysql_select_db($db);
		$query = "SELECT sujet, bdate, nature, adetail, decideur FROM besoin";
		$result = mysql_query($query, $conn) or die("Sorry, don't get result for error: ".mysql_error());
		while($row = mysql_fetch_assoc($result)){
			echo '<tr><td>'.$row["sujet"].'</td>';
			echo '<td>'.$row["bdate"].'</td>';
			echo '<td>'.$row["nature"].'</td>';
			echo '<td>'.$row["adetail"].'</td>';
			echo '<td>'.$row["decideur"].'</td>';
			echo '<td><a href="'.$row['sujet'].'".php" alt="autosujet.php">DETAIL</a></td>';
			echo '</tr>';
		}
	?>
alagirinetaxis
Newbie Poster
15 posts since Oct 2009
Reputation Points: 10
Solved Threads: 3
 

Hi Use This

<table id="t" border="1">
		<tr>
			<th>SUJET</th>
			<th>DATE</th>
			<th>NATURE</th>
			<th>ACTION</th>
			<th>NON DE DECIDEUR</th>
			<th>DETAIL</th>
		</tr>
	<?php
		$conn = mysql_connect("localhost","root","") or die("Sorry, can't connect: ".mysql_error());
		mysql_select_db($db);
		$query = "SELECT sujet, bdate, nature, adetail, decideur FROM besoin";
		$result = mysql_query($query, $conn) or die("Sorry, don't get result for error: ".mysql_error());
		while($row = mysql_fetch_assoc($result)){
			echo '<tr><td>'.$row["sujet"].'</td>';
			echo '<td>'.$row["bdate"].'</td>';
			echo '<td>'.$row["nature"].'</td>';
			echo '<td>'.$row["adetail"].'</td>';
			echo '<td>'.$row["decideur"].'</td>';
			echo '<td><a href="'.$row['sujet'].'".php" alt="autosujet.php">DETAIL</a></td>';
			echo '</tr>';
		}
	?>

Thanks a lot for your posting. You are almost there.

I changed my code based on yours. Just delete a " and it works now.

echo '<td><a href="'.$row['sujet'].'.php" alt="autosujet.php">DETAIL</a></td>';


Thanks a lot for the help, friend!

garcon1986
Light Poster
27 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

I have one another question about passing variables between pages.

If i want to use $row['sujet'] in the page $row['sujet'].php, how can i manage to do that?

Hope for advice.

garcon1986
Light Poster
27 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

Please Explain your Need

alagirinetaxis
Newbie Poster
15 posts since Oct 2009
Reputation Points: 10
Solved Threads: 3
 
Please Explain your Need


Sorry, i forgot to describe my need with details.

I want to display a form in $row['sujet'].php.

First, I use a mysql query "select * from table besoin where sujet=$row['sujet']"; to get the values.

And then, i want to populate them in a form.

I can populate it in a form, but i don't know how to pass the variable to the page $['sujet'].php.

Thanks for your suggestions.

garcon1986
Light Poster
27 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: