| | |
Newbie Question. how to put url into echo $row
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jan 2005
Posts: 6
Reputation:
Solved Threads: 0
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 " " . $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
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 " " . $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
Suppose you have the code:
Everything within the quotes is printed out. However, now take the following code:
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)
echo "$value";
PHP Syntax (Toggle Plain Text)
echo "<a href="$value">";
PHP Syntax (Toggle Plain Text)
echo "<a href=\"$value\">";
Practice makes perfect.
I'm not exactly sure what $m[id] is ? Where are you fetching that $m[] array from?
PHP Syntax (Toggle Plain Text)
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?
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:
if your query was something to this effect:
PHP Syntax (Toggle Plain Text)
$result = mysql_query("SELECT login,age FROM some_table WHERE user_name='".$user.'"); $row = mysql_fetch_row($result); $login = $row[0]; $age = $row[1]; $link = "<a href=\"members.php?mid=".$login."\">".$age."</a>
•
•
Join Date: Jan 2005
Posts: 6
Reputation:
Solved Threads: 0
Hello. thanks for all your help, both of you,
what i currently have is:
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
what i currently have is:
PHP Syntax (Toggle Plain Text)
<?php $result = mysql_query("select P.id , M.login , dayofmonth(P.birthdate) as birth_day , month(P.birthdate) as birth_month , year(current_date) -year(P.birthdate) as age from profiles as P inner join members as M on P.id = M.id where dayofmonth(current_date) = dayofmonth(P.birthdate) and month(current_date) = month(P.birthdate)") or die("Query failed: " . mysql_error()); while ($row = mysql_fetch_array($result)) { echo "<a href=\"member.php?mid=$row[mid]\">$row[login]</a>"; echo " " . $row['age'] . "<br>"; } ?>
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
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:
this has always proved a big help in my dire times of need with SQL debugging
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)
<!-- Program Name: mysql_send.php Description: PHP program that sends an SQL query to the MySQL server and displays the results. --> <html> <head> <title>SQL Query Sender</title> </head> <body> <?php $user="root"; $host="localhost"; $password=""; /* Section that executes query */ if (@$form == "yes") { mysql_connect($host,$user,$password); mysql_select_db($database); $query = stripSlashes($query) ; $result = mysql_query($query); echo "Database Selected: <b>$database</b><br> Query: <b>$query</b> <h3>Results</h3> <hr>"; if ($result == 0) echo("<b>Error " . mysql_errno() . ": " . mysql_error() . "</b>"); elseif ( <email protected>($result) == 0) echo("<b>Query completed. No results returned.</b><br>"); else { echo "<table border='1'> <thead> <tr>"; for ($i = 0; $i < mysql_num_fields($result); $i++) { echo("<th>" . mysql_field_name($result,$i) . "</th>"); } echo " </tr> </thead> <tbody>"; for ($i = 0; $i < mysql_num_rows($result); $i++) { echo "<tr>"; $row = mysql_fetch_row($result); for ($j = 0; $j < mysql_num_fields($result); $j++) { echo("<td>" . $row[$j] . "</td>"); } echo "</tr>"; } echo "</tbody> </table>"; } echo "<hr><br> <form action=$PHP_SELF method=post> <input type=hidden name=query value=\"$query\"> <input type=hidden name=database value=$database> <input type=submit name=\"queryButton\" value=\"New Query\"> <input type=submit name=\"queryButton\" value=\"Edit Query\"> </form>"; unset($form); exit(); } /* Section that requests user input of query */ @$query = stripSlashes($query); if (@$queryButton != "Edit Query") { $database = " "; $query = " "; } ?> <form action=<?php echo $PHP_SELF ?>?form=yes method="post"> <table> <tr> <td align="right"><b>Type in database name</b></td> <td> <input type=text name="database" value=<?php echo $database ?> > </td> </tr> <tr> <td align="right" valign="top"><b>Type in SQL query</b></td> <td><textarea name="query" cols="60" rows="10"><?php echo $query ?></textarea> </td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="Submit Query"></td> </tr> </table> </form> </body> </html>
this has always proved a big help in my dire times of need with SQL debugging
![]() |
Other Threads in the PHP Forum
- Previous Thread: Simple Subform?
- Next Thread: bar graph & _POST variables
| Thread Tools | Search this Thread |
apache api array basic binary body broken cakephp class cms code computing confirm cron curl customizableitems database date date/time delete dynamic ebooks email error file filter folder form forms forum function functions gc_maxlifetime header headmethod href htaccess html iframe image include ip javascript joomla limit link list login malfunction mediawiki memmory memory menu msqli_multi_query multiple mycodeisbad mysql navigation number oop parameter parsing paypal pdf php phpincludeissue query question random recourse regex script search seo server sessions snippet source sp space speed sql static subdomain system table tag thesishelp trouble tutorial update upload url variable vbulletin web webdesign white xml youtube








so it would be something like: