944,087 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 29189
  • PHP RSS
Jan 14th, 2005
0

Newbie Question. how to put url into echo $row

Expand Post »
Hi there.

I'm very very new to php. :o so i hope i'm posting in the right forum.
and i really can't figure this out. probably really simple but i need to place a url into:

while ($row = mysql_fetch_array($result)) {
echo $row['login'];
echo "&nbsp;" . $row['age'] . "<br>";

everytime i place <a href= etc i get errors.

I need the login to link to the user's profile page.

Please could anybody help??

Kind Regards
Ross
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rosslad2004 is offline Offline
6 posts
since Jan 2005
Jan 14th, 2005
0

Re: Newbie Question. how to put url into echo $row

Suppose you have the code:
PHP Syntax (Toggle Plain Text)
  1. echo "$value";
Everything within the quotes is printed out. However, now take the following code:
PHP Syntax (Toggle Plain Text)
  1. echo "<a href="$value">";
PHP gets confused where you have quotes within quotes. Therefore, if you want to print out a real quote inside an echo statement, you have to escape the " character with a backlash. Like this ...
PHP Syntax (Toggle Plain Text)
  1. echo "<a href=\"$value\">";
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is online now Online
13,646 posts
since Feb 2002
Jan 14th, 2005
0

Re: Newbie Question. how to put url into echo $row

so it would be something like:

echo "<a href=member.php?mid=$m[id]\"$row['login']\">";

?

said i'm new at this, sorry :o

Thanks for the quick reply

Kind Regards
Ross
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rosslad2004 is offline Offline
6 posts
since Jan 2005
Jan 14th, 2005
0

Re: Newbie Question. how to put url into echo $row

unfortunatly none of the ways i try seem to work.

i don't think i'm cut out for this php thing.

Ross
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rosslad2004 is offline Offline
6 posts
since Jan 2005
Jan 14th, 2005
0

Re: Newbie Question. how to put url into echo $row

Practice makes perfect.

PHP Syntax (Toggle Plain Text)
  1. echo "<a href=\"member.php?mid=$row[mid]\">$row[login]</a>";

I'm not exactly sure what $m[id] is ? Where are you fetching that $m[] array from?
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is online now Online
13,646 posts
since Feb 2002
Jan 14th, 2005
0

Re: Newbie Question. how to put url into echo $row

generally when u pull it from mysql you would reference the item you want by column number, so....
if your query was something to this effect:
PHP Syntax (Toggle Plain Text)
  1. $result = mysql_query("SELECT login,age FROM some_table WHERE user_name='".$user.'");
  2. $row = mysql_fetch_row($result);
  3.  
  4. $login = $row[0];
  5. $age = $row[1];
  6.  
  7. $link = "<a href=\"members.php?mid=".$login."\">".$age."</a>
  8.  
Reputation Points: 13
Solved Threads: 4
Posting Whiz
paradox814 is offline Offline
351 posts
since Oct 2004
Jan 14th, 2005
0

Re: Newbie Question. how to put url into echo $row

Hello. thanks for all your help, both of you,

what i currently have is:

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. $result = mysql_query("select P.id
  3. , M.login
  4. , dayofmonth(P.birthdate) as birth_day
  5. , month(P.birthdate) as birth_month
  6. , year(current_date)
  7. -year(P.birthdate) as age
  8. from profiles as P
  9. inner
  10. join members as M
  11. on P.id = M.id
  12. where dayofmonth(current_date) = dayofmonth(P.birthdate)
  13. and month(current_date) = month(P.birthdate)") or die("Query failed: " . mysql_error());
  14. while ($row = mysql_fetch_array($result)) {
  15. echo "<a href=\"member.php?mid=$row[mid]\">$row[login]</a>";
  16. echo "&nbsp;" . $row['age'] . "<br>";
  17. }
  18.  
  19. ?>

which does give me the linked login name that i was after
but the link doesnt point to the users profile

I wanted it as a todays birthdays list with login name and age, but the tables for login and birthdate was in seperate locations so i ended up with the above.

can you see what i am doing wrong here? :cry:

Kind Regards
Ross
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rosslad2004 is offline Offline
6 posts
since Jan 2005
Jan 15th, 2005
0

Re: Newbie Question. how to put url into echo $row

i don't know, maybe it's a problem with your sql query?
can you login via ssh/telnet and double check to see if that works?

if not here is a PHP interface:

PHP Syntax (Toggle Plain Text)
  1. <!-- Program Name: mysql_send.php
  2. Description: PHP program that sends an SQL query to the
  3. MySQL server and displays the results.
  4. -->
  5. <html>
  6. <head>
  7. <title>SQL Query Sender</title>
  8. </head>
  9. <body>
  10. <?php
  11. $user="root";
  12. $host="localhost";
  13. $password="";
  14.  
  15. /* Section that executes query */
  16. if (@$form == "yes")
  17. {
  18. mysql_connect($host,$user,$password);
  19. mysql_select_db($database);
  20. $query = stripSlashes($query) ;
  21. $result = mysql_query($query);
  22. echo "Database Selected: <b>$database</b><br>
  23. Query: <b>$query</b>
  24. <h3>Results</h3>
  25. <hr>";
  26. if ($result == 0)
  27. echo("<b>Error " . mysql_errno() . ": " . mysql_error() . "</b>");
  28.  
  29. elseif ( <email protected>($result) == 0)
  30. echo("<b>Query completed. No results returned.</b><br>");
  31. else
  32. {
  33. echo "<table border='1'>
  34. <thead>
  35. <tr>";
  36. for ($i = 0; $i < mysql_num_fields($result); $i++)
  37. {
  38. echo("<th>" . mysql_field_name($result,$i) . "</th>");
  39. }
  40. echo " </tr>
  41. </thead>
  42. <tbody>";
  43. for ($i = 0; $i < mysql_num_rows($result); $i++)
  44. {
  45. echo "<tr>";
  46. $row = mysql_fetch_row($result);
  47. for ($j = 0; $j < mysql_num_fields($result); $j++)
  48. {
  49. echo("<td>" . $row[$j] . "</td>");
  50. }
  51. echo "</tr>";
  52. }
  53. echo "</tbody>
  54. </table>";
  55. }
  56. echo "<hr><br>
  57. <form action=$PHP_SELF method=post>
  58. <input type=hidden name=query value=\"$query\">
  59. <input type=hidden name=database value=$database>
  60. <input type=submit name=\"queryButton\" value=\"New Query\">
  61. <input type=submit name=\"queryButton\" value=\"Edit Query\">
  62. </form>";
  63. unset($form);
  64. exit();
  65. }
  66.  
  67. /* Section that requests user input of query */
  68. @$query = stripSlashes($query);
  69. if (@$queryButton != "Edit Query")
  70. {
  71. $database = " ";
  72. $query = " ";
  73. }
  74. ?>
  75.  
  76. <form action=<?php echo $PHP_SELF ?>?form=yes method="post">
  77. <table>
  78. <tr>
  79. <td align="right"><b>Type in database name</b></td>
  80. <td>
  81. <input type=text name="database" value=<?php echo $database ?> >
  82. </td>
  83. </tr>
  84. <tr>
  85. <td align="right" valign="top"><b>Type in SQL query</b></td>
  86. <td><textarea name="query" cols="60" rows="10"><?php echo $query ?></textarea>
  87. </td>
  88. </tr>
  89. <tr>
  90. <td colspan="2" align="center"><input type="submit" value="Submit
  91. Query"></td>
  92. </tr>
  93. </table>
  94. </form>
  95.  
  96. </body>
  97. </html>

this has always proved a big help in my dire times of need with SQL debugging
Reputation Points: 13
Solved Threads: 4
Posting Whiz
paradox814 is offline Offline
351 posts
since Oct 2004
Jul 31st, 2005
0

Re: Newbie Question. how to put url into echo $row

you saved my life with this thread, , thanks !
Reputation Points: 10
Solved Threads: 0
Newbie Poster
escolta is offline Offline
6 posts
since Jul 2005
Feb 25th, 2010
-1
Re: Newbie Question. how to put url into echo $row
you can use this tested ok
PHP Syntax (Toggle Plain Text)
  1. echo '<a href="'."/yourlink.php?id=".$row['id'].'">'.$row['type'].'</a>';
Last edited by Ezzaral; Feb 25th, 2010 at 1:21 pm. Reason: Added code tags. Please use them to format any code that you post.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mhelmyh is offline Offline
1 posts
since Feb 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Validating the textbox entry
Next Thread in PHP Forum Timeline: on click url submit form without refresh?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC