Jump to content


Photo

Query help


  • Please log in to reply
3 replies to this topic

#1 transfield

transfield
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 26 May 2006 - 03:39 PM

Hello,
I have 2 tables in 1 database. The table names are developer and developer_log. I want to use the keywords in developer_log to query developer. Then I want to display the results of this query. So here's how it should work:-
developer_log.company should query developer.name
developer_log.project should query developer.development
developer_log.property should query developer.type

My half written code is below. Please help me to modify it. Thank you very much.

<?php 
$username="abc123"; 
$password="abc123"; 
$database="abc123"; 
$host="localhost"; 

mysql_connect ("$host","$username","$password"); 
mysql_select_db($database) or die( "Where's the database man?"); 

$mktime = date('Y-m-d'); 

$query1=("SELECT * FROM THIS IS WHERE I NEED HELP, I GUESS"); 

$result1=mysql_query($query1); 
$num=mysql_num_rows($result1); 

while ($row1 = mysql_fetch_array($result1)) 
{ 
echo"<b>Year Approved: </b> ".$row1['year']. 
"<p><b>Name of Developer: </b> ".$row1['name']. 
"<p><b>Address: </b> ".$row1['development']. 
"<p><b>Type of Property: </b> ".$row1['type']. 
"<p><b>Levels: </b> ".$row1['levels']. 
"<p><b>Number of Units: </b> ".$row1['quantity']. 
"<p>" 
; 
} 
?>


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 27 May 2006 - 11:42 PM

The non-telepathic amongst us would need to know the structure of those 2 tables so we know which tables contain "levels", "quantity", "year" columns and if you have any selection criteria to extract the particular developer.

Knowing stuff like that really does help to construct the query
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 28 May 2006 - 12:11 AM

** OFF - TOPIC **
Barand you seem to be very good with MySQL and apparently use often MySQL only when I'd use PHP too...
How do you UPDATE tables with values retrieved from other tables? JOIN's seem to be usable only in SELECT...
~ D Kuang

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 28 May 2006 - 10:10 AM

@poirot

Starting with MySQL Version 4.0.4, you can also perform UPDATE operations that cover multiple tables:

UPDATE items,month SET items.price=month.price
WHERE items.id=month.id;

The example shows an inner join using the comma operator, but multiple-table UPDATE statements can use any type of join allowed in SELECT statements, such as LEFT JOIN.

Note: you cannot use ORDER BY or LIMIT with multiple-table UPDATE.



If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users