Newbie Question. how to put url into echo $row

Reply

Join Date: Jan 2005
Posts: 6
Reputation: rosslad2004 is an unknown quantity at this point 
Solved Threads: 0
rosslad2004 rosslad2004 is offline Offline
Newbie Poster

Newbie Question. how to put url into echo $row

 
0
  #1
Jan 14th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,036
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 128
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

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

 
0
  #2
Jan 14th, 2005
Suppose you have the code:
  1. echo "$value";
Everything within the quotes is printed out. However, now take the following code:
  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 ...
  1. echo "<a href=\"$value\">";
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/daniweb
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 6
Reputation: rosslad2004 is an unknown quantity at this point 
Solved Threads: 0
rosslad2004 rosslad2004 is offline Offline
Newbie Poster

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

 
0
  #3
Jan 14th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 6
Reputation: rosslad2004 is an unknown quantity at this point 
Solved Threads: 0
rosslad2004 rosslad2004 is offline Offline
Newbie Poster

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

 
0
  #4
Jan 14th, 2005
unfortunatly none of the ways i try seem to work.

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

Ross
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,036
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 128
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

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

 
0
  #5
Jan 14th, 2005
Practice makes perfect.

  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?
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/daniweb
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 348
Reputation: paradox814 is an unknown quantity at this point 
Solved Threads: 4
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

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

 
0
  #6
Jan 14th, 2005
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:
  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.  
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 6
Reputation: rosslad2004 is an unknown quantity at this point 
Solved Threads: 0
rosslad2004 rosslad2004 is offline Offline
Newbie Poster

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

 
0
  #7
Jan 14th, 2005
Hello. thanks for all your help, both of you,

what i currently have is:

  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
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 348
Reputation: paradox814 is an unknown quantity at this point 
Solved Threads: 4
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

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

 
0
  #8
Jan 15th, 2005
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:

  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
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 6
Reputation: escolta is an unknown quantity at this point 
Solved Threads: 0
escolta escolta is offline Offline
Newbie Poster

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

 
0
  #9
Jul 31st, 2005
you saved my life with this thread, , thanks !
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



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