3 Replies - 1062 Views - Last Post: 20 November 2012 - 08:53 PM

#1 Bestford  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 05-December 11

showing the user name rather than the id Parsing

Posted 19 November 2012 - 02:49 PM

hello guys,

i want some advice on how to show the username from the ID, so I currently have this
<div id="container">

<aside>
	<?php
if (logged_in() === TRUE ) {
	include '../includes/widgets/loggedin.php';
} else {
	include '../includes/widgets/login.php';
}
include('../includes/widgets/user_count.php');
?>
</aside>

<h1>Admin</h1>
<p>Welcome please update select a module to update from the table below</p>



<div id="allresult">
	<?php
$sql = "SELECT * FROM lr_programme WHERE user_id ="  . $_SESSION['user_id']; //select statement to show in a table doesnt show the publisher
$queryresult = mysql_query($sql)
	or die(mysql_error());
echo "<table id='results'>";
echo "<thead>";//teable head for stucture
echo "<tr>\n";
echo "<th><strong>Programme Code</strong></th>\n";//shows the table headings
echo "<th><strong>Programme Name</strong></th>\n";
echo "<th>Programme Tutor</th>\n";
echo "<th>Programme Desc</th>\n";
echo "<th>Programme Link</th>\n";
echo "</tr>\n";
echo "</thead>";

while ($row = mysql_fetch_assoc($queryresult)) {
	$prog_id = $row['prog_id'];
	$prog_name = $row['prog_name'];
	$user_id = $row['user_id'];
	$prog_desc = $row['prog_desc'];
	$prog_link = $row['prog_link'];

	echo "<tbody>
	<tr>
	<td> <a href=\"updateProgInfo.php?prog_id=$prog_id\">$prog_id</a></td>
	<td> $prog_name </td>
	<td> $user_id </td>
	<td> $prog_desc </td>
	<td> $prog_link </td>
	</tr>
	</tbody>";
}

?>
</table>
</div><!--end of allresults div-->
</div>
	<footer>
		&copy; Mark Bestford 2012. All rights reserved.
	</footer>



as you can see it prints out the user ID as I hold that not the user name the tables im using are lr_programme and the user data is held on a table called users

any help would be great thanks and regards
Bestford

Is This A Good Question/Topic? 0
  • +

Replies To: showing the user name rather than the id Parsing

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5954
  • View blog
  • Posts: 23,219
  • Joined: 23-August 08

Re: showing the user name rather than the id Parsing

Posted 20 November 2012 - 05:21 AM

Why not save the user's name in a session variable when they login and then use that?
Was This Post Helpful? 0
  • +
  • -

#3 Bestford  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 05-December 11

Re: showing the user name rather than the id Parsing

Posted 20 November 2012 - 01:26 PM

and how would i go about doing that?

regards
Bestford
Was This Post Helpful? 0
  • +
  • -

#4 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 404
  • View blog
  • Posts: 1,720
  • Joined: 30-April 10

Re: showing the user name rather than the id Parsing

Posted 20 November 2012 - 08:53 PM

http://www.php.net/m...ook.session.php

Use session_start(); at the top of every page before anything is sent to the page.
Then you can set a session variable that will carry through each page that has the session_start(); at the top.

Setting session variable: $_SESSION["example"]='string';
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1