Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> MySQL
Author Message
ThePiston
Worker
Worker



Joined: Dec 22, 2004
Posts: 135

PostPosted: Wed Mar 16, 2005 7:04 am Reply with quote

Here's my code I'm working on, check out the WHERE clause at the end
Code:
   $check = $cookie[1];

    $check2 = $cookie[2];
    $sql = "select u.name, o.offname, o.add1, o.add2, o.city, o.state, o.zip, o.phone, o.fax FROM nuke_users u, offices o WHERE username='$check'";

I want the WHERE clause to check user_id in a table I created called "offices" (it also has "user_id" like "nuke_users" does). I can't seem to just change username to user_id. How do I do that? I only want results from the "offices" table where the user_id matches the current user's user_id.
 
View user's profile Send private message
TheosEleos
Life Cycles Becoming CPU Cycles



Joined: Sep 18, 2003
Posts: 960
Location: Missouri

PostPosted: Wed Mar 16, 2005 8:17 am Reply with quote

What error do you get?

_________________
Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website AIM Address ICQ Number
ThePiston







PostPosted: Wed Mar 16, 2005 10:03 pm Reply with quote

Code:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /public_html/modules/Your_Account/index.php on line 3650


Here's the entire code:
Code:
function edithome() {

    global $user, $userinfo, $db, $Default_Theme, $user_id, $cookie, $broadcast_msg, $user_news, $storyhome, $module_name, $offices, $name, $offname, $add1, $add2, $city, $state, $zip, $phone, $fax;
    cookiedecode($user);
    getusrinfo($user);
   $check = $cookie[1];
    $check2 = $cookie[2];
   $sql = "select u.user_id, u.name, o.user_id, o.offname, o.add1, o.add2, o.city, o.state, o.zip, o.phone, o.fax FROM nuke_users u, offices o WHERE user_id='$check'";
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrow($result);
    if ((is_user($user)) AND (strtolower($userinfo['username']) == strtolower($cookie[1])) AND ($userinfo['user_password'] == $cookie[2])) {
    include ("header.php");
    OpenTable();
    echo "<center><font class=\"title\"><b>"._HOMECONFIG."</b></font></center>";
    CloseTable();
    echo "<br>";   
    OpenTable();
    nav();
    CloseTable();
    echo "<br>";
    if($userinfo[theme]=="") {
        $userinfo[theme] = "$Default_Theme";
    }   
   //begin white area with table of current offices
   echo "<b>$userinfo[username],"._OFFICEID."</b>"
       ."<br><br>";   
   $num = $db->sql_numrows($result);
$i=0;
print "<table width=80% border=0>";
while($row=mysql_fetch_assoc($result))   {
   if($i==3)
      {
      echo "</tr> <tr>";
      $i=0;   
      }
   echo "<td>"."<b>".$row[name]."</b>"."<br>".$row[offname]."<br>".$row[add1].$row[add2]."<br>".$row[city].", ".$row[state]." ".$row[zip]."<br>".$row[phone]." Phone"."<br>".$row[fax]." Fax"."<br>"."<br>"."</td>";
   $i++;
   }

The line 3650 is this one:

Code:
while($row=mysql_fetch_assoc($result))   { 

The problem, I think, lies in the $sql part. I'm trying to only retrieve results WHERE user_id=current user's ID. Do I have to put it in the cookie?
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> MySQL

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©