Page 2 of 2

Posted: Wed Oct 20, 2004 1:15 pm
by feyd
you can consolidate the first 2 queries you have into 1, and the three after that into 1. Since the query is the same for each set, you can bring the variable setting into one block like so:

Code: Select all

$sql = mysql_query($query) or die(mysql_error());
$categories = array();
$whatever = array();
while($row = mysql_fetch_assoc($sql))
{
  $categories[] = $row['category'];
  $whatever[] = $row['something else'];
}

Posted: Sat Oct 23, 2004 6:27 am
by ynoc
try to avoid cross product queries
e.g.

Code: Select all

select t1.thing1, t2.thing2 from table1 as t1, table2 as t2 where .....
try to use joins instead, these are usually more efficient

Posted: Sun Oct 24, 2004 5:38 am
by devilgrendall
Thanks for your advice and help.

I solved it in the end by doing the multiple query.

Code: Select all

<?php
			include ("**");
			$link = mysql_connect($host, $user, $password) or die ("Could not connect.");
			$result = mysql_db_query($dbname,$sql,$link);
			$sql = mysql_query("SELECT * FROM table ORDER BY keyindex desc limit 5") OR die(mysql_error());
					while($row = mysql_fetch_array($sql, MYSQL_ASSOC))
					{
   				  $categories [] = $row['category'];
				  $articlenames [] = $row['articletitle'];
						}
			$sql = mysql_query("SELECT * FROM table2 ORDER BY keyindex desc limit 4") OR die(mysql_error());
					while($row = mysql_fetch_array($sql, MYSQL_ASSOC))
					{
   				  $bname [] = $row['buildingname'];
				  $count [] = $row['county'];
						}
						
			$rows = mysql_num_rows($sql);
			if($rows) {
			$message = "$rows records found";
			}
			else{
			echo "No records found";
			}			
			
			mysql_close($link);
?>
HTML BIT

Code: Select all

<?php echo $bname[$indexcount]; ?>
Etc etc

Thanks again


Jay