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

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

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

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

}

?>

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

}
}
?>

 

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;


}
}

?>

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>

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

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

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

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

 

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

 

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

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

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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.