Current location: Hot Scripts Forums » Programming Languages » PHP » Php based mysql query problome


Php based mysql query problome

Reply
  #1 (permalink)  
Old 04-16-08, 07:40 AM
prasanth prasanth is offline
New Member
 
Join Date: Apr 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Php based mysql query problome

Hi ,

i am using php based one helpdesk tool i need to modify that tool in that
i am using two tables users,incident

when all user information will be in users table, but i need fetch inceident table details indexed by the users table login name
this is the php and query sample

PHP Code:

if (!@mysql_select_db("helpcore"$link)) {

     echo 
"<p>There has been an error. This is the error message:</p>";
     echo 
"<p><strong>" mysql_error() . "</strong></p>";
     echo 
"Please Contact Your Systems Administrator with the details";
}

/* Passes a Query to the Active Database */
$sql1 mysql_query("SELECT users.id FROM users WHERE (users.loginname='$myusename')");

$result mysql_query("SELECT incidents.id, incidents.description, users.firstname, users.surname, users.loginname FROM incidents,users WHERE (incidents.owner_id = users.id) OR  (incidents.contact_id = '$sql1')"), $link);

if (!
$result) {
  echo(
"<p>Error performing query: " mysql_error() . "</p>"); 
my requerement is when user login that information will store $myusername variable , as per that login name i need to fetch other information from incedints table
Reply With Quote
  #2 (permalink)  
Old 04-16-08, 11:07 AM
blinn_shade's Avatar
blinn_shade blinn_shade is offline
Aspiring Coder
 
Join Date: Aug 2007
Posts: 540
Thanks: 0
Thanked 0 Times in 0 Posts
Try writting your query like this:

PHP Code:


$sql1 
mysql_query("SELECT users.id FROM users WHERE loginname='".$myusename."'");
$row mysql_fetch_array($sql1);
$result mysql_query("SELECT in.id, in.description, u.firstname, u.surname, u.loginname FROM incidents AS in,users AS u WHERE (in.owner_id = u.id OR in.contact_id = '".$row['column_name']."')"), $link); 
Replace $row['column_name'] with the actual column name but keep it in the $row array variable.
__________________
Can you think outside the box but remain inside the box?
Reply With Quote
  #3 (permalink)  
Old 04-16-08, 05:44 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
I'm always curious about this....

Why not just write:

Code:
$sql1 = mysql_query("SELECT users.id FROM users WHERE loginname='$myusename'");
instead of:

Code:
$sql1 = mysql_query("SELECT users.id FROM users WHERE loginname='".$myusename."'");
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
  #4 (permalink)  
Old 04-16-08, 05:54 PM
blinn_shade's Avatar
blinn_shade blinn_shade is offline
Aspiring Coder
 
Join Date: Aug 2007
Posts: 540
Thanks: 0
Thanked 0 Times in 0 Posts
Because in the program I use It makes the variable stand out and I can spot it quicker. See in the code above it stands out?
__________________
Can you think outside the box but remain inside the box?
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
PHP not recognizing admin in MySQL gizelle Database 3 04-15-07 08:39 PM
Php Mysql Bug??? tranquilraven PHP 4 03-01-06 03:06 AM
Need help with some php mysql TheTinkeringToad PHP 9 02-01-06 10:56 AM
PHP multi-dimensional array sorting issue aqw PHP 2 06-24-05 11:09 PM


All times are GMT -5. The time now is 07:42 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.