Help please. Database query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
smoky989
Forum Commoner
Posts: 41
Joined: Mon Sep 02, 2002 1:14 pm

Help please. Database query

Post by smoky989 »

This has been bugging me for a while now, I know its something small but I can't find it. Assuming all my tabel names and column names are spelled right, shich I've double checked, does anyone see a reason this wouldn't work

Code: Select all

<?php

$db = mysql_connect("localhost", "username", "pass");

mysql_select_db ("db");

$result = mysql_query("select roster.w_name, master_roster.w_name, master_roster.show, master_roster.active, master_roster.notes 

from roster, master_roster 

where roster.w_name = master_roster.w_name and roster.status = 1 || roster.status = 3 

order by master_roster.w_name", $db) or die(MySQL_Error());

echo "<table border =2><tr><td colspan=4><b><div align=center>Testing</div></b></td></tr>";

while($myrow = mysql_fetch_array($result))&#123;
	$name = $myrow&#1111;"roster.w_name"]; 
	$show = $myrow&#1111;"master_roster.show"]; 
	$active = $myrow&#1111;"master_roster.active"]; 
	$notes = $myrow&#1111;"master_roster.notes"]; 
	
	echo "<tr><td width=175>";
	echo "$name";
	echo "</td><td>";
	echo "$show";
	echo "</td><td>";
	echo "$active";
	echo "</td><td>";
	echo "$notes";
	echo "</td><tr>";
	
	&#125;;
	
	echo "</table>"
	?>
poeta_eletrico
Forum Commoner
Posts: 32
Joined: Mon Dec 22, 2003 7:33 am
Contact:

Re: Help please. Database query

Post by poeta_eletrico »

well ::::


can u paste here the error message?


poeta_eletrico
smoky989
Forum Commoner
Posts: 41
Joined: Mon Sep 02, 2002 1:14 pm

I dont get one

Post by smoky989 »

I dont get an error message. The script runs and a table is created with nothing in it.
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

The array keys of $myrow will not include the table names

e.g.

$name = $myrow["roster.w_name"];
$show = $myrow["master_roster.show"];
$active = $myrow["master_roster.active"];
$notes = $myrow["master_roster.notes"];

will be....

$name = $myrow["w_name"];
$show = $myrow["show"];
$active = $myrow["active"];
$notes = $myrow["notes"];

As you are selecting both roster.w_name & master_roster.w_name you will have two w_name columns in the results.
smoky989
Forum Commoner
Posts: 41
Joined: Mon Sep 02, 2002 1:14 pm

Post by smoky989 »

ok that got me started. I changed one of the column names from w_name to w_name2 and I get a result now. The only problem is I'm getting each set of info 7 times. Any ideas?

go to http://striketowers.com/master_roster.php if you want to see what I mean.
smoky989
Forum Commoner
Posts: 41
Joined: Mon Sep 02, 2002 1:14 pm

ALL SET

Post by smoky989 »

I got it working from a combination of suggestions. Thanks everyone.
Post Reply