Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-07-2012, 09:52 PM   PM User | #1
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
Left Join incorrect

hi guys, ive got this code below, however its only displaying one of the echo's that ive produced, and thats the email.

PHP Code:
$sqlhd "SELECT h.*,ht.* "
     
" FROM helpdesk AS h LEFT JOIN helpdeskreplies AS ht ON h.id=ht._ticketid "
     
" WHERE h.id='" $ticketid "' LIMIT 1";



$queryhd=mysql_query$sqlhd ) or die( mysql_error() );  
$ticket mysql_fetch_object($queryhd);


echo 
"$ticket->email<br>";

echo 
"$ticket->username<br>";

echo 
"$ticket->_ticketid<br>"
I know ive gone wrong somewhere, i just cant see it, so if someone has better eyes than me, please can you help me out.

Thanks

Dan
__________________
http://360-tactics.co.uk/forum/index.php

Crime-Wave

please post your code wrapped in tags
please post your PHP wrapped in tags
Dan13071992 is offline   Reply With Quote
Old 05-07-2012, 09:59 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
What is the structure and relationship of helpdesk and helpdeskreplies?
You can also do a simple print_r/var_dump on $ticket to see what's in it.
Fou-Lu is offline   Reply With Quote
Old 05-07-2012, 10:07 PM   PM User | #3
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
Help Desk:

Code:
# 	Column 	Type 	Collation 	Attributes 	Null 	Default 	Extra 	Action
	1 	id 	int(12) 			No 	None 	AUTO_INCREMENT 	Change Change 	Drop Drop 	More Show more actions
	2 	username 	varchar(40) 	latin1_swedish_ci 		No 	None 		Change Change 	Drop Drop 	More Show more actions
	3 	email 	varchar(100) 	latin1_swedish_ci 		No 	None 		Change Change 	Drop Drop 	More Show more actions
	4 	catid 	varchar(100) 	latin1_swedish_ci 		No 	None 		Change Change 	Drop Drop 	More Show more actions
	5 	data1 	varchar(40) 	latin1_swedish_ci 		No 	None 		Change Change 	Drop Drop 	More Show more actions
	6 	data2 	varchar(150) 	latin1_swedish_ci 		No 	None 		Change Change 	Drop Drop 	More Show more actions
	7 	maincontent 	text 	latin1_swedish_ci 		No 	None 		Change Change 	Drop Drop 	More Show more actions
	8 	helplevel 	enum('0', '1') 	latin1_swedish_ci 		No 	0 		Change Change 	Drop Drop 	More Show more actions
	9 	date 	datetime 			No 	None 		Change Change 	Drop Drop 	More Show more actions
	10 	updateddate 	datetime 			No 	None 		Change Change 	Drop Drop 	More Show more actions
	11 	status 	enum('0', '1', '2', '3') 	latin1_swedish_ci 		No 	0 		Change Change 	Drop Drop 	More Show more actions
the relationship for helpdesk is id and for helpdeskreplies its _ticketid


Helpdeskreplies:

Code:
# 	Column 	Type 	Collation 	Attributes 	Null 	Default 	Extra 	Action
	1 	id 	int(32) 			No 	None 	AUTO_INCREMENT 	Change Change 	Drop Drop 	More Show more actions
	2 	_ticketid 	int(32) 			No 	None 		Change Change 	Drop Drop 	More Show more actions
	3 	username 	varchar(20) 	utf8_general_ci 		No 	None 		Change Change 	Drop Drop 	More Show more actions
	4 	reply 	varchar(300) 	utf8_general_ci 		No 	None 		Change Change 	Drop Drop 	More Show more actions
__________________
http://360-tactics.co.uk/forum/index.php

Crime-Wave

please post your code wrapped in tags
please post your PHP wrapped in tags
Dan13071992 is offline   Reply With Quote
Old 05-07-2012, 10:09 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
And what's in the $ticket object?
Edit:
This is ambiguous as well which is likely a part of the problem. It can't tell what 'username' is associated with.

Last edited by Fou-Lu; 05-07-2012 at 10:12 PM..
Fou-Lu is offline   Reply With Quote
Old 05-07-2012, 10:14 PM   PM User | #5
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
do you mean what am i looking to get?

$ticket should be used to display everything from helpdeskreplies, aswell as some information from helpdesk, such as category id, username, maincontent ect.

its a helpdesk system that will have many different replies to the specific help desk ticket.

If i have got the wrong impression of what you mean by object, please let me know so i can correct myself.
__________________
http://360-tactics.co.uk/forum/index.php

Crime-Wave

please post your code wrapped in tags
please post your PHP wrapped in tags
Dan13071992 is offline   Reply With Quote
Old 05-07-2012, 10:15 PM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
No, I mean what is currently in $ticket. Var_dump it.
Fou-Lu is offline   Reply With Quote
Old 05-07-2012, 10:18 PM   PM User | #7
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
Var Dump:

object(stdClass)#7 (13) { ["id"]=> NULL ["username"]=> NULL ["email"]=> string(21) "dos1392@hotmail.co.uk" ["catid"]=> string(1) "9" ["data1"]=> string(0) "" ["data2"]=> string(0) "" ["maincontent"]=> string(10) "fsdgsdfgfd" ["helplevel"]=> string(1) "0" ["date"]=> string(19) "2012-05-01 09:16:07" ["updateddate"]=> string(19) "2012-05-01 09:16:07" ["status"]=> string(1) "0" ["_ticketid"]=> NULL ["reply"]=> NULL }



the whole ticketid in this page is collected from a $_GET which is from the tickets a user has already submitted,
__________________
http://360-tactics.co.uk/forum/index.php

Crime-Wave

please post your code wrapped in tags
please post your PHP wrapped in tags
Dan13071992 is offline   Reply With Quote
Old 05-07-2012, 10:52 PM   PM User | #8
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Run this query directly on the command line utilities or on PHPMyAdmin. It looks to me that your entries in helpdeskreplies are null entries. You should be using innodb relations to ensure the integrity of the table relationships.
Also make sure to separate the fields appropriately within the query. Do not select *.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:52 AM.


Advertisement
Log in to turn off these ads.