Shadowing Posted December 13, 2011 Share Posted December 13, 2011 Trying to figure out how to make it so name is a link to the profile when its echo anyone know how to do this? im at a huge stand still <?php $sql = "SELECT name FROM users WHERE DATE_SUB(NOW(),INTERVAL 5 MINUTE) <= lastactive ORDER BY id ASC"; $query = mysql_query($sql) or die(mysql_error()); $count = mysql_num_rows($query); $i = 1; while($row = mysql_fetch_object($query)) { $online_name = htmlspecialchars($row->name); echo '<a href="Inbox.php">"'[$goauld]'</a>"'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/253057-display-a-variable-as-a-link-inside-a-echo/ Share on other sites More sharing options...
Shadowing Posted December 13, 2011 Author Share Posted December 13, 2011 Trying to figure out how to make it so name is a link to the profile when its echo anyone know how to do this? im at a huge stand still <?php $sql = "SELECT name FROM users WHERE DATE_SUB(NOW(),INTERVAL 5 MINUTE) <= lastactive ORDER BY id ASC"; $query = mysql_query($sql) or die(mysql_error()); $count = mysql_num_rows($query); $i = 1; while($row = mysql_fetch_object($query)) { $online_name = htmlspecialchars($row->name); echo '<a href="Inbox.php">"'[$online_name]'</a>"'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/253057-display-a-variable-as-a-link-inside-a-echo/#findComment-1297372 Share on other sites More sharing options...
Drummin Posted December 13, 2011 Share Posted December 13, 2011 See how this works out for you. <?php if(isset($_GET['id']) && is_numeric($_GET['id'])){ $userid=$_GET['id']; //Query for profile add fields as needed $sql = mysql_query("SELECT name FROM users WHERE id='$userid'"); WHILE ($row = mysql_fetch_array($sql)) { $online_name = $row['name']; echo "User Name: $online_name<br />\n"; } }//end if get user id else{ //If not showing profile list users $sql = mysql_query("SELECT name,id FROM users WHERE DATE_SUB(NOW(),INTERVAL 5 MINUTE) <= lastactive ORDER BY id ASC"); WHILE ($row = mysql_fetch_array($sql)) { $online_name = $row['name']; $userid = $row['id']; echo "<a href=\"profile.php?id=$userid\">$online_name</a><br />\n"; } }//if NOT get user id ?> Quote Link to comment https://forums.phpfreaks.com/topic/253057-display-a-variable-as-a-link-inside-a-echo/#findComment-1297373 Share on other sites More sharing options...
Shadowing Posted December 13, 2011 Author Share Posted December 13, 2011 Thanks Drummin that works very awesome what is the reason for repeating $online_name = $row['name']; I tried doing something close to what you did on another page but the echo shows up blank. whats the reason for that? <?php if(isset($_POST['search'])) { $search3 = "SELECT goauld,id FROM users WHERE name='".mysql_real_escape_string($_POST['goaulds'])."'"; $search2 = mysql_query($search3) or die(mysql_error()); $search1 = mysql_fetch_array($search2); $grab_goauld = $search1['goauld']; $goauld_name = $search1['id']; echo "<a href=\"profile.php?id=$goauld_name\">$grab_goauld</a><br />\n"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/253057-display-a-variable-as-a-link-inside-a-echo/#findComment-1297502 Share on other sites More sharing options...
Drummin Posted December 13, 2011 Share Posted December 13, 2011 Missing WHILE and the array brackets. See http://php.net/manual/en/function.mysql-fetch-array.php <?PHP if(isset($_POST['search'])) { $search3 = "SELECT goauld,id FROM users WHERE name='".mysql_real_escape_string($_POST['goaulds'])."'"; $search2 = mysql_query($search3) or die(mysql_error()); WHILE($search1 = mysql_fetch_array($search2)){ $grab_goauld = $search1['goauld']; $goauld_name = $search1['id']; echo "<a href=\"profile.php?id=$goauld_name\">$grab_goauld</a><br />\n"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/253057-display-a-variable-as-a-link-inside-a-echo/#findComment-1297533 Share on other sites More sharing options...
Shadowing Posted December 13, 2011 Author Share Posted December 13, 2011 Thanks for taking the time to help me understand this. I made this more simple so i can understand whats going on here when search is hit and while fetch_array is going on it will echo grab_goauld this gives me a blank result though something huge i dont understand here <?php if(isset($_POST['search'])) { $search3 = "SELECT goauld,id FROM users WHERE name='".mysql_real_escape_string($_POST['goaulds'])."'"; $search2 = mysql_query($search3) or die(mysql_error()); WHILE($search1 = mysql_fetch_array($search2)){ $grab_goauld = $search1['goauld']; echo $grab_goauld; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/253057-display-a-variable-as-a-link-inside-a-echo/#findComment-1297548 Share on other sites More sharing options...
Drummin Posted December 13, 2011 Share Posted December 13, 2011 It looks correct. Are you sure your form has the same names you are using in the process code and you are searching for a user that has a "name" you're searching for? The form should be something like this. <form method="post" action=""> <input type="text" name="goaulds" /> <input type="submit" name="search" value="Search" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/253057-display-a-variable-as-a-link-inside-a-echo/#findComment-1297560 Share on other sites More sharing options...
Shadowing Posted December 13, 2011 Author Share Posted December 13, 2011 I fixed it!!! WHERE name needed to be goauld instead of name i read that several times and didnt notice it lol. its crazy cause i changed it to name so you could read it easier. when i was using name instead of goauld Thank you so much man. i learned alot with this problem this was my first time using the while command Quote Link to comment https://forums.phpfreaks.com/topic/253057-display-a-variable-as-a-link-inside-a-echo/#findComment-1297582 Share on other sites More sharing options...
Shadowing Posted December 13, 2011 Author Share Posted December 13, 2011 How would I go about in displaying all the goaulds as a list I wouldnt need a while command for that right? i want it to happend as soon as the page loads. <?php $search6 = ("SELECT goauld FROM users ORDER BY goauld DESC"); $search5 = mysql_query($search6) or die(mysql_error()); while($search4 = mysql_fetch_array($search5)) { $grab_goauld = $search1['goauld']; echo "<table border=\"1\" align=\"center\">"; echo "<th>$grab_goauld</th>"; echo '</table>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/253057-display-a-variable-as-a-link-inside-a-echo/#findComment-1297610 Share on other sites More sharing options...
Drummin Posted December 13, 2011 Share Posted December 13, 2011 Move the table tags outside the loop. Don't forget the <tr> tags! <?php echo "<table border=\"1\" align=\"center\">"; $search6 = ("SELECT goauld FROM users ORDER BY goauld DESC"); $search5 = mysql_query($search6) or die(mysql_error()); while($search4 = mysql_fetch_array($search5)) { $grab_goauld = $search1['goauld']; echo "<tr><th>$grab_goauld</th></tr>"; } echo '</table>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/253057-display-a-variable-as-a-link-inside-a-echo/#findComment-1297616 Share on other sites More sharing options...
Shadowing Posted December 13, 2011 Author Share Posted December 13, 2011 Im not getting anything with that code sat here for a hour looking on google for solutions. I don t know why its hard to find related stuff to what im doing Quote Link to comment https://forums.phpfreaks.com/topic/253057-display-a-variable-as-a-link-inside-a-echo/#findComment-1297650 Share on other sites More sharing options...
Andy-H Posted December 13, 2011 Share Posted December 13, 2011 <?php $sql = "SELECT name FROM users WHERE DATE_SUB(NOW(),INTERVAL 5 MINUTE) <= lastactive ORDER BY id ASC"; $query = mysql_query($sql) or die(mysql_error()); $count = mysql_num_rows($query); $i = 1; while($row = mysql_fetch_object($query)) { $online_name = stripslashes(htmlentities($row->name, ENT_QUOTES)); echo '<a href="Inbox.php">['. $goauld .']</a>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/253057-display-a-variable-as-a-link-inside-a-echo/#findComment-1297652 Share on other sites More sharing options...
Shadowing Posted December 13, 2011 Author Share Posted December 13, 2011 thanks for joining the conversation Andy I'm just trying to get it to display all the goauld in a list Quote Link to comment https://forums.phpfreaks.com/topic/253057-display-a-variable-as-a-link-inside-a-echo/#findComment-1297660 Share on other sites More sharing options...
Andy-H Posted December 13, 2011 Share Posted December 13, 2011 <?php $qry = "SELECT CONCAT('<tr><th>', GROUP_CONCAT(DISTINCT goauld ORDER BY goald DESC SEPARATOR '</th></tr><tr><th>'), '</th></tr>') FROM users"; $res = mysql_query($qre) or die(mysql_error()); $row = mysql_result($res, 0, 0); echo <<<TABLE <table border="1" align="center"> {$row} </table> TABLE; //does that work? ?> Quote Link to comment https://forums.phpfreaks.com/topic/253057-display-a-variable-as-a-link-inside-a-echo/#findComment-1297662 Share on other sites More sharing options...
Andy-H Posted December 13, 2011 Share Posted December 13, 2011 <?php $qry = "SELECT CONCAT('<tr><th>', GROUP_CONCAT(DISTINCT goauld ORDER BY goald DESC SEPARATOR '</th></tr><tr><th>'), '</th></tr>') FROM users"; $res = mysql_query($qre) or die(mysql_error()); $row = mysql_result($res, 0, 0); echo <<<TABLE <table border="1" align="center"> {$row} </table> TABLE; //does that work? ?> Quote Link to comment https://forums.phpfreaks.com/topic/253057-display-a-variable-as-a-link-inside-a-echo/#findComment-1297663 Share on other sites More sharing options...
Drummin Posted December 13, 2011 Share Posted December 13, 2011 Hey Andy-H, that's a new one. I'll have to look into that. As far as the problem with code posted above... Variables don't match. Should have been $search4. Sorry I didn't see that earlier. while($search4 = mysql_fetch_array($search5)) { $grab_goauld = $search4['goauld']; Quote Link to comment https://forums.phpfreaks.com/topic/253057-display-a-variable-as-a-link-inside-a-echo/#findComment-1297670 Share on other sites More sharing options...
Shadowing Posted December 14, 2011 Author Share Posted December 14, 2011 Thanks alot Its all working now. I dont know why i didnt notice that search1 lol. is echoing forms the best way to do this? I was reading the php manual something about HTML_FORM is that a command i should be using instead? Quote Link to comment https://forums.phpfreaks.com/topic/253057-display-a-variable-as-a-link-inside-a-echo/#findComment-1297695 Share on other sites More sharing options...
Drummin Posted December 14, 2011 Share Posted December 14, 2011 When you can, use html. That doesn't use resources. Not that echoing is bad. I have a site where users change the layout and the pattern is saved to DB and then parts are echoed out for each user depending on their configuration. Quote Link to comment https://forums.phpfreaks.com/topic/253057-display-a-variable-as-a-link-inside-a-echo/#findComment-1297706 Share on other sites More sharing options...
Shadowing Posted December 14, 2011 Author Share Posted December 14, 2011 thats kewl i know im asking alot of questions another thing though. how do you make something echo onto a form on another page like if I hit send message on a persons profile i would want it to go to inbox with their name filled in already Quote Link to comment https://forums.phpfreaks.com/topic/253057-display-a-variable-as-a-link-inside-a-echo/#findComment-1297711 Share on other sites More sharing options...
Shadowing Posted December 14, 2011 Author Share Posted December 14, 2011 well i guess i could use sessions to do that is thats how its done though. Quote Link to comment https://forums.phpfreaks.com/topic/253057-display-a-variable-as-a-link-inside-a-echo/#findComment-1297717 Share on other sites More sharing options...
Shadowing Posted December 15, 2011 Author Share Posted December 15, 2011 I figured out how to do it using $_GET and storing it in the link pretty kewl Quote Link to comment https://forums.phpfreaks.com/topic/253057-display-a-variable-as-a-link-inside-a-echo/#findComment-1298032 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.