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

Thread Solved

Join Date: Oct 2009
Posts: 25
Reputation: garcon1986 is an unknown quantity at this point 
Solved Threads: 0
garcon1986 garcon1986 is offline Offline
Light Poster

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

 
0
  #1
Oct 27th, 2009
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:

  1. <table id="t" border="1">
  2. <tr>
  3. <th>SUJET</th>
  4. <th>DATE</th>
  5. <th>NATURE</th>
  6. <th>ACTION</th>
  7. <th>NON DE DECIDEUR</th>
  8. <th>DETAIL</th>
  9. </tr>
  10. <?php
  11. $conn = mysql_connect("localhost","root","") or die("Sorry, can't connect: ".mysql_error());
  12. mysql_select_db($db);
  13. $query = "SELECT sujet, bdate, nature, adetail, decideur FROM besoin";
  14. $result = mysql_query($query, $conn) or die("Sorry, don't get result for error: ".mysql_error());
  15. while($row = mysql_fetch_assoc($result)){
  16. echo "<tr><td>".$row["sujet"]."</td>";
  17. echo "<td>".$row["bdate"]."</td>";
  18. echo "<td>".$row["nature"]."</td>";
  19. echo "<td>".$row["adetail"]."</td>";
  20. echo "<td>".$row["decideur"]."</td>";
  21. echo "<td><a href=\"$row[\"sujet\"].php\" alt='autosujet.php'>DETAIL</a></td>";
  22. echo "</tr><br>";
  23. }
  24. ?>

Error:

  1. 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
  2.  
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 25
Reputation: garcon1986 is an unknown quantity at this point 
Solved Threads: 0
garcon1986 garcon1986 is offline Offline
Light Poster
 
0
  #2
Oct 27th, 2009
i know it's the problem of
  1. echo "<td><a href=\"$row[\"sujet\"].php\" alt='autosujet.php'>DETAIL</a></td>";
.

But i can't solve it.

Welcome for any suggestions!!! Thanks.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 25
Reputation: garcon1986 is an unknown quantity at this point 
Solved Threads: 0
garcon1986 garcon1986 is offline Offline
Light Poster
 
0
  #3
Oct 27th, 2009
i have changed the code to:

  1. 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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 15
Reputation: alagirinetaxis is an unknown quantity at this point 
Solved Threads: 3
alagirinetaxis alagirinetaxis is offline Offline
Newbie Poster
 
0
  #4
Oct 27th, 2009
Originally Posted by garcon1986 View Post
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:

  1. <table id="t" border="1">
  2. <tr>
  3. <th>SUJET</th>
  4. <th>DATE</th>
  5. <th>NATURE</th>
  6. <th>ACTION</th>
  7. <th>NON DE DECIDEUR</th>
  8. <th>DETAIL</th>
  9. </tr>
  10. <?php
  11. $conn = mysql_connect("localhost","root","") or die("Sorry, can't connect: ".mysql_error());
  12. mysql_select_db($db);
  13. $query = "SELECT sujet, bdate, nature, adetail, decideur FROM besoin";
  14. $result = mysql_query($query, $conn) or die("Sorry, don't get result for error: ".mysql_error());
  15. while($row = mysql_fetch_assoc($result)){
  16. echo "<tr><td>".$row["sujet"]."</td>";
  17. echo "<td>".$row["bdate"]."</td>";
  18. echo "<td>".$row["nature"]."</td>";
  19. echo "<td>".$row["adetail"]."</td>";
  20. echo "<td>".$row["decideur"]."</td>";
  21. echo "<td><a href=\"$row[\"sujet\"].php\" alt='autosujet.php'>DETAIL</a></td>";
  22. echo "</tr><br>";
  23. }
  24. ?>

Error:

  1. 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
  2.  
  1. <table id="t" border="1">
  2. <tr>
  3. <th>SUJET</th>
  4. <th>DATE</th>
  5. <th>NATURE</th>
  6. <th>ACTION</th>
  7. <th>NON DE DECIDEUR</th>
  8. <th>DETAIL</th>
  9. </tr>
  10. <?php
  11. $conn = mysql_connect("localhost","root","") or die("Sorry, can't connect: ".mysql_error());
  12. mysql_select_db($db);
  13. $query = "SELECT sujet, bdate, nature, adetail, decideur FROM besoin";
  14. $result = mysql_query($query, $conn) or die("Sorry, don't get result for error: ".mysql_error());
  15. while($row = mysql_fetch_assoc($result)){
  16. echo '<tr><td>'.$row["sujet"].'</td>';
  17. echo '<td>'.$row["bdate"].'</td>';
  18. echo '<td>'.$row["nature"].'</td>';
  19. echo '<td>'.$row["adetail"].'</td>';
  20. echo '<td>'.$row["decideur"].'</td>';
  21. echo '<td><a href="'.$row['sujet'].'".php" alt="autosujet.php">DETAIL</a></td>';
  22. echo '</tr><br>';
  23. }
  24. ?>
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 15
Reputation: alagirinetaxis is an unknown quantity at this point 
Solved Threads: 3
alagirinetaxis alagirinetaxis is offline Offline
Newbie Poster
 
0
  #5
Oct 27th, 2009
Hi Use This

  1. <table id="t" border="1">
  2. <tr>
  3. <th>SUJET</th>
  4. <th>DATE</th>
  5. <th>NATURE</th>
  6. <th>ACTION</th>
  7. <th>NON DE DECIDEUR</th>
  8. <th>DETAIL</th>
  9. </tr>
  10. <?php
  11. $conn = mysql_connect("localhost","root","") or die("Sorry, can't connect: ".mysql_error());
  12. mysql_select_db($db);
  13. $query = "SELECT sujet, bdate, nature, adetail, decideur FROM besoin";
  14. $result = mysql_query($query, $conn) or die("Sorry, don't get result for error: ".mysql_error());
  15. while($row = mysql_fetch_assoc($result)){
  16. echo '<tr><td>'.$row["sujet"].'</td>';
  17. echo '<td>'.$row["bdate"].'</td>';
  18. echo '<td>'.$row["nature"].'</td>';
  19. echo '<td>'.$row["adetail"].'</td>';
  20. echo '<td>'.$row["decideur"].'</td>';
  21. echo '<td><a href="'.$row['sujet'].'".php" alt="autosujet.php">DETAIL</a></td>';
  22. echo '</tr><br>';
  23. }
  24. ?>
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 25
Reputation: garcon1986 is an unknown quantity at this point 
Solved Threads: 0
garcon1986 garcon1986 is offline Offline
Light Poster
 
0
  #6
Oct 27th, 2009
Originally Posted by alagirinetaxis View Post
Hi Use This

  1. <table id="t" border="1">
  2. <tr>
  3. <th>SUJET</th>
  4. <th>DATE</th>
  5. <th>NATURE</th>
  6. <th>ACTION</th>
  7. <th>NON DE DECIDEUR</th>
  8. <th>DETAIL</th>
  9. </tr>
  10. <?php
  11. $conn = mysql_connect("localhost","root","") or die("Sorry, can't connect: ".mysql_error());
  12. mysql_select_db($db);
  13. $query = "SELECT sujet, bdate, nature, adetail, decideur FROM besoin";
  14. $result = mysql_query($query, $conn) or die("Sorry, don't get result for error: ".mysql_error());
  15. while($row = mysql_fetch_assoc($result)){
  16. echo '<tr><td>'.$row["sujet"].'</td>';
  17. echo '<td>'.$row["bdate"].'</td>';
  18. echo '<td>'.$row["nature"].'</td>';
  19. echo '<td>'.$row["adetail"].'</td>';
  20. echo '<td>'.$row["decideur"].'</td>';
  21. echo '<td><a href="'.$row['sujet'].'".php" alt="autosujet.php">DETAIL</a></td>';
  22. echo '</tr><br>';
  23. }
  24. ?>
Thanks a lot for your posting. You are almost there.

I changed my code based on yours. Just delete a " and it works now.
  1. echo '<td><a href="'.$row['sujet'].'.php" alt="autosujet.php">DETAIL</a></td>';

Thanks a lot for the help, friend!
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 25
Reputation: garcon1986 is an unknown quantity at this point 
Solved Threads: 0
garcon1986 garcon1986 is offline Offline
Light Poster
 
0
  #7
Oct 27th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 15
Reputation: alagirinetaxis is an unknown quantity at this point 
Solved Threads: 3
alagirinetaxis alagirinetaxis is offline Offline
Newbie Poster
 
0
  #8
Oct 27th, 2009
Please Explain your Need
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 25
Reputation: garcon1986 is an unknown quantity at this point 
Solved Threads: 0
garcon1986 garcon1986 is offline Offline
Light Poster
 
0
  #9
Oct 27th, 2009
Originally Posted by alagirinetaxis View Post
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.
Reply With Quote Quick reply to this message  
Reply

Tags
echo, href, variable

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC