Jump to content

Display a variable as a link inside a echo


Shadowing

Recommended Posts

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>"'; ?>

Link to comment
Share on other sites

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>"'; ?>

Link to comment
Share on other sites

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
?>

Link to comment
Share on other sites

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";

}

?>

Link to comment
Share on other sites

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";

}
}
?>

 

Link to comment
Share on other sites

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;


}
}

?>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>';
} ?>

Link to comment
Share on other sites

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>'; 
?>

Link to comment
Share on other sites

<?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>';
         }
?>

Link to comment
Share on other sites

 

<?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?
?>

Link to comment
Share on other sites

 

<?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?
?>

Link to comment
Share on other sites

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'];

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.