confusing myself with double table query


#1

[php]
} elseif ($_GET[ViewPlans]) {

$View_Plan_Query = mysql_query("SELECT hosts_name.name,hosts_info.id,hosts_info.name FROM hosts_name,hosts_info WHERE hosts_name.id = hosts_info.host_id");
$Host_Array = mysql_fetch_array($View_Plan_Query);
echo "$Host_Array[0]";
while ($row = mysql_fetch_array($View_Plan_Query)) {
echo "<TR><TD colspan="3"><A HREF="$PHP_SELF?EditPlan=$row[id]">$row[name]</A></TD></TR>";
}

} else {
[/php]

Alright. I had this working. I changed something and to the point that I’m not sure what it was, but it is not erroring, and the array is populated. Pretty much this is drawing from two tables, and i can’t figure out why it wont display the buttom proportion, only the top. It has to be something simple. Not sure. Any help would be appreciated, and if their is a better way of doing this let me know. The hole goal was to bring out the information in 1 query, but at the same time make it so the info drawn from the hosts_name.name was not looped, only displayed once, while the rest of the data is looped.

Thanks for the help and suggestions!

Drew


#2

I am pretty sure the problem is the way I am referencing the array. As when querying 2 different tables it creates two arrays inside of the main array, correct?

i.e.

array (
array ( table 1, info, info, info, info )
array (table 2, info, info, info, info)

)

I tried using $row[1][name] to find the info as well and that did not work. Any ideas?


#3

You call mysql_fetch_array() and then you call it again right afterwards. Both of these are moving the internal pointer of the mysql reuslt set forward by one. I think this is probobly why the result isn’t what you expect. Also, doing a multi table query doesn’t change the way mysql_fetch_array returns its result set. It functiosn the same with one table or 100 tables. If you only want to display the name for the host once but show all the entries for the host then I would order the query by name and then write a small if statement to compare the current value of name to the last and if it’s different then print the new name, if not just print the detailed info.

Keith


#4

… and my biggest problem with coding… i make things more difficult then they need to be… Thank You Sir :)

[php]
} elseif ($_GET[ViewPlans]) {

$View_Plan_Query = mysql_query("SELECT hosts_name.name,hosts_info.id,hosts_info.name FROM hosts_name,hosts_info WHERE hosts_name.id = hosts_info.host_id");
$display_once = 1;
while ($row = mysql_fetch_array($View_Plan_Query)) {
	if ($display_once = 1) {
	echo "$row[0]";
	}
echo "<TR><TD colspan="3"><A HREF="$PHP_SELF?EditPlan=$row[id]">$row[name]</A></TD></TR>";
$display_once++;	
}

} else {
[/php]