Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts

    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

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    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

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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 11:12 PM.

  • #5
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    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

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    No, I mean what is currently in $ticket. Var_dump it.

  • #7
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    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

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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 *.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •