hostfreak Posted August 6, 2006 Share Posted August 6, 2006 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:[code]<?phpinclude("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!";}?>[/code] Quote Link to comment Share on other sites More sharing options...
king arthur Posted August 6, 2006 Share Posted August 6, 2006 Where are you getting the $username variable from? Quote Link to comment Share on other sites More sharing options...
hostfreak Posted August 6, 2006 Author Share Posted August 6, 2006 It's defined in session.php Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 6, 2006 Share Posted August 6, 2006 When in doubt, echo the query to see what it [b]really[/b] is:[code]$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());[/code] Quote Link to comment Share on other sites More sharing options...
hostfreak Posted August 6, 2006 Author Share Posted August 6, 2006 I did what you said Andy, It returned:Debug: SELECT * FROM trucks WHERE id2 = '' AND company LIKE 'A%' ORDER BY company ASCSo I guess somewhere the $id_num is getting lost? Quote Link to comment Share on other sites More sharing options...
hostfreak Posted August 6, 2006 Author Share Posted August 6, 2006 Ah, I figured it out. Needed to add:$username = $session->username;Thanks guys. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.