Re: Making a Variable from different tables with Matching Db fields?

From: Date: Wed, 28 Jan 2009 21:42:39 +0000
Subject: Re: Making a Variable from different tables with Matching Db fields?
References: 1 2 3 4 5 6  Groups: php.general 
Request: Send a blank email to php-general+get-287319@lists.php.net to get a copy of this message
> >> Because there is ambiguity w/r/t the columns you are selecting, you'll > >> need to use aliases. > >> > >> http://dev.mysql.com/doc/refman/5.1/en/identifiers.html > >> In your code, when you are referencing the column, do so using the > >> alias. That should solve your problem. > > I just read it 3 times and I don't understand it. > Try this... (just make sure to assign a valid $username value.) > $sql = > "SELECT workorders.WorkOrderID , workorders.AdminID > FROM workorders > INNER JOIN > admin > ON workorders.AdminID = admin.AdminID > WHERE admin.UserName = '" . mysql_real_escape_string($username) . "'"; Andrew is right. If you use the above query, that will probably get you going. But in general, aliases allow you to reference a column as something other than what it is named in the table's schema. It would allow you to do something along the lines of: SELECT Employee.Name AS EmployeeName, Employer.Name AS EmployerName FROM blah blah blah. In the above example, the column "Name" is ambiguous. By defining an alias, it removes the ambiguity and allows mysql to return the value of both columns. In your code, you would just reference it using: $rowData['EmployeeName'] $rowData['EmployerName'] I hope that helps explain aliases a bit. thnx, Christoph

« previous php.general (#287319) next »