Forum Moderators: coopster & phranque

Message Too Old, No Replies

mySQL Problem / Thoery

Any advice..

         

ukgimp

3:29 pm on Sep 12, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For examples sake say I have the following SQL and wish to dump the contents of a DB onto a web page using PHP

$sql = "SELECT *
FROM Table1, Table2
WHERE Table1.ParameterX = Table2.ParameterX
AND Table1.ParameterX='A'";

Printing this out only shows the FK value from the main table instead of the full value from table 2.

Also is there a better altenative to the "SELECT *" as that would be prone to downgrading as the contents of the DB increased.

Cheers

ukgimp

3:32 pm on Sep 12, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Unbelievable, after a good few hours the very next time I try it it works.

Still curious with regards to the SELECT.

Cheers

mrgym

4:33 pm on Sep 12, 2002 (gmt 0)

10+ Year Member



I don't know what you mean by "downgrading", but you can LIMIT the number of rows retrieved using a select statement, or you can apply conditions on the rows retrieved using WHERE.....

jatar_k

5:18 pm on Sep 12, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



If you want to select all of the columns then * is your best bet. Like mrgym says, limit the amount of rows you are getting to the amount you need on that particular page. I doubt you will need all of the rows each time.

Use limit to select 10 to display, always make sure you are using your queries to the utmost and leave less work for your scripts. If you have the script do all of the sorting and selecting of data you are increasing the workload exponentially. Mysql can do most of the work for you.

<added>Welcome to WebmasterWorld [webmasterworld.com] mrgym

lorax

5:28 pm on Sep 12, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



ukgimp

You can use
$q = "SELECT table1.field1, table2.field1
FROM table1,table2
WHERE table1.field2 = table2.field2";

Instead of calling all fields with * - I'm not sure of the time savings using this method but I'm under the impression (rightly or wrongly) it will reduce query times.

As long as the field names are different in the two tables you can call your values after fetching the array with $array["fieldname"]

Cheers!
GB