Jump to content


Photo

Page not displaying retrieved information *solved*


  • Please log in to reply
5 replies to this topic

#1 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 06 August 2006 - 02:52 PM

I've got a system setup to manage trucks etc. Well when a truck is added, it is assigned to an agent. In the truck table, where the trucks are added, there is a field called id2. The id2 receives the value of the id of the user that it is assigned to. That way it is unique to that user. Well for some reason, when I try to call it to display trucks under that user, it doesn't display anything. No errors etc. Here is my code:

<?php
include("include/session.php");
if($session->logged_in){
include ("top.txt");
include("include/constants.inc");
?>

<table id="settingstable">
	<tr>	
		<td id="settingstd3">
<a href=amta.php><b><u>A</u></b></a>
<a href=amtb.php><b><u>B</u></b></a>
<a href=amtc.php><b><u>C</u></b></a>
<a href=amtd.php><b><u>D</u></b></a>
<a href=amte.php><b><u>E</u></b></a>
<a href=amtf.php><b><u>F</u></b></a>
<a href=amtg.php><b><u>G</u></b></a>
<a href=amth.php><b><u>H</u></b></a>
<a href=amti.php><b><u>I</u></b></a>
<a href=amtj.php><b><u>J</u></b></a>
<a href=amtk.php><b><u>K</u></b></a>
<a href=amtl.php><b><u>L</u></b></a>
<a href=amtm.php><b><u>M</u></b></a>
<a href=amtn.php><b><u>N</u></b></a>
<a href=amto.php><b><u>O</u></b></a>
<a href=amtp.php><b><u>P</u></b></a>
<a href=amtq.php><b><u>Q</u></b></a>
<a href=amtr.php><b><u>R</u></b></a>
<a href=amts.php><b><u>S</u></b></a>
<a href=amtt.php><b><u>T</u></b></a>
<a href=amtu.php><b><u>U</u></b></a>
<a href=amtv.php><b><u>V</u></b></a>
<a href=amtw.php><b><u>W</u></b></a>
<a href=amtx.php><b><u>X</u></b></a>
<a href=amty.php><b><u>Y</u></b></a>
<a href=amtz.php><b><u>Z</u></b></a>
		</td>
	</tr>
</table>
<?php
$connection = mysql_connect("$server","$user","$password");  
mysql_select_db("$database", $connection);

$sql = "SELECT * FROM users WHERE username = '$username'";
$result = mysql_query($sql, $connection) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
	$id_num = $row['id_num'];
}

$sql = "SELECT * FROM trucks";
$result = mysql_query($sql, $connection) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
	$id2 = $row['id2'];
}

$letter = 'A';
$sql = "SELECT * FROM trucks WHERE id2 = '$id_num' AND company LIKE '$letter%' ORDER BY company ASC";
$result = mysql_query($sql, $connection) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
	$company = $row['company'];
	$mc = $row['mc'];
?>

<table id="settingstable">
	<tr>
		<td></td>
	<tr>

	<tr>
		<td id="settingstd1">Company Name:</td>
		<td id="settingstd2"><?php echo "$company"; ?></td>
	</tr>

	<tr>
		<td id="settingstd1">MC #:</td>
		<td id="settingstd2"><?php echo "$mc"; ?></td>
	</tr>

	<tr>
		<td id="settingstd1">Delete:</td>
		<td id="settingstd2"><a href='deltrequest.php'>Delete Truck</a></td>
	</tr>

	<tr>
		<td id="settingstd1">Edit Truck:</td>
		<td id="settingstd2"><a href='edittrequest.php'>Edit Truck Information</a></td>
	</tr>
</table>

<?php
}
include ("bottom.txt");
}
else { //If the user is not logged in, warn them
$ip = $_SERVER['REMOTE_ADDR'];
echo "You are not authorized to view this page! An email has been dispatched to the administrators to inform them of your whereabouts!<br>Your IP address: <b>$ip</b> , has been recorded and will be reported to the law if this happens again!";
}
?>


#2 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 06 August 2006 - 03:00 PM

Where are you getting the $username variable from?
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#3 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 06 August 2006 - 03:02 PM

It's defined in session.php

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 06 August 2006 - 03:03 PM

When in doubt, echo the query to see what it really is:

$sql = "SELECT * FROM trucks WHERE id2 = '$id_num' AND company LIKE '$letter%' ORDER BY company ASC";
echo "Debug: ". $sql. "<br/>"; // so what is the query exactly?
$result = mysql_query($sql, $connection) or die(mysql_error());

Legend has it that reading the manual never killed anyone.
My site

#5 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 06 August 2006 - 03:05 PM

I did what you said Andy, It returned:
Debug: SELECT * FROM trucks WHERE id2 = '' AND company LIKE 'A%' ORDER BY company ASC

So I guess somewhere the $id_num is getting lost?

#6 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 06 August 2006 - 03:10 PM

Ah, I figured it out. Needed to add:

$username = $session->username;

Thanks guys.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users