This topic is locked

stumped on query that works on one page but not another

4/20/2017 4:03:31 PM
PHPRunner General questions
M
mhollibush author

I have a table dogs
dogID ( all the dogs )

sireID ( the dog that is the father )

damID ( the dog that is the mother )

regname ( name of the dog )
I have a tab on the view page "known offspring"
I created a snippet in the tab
and placed the following code ( based on example in manual )
global $dal;
$tblOrders = $dal->Table("dogs");

$rs = $tblOrders->Query("sireID=".$_REQUEST["editid1"],"");

$data = db_fetch_array($rs);

$CustomerID = $data["sireID"];

echo "<font size='1'><i>based on dogs entered in the system</i></font>
";

$rsOrders = $tblOrders->Query("sireID='".$CustomerID."'","");

while($data=db_fetch_array($rsOrders))

{

echo "<a href=dogs_view.php?editid1=".$data["dogID"].

">". $data["regname"]."</a>
";

}
I don't get any results with this?
I have this working with a different tab in the person table where it looks up all the dogs the person owns.
global $dal;
$tblOrders = $dal->Table("dogs");

$rs = $tblOrders->Query("owner=".$_REQUEST["editid1"],"");

$data = db_fetch_array($rs);

$CustomerID = $data["owner"];

echo "<font size='1'><i>based on dogs entered in the system</i></font>
";

$rsOrders = $tblOrders->Query("owner='".$CustomerID."'","");

while($data=db_fetch_array($rsOrders))

{

echo "<a href=dogs_view.php?editid1=".$data["dogID"].

">". $data["regname"]."</a>
";

}
That works -
I also will be doing this for another tab in the dogs view where it will list all the breedings the dog has done

this will need to look up based on dogID and gender

So if the gender is female - it looks up all the males that the female has been bred to

and if the gender is a male - it looks up all the females that it has been bred to...
dogID - dogs in the table

sireID - sires in the table

damID - dams in the table

gender - Male / Female
I am stumped on this - any help would be greatly appreciated.

A
Athlon 5/30/2017

Your code looks wrong,
You should be pulling the $data after the while or it won't populate on the loop..it is only looking once as is... Unless I am misreading...

Mike.
example:
global $dal;

$tblUsers = $dal->Table("MAR");

$rs = $tblUsers->Query("UniqueID ='".$deleted_values['UniqueID']."'","Date_Added ASC");

$TotalSummary ="";

while( $data = db_fetch_array($rs) )
{
$TotalSummary = $TotalSummary."\n\n".$data["Summary"];
}
unless you are meaning something else... only read it quick .