Jump to content

Recommended Posts

Evening Folks,

 

I'm having a little trouble getting a function to work properly within a echo. It seems to me that this problem is something really simple, but I just can't quite put my finger on it  :-\.

 

The function does execute within the echo, but its being displayed in the wrong order. I dont know whether it is a CSS problem, HTML problem or a PHP problem, or all of the above. Any help is greatly Appreciated!

 

Here's the echo:

<!-- Left Column -->
<div id = "leftcolumn">

<?php	echo '<span><b>Name</b>' . player_table("username") . '  </span>'; ?>

</div>

 

this is displaying:

ACEName

 

when it should really be more like this:

Name    ACE

 

Here is the CSS code for the span tag:

/* spacing */
span  { word-spacing: 30px }

 

Regards ACE

Link to comment
https://forums.phpfreaks.com/topic/71139-solved-using-a-function-within-a-echo/
Share on other sites

// Select fields from the user table
function player_table($select) {
if (!isset($_SESSION['playerid'])) {

// Destroy the session
session_destroy();

// Automatically redirect to the homepage
header("Location: index.php?page=home");
}

$where = $_SESSION['playerid'];

$rs = mysql_connect( "localhost", "ace_ACE", "*****" );
$rs = mysql_select_db( "ace_cf" );

// SQL query for all entries in descending order
$sql = "SELECT `" . $select . "` FROM `cf_users` WHERE `id`='" . $where . "' LIMIT 1";
$rs = mysql_query( $sql ) or die('Query:<br />' . $sql . '<br /><br />Error:<br />' . mysql_error());

// This gets the data from the result resource
$query = mysql_result($rs,0,0);

echo $query;

};

Still does the same thing  :-[

are you shure to save changes in function

 

in your 1st code echo statesment first build string for output

in building string first call function (it print name on screen) and use what function return (in 1st code nothing)

after that print on page using '' for name

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.