Forum Moderators: coopster

Message Too Old, No Replies

Help with displaying variable search data

         

MBundy

11:21 am on Nov 11, 2008 (gmt 0)

10+ Year Member



<?php

$var2 = @$_GET['q2'] ; // get the query for the search engine (if applicable)

$trimmed2 = trim($var2); //trim whitespace from the stored variable

$var3 = @$_GET['q3'] ; // get the query for the search engine (if applicable)

$trimmed3 = trim($var3); //trim whitespace from the stored variable

include("det.php");

// Connection to DBase

mysql_connect($host,$user,$pass);

@mysql_select_db($dbase) or die("Unable to select database");

$field_to_search = "field";

$query = "SELECT * FROM pedigree WHERE Name LIKE \"$trimmed2\" or Name LIKE \"$trimmed3\"order by Name";

$result = mysql_query($query);

$count =mysql_numrows($result);

if ($trimmed2 == "")

{

echo "

<body topmargin='0' leftmargin='0'>

<table cellpadding='0' cellspacing='0' border='0' width='800' height='650' valign='top' bgcolor='#223322' background='images/cellbk_bull.gif'>

<tr valign='top'><td height='10'><img src='images/blank.gif'></td></tr>

<tr><td style='border-top: 1px solid #cccccc;border-bottom: 1px solid #cccccc' height='20' background='images/cellbk_dam.gif'><img src='images/blank.gif'></td></tr>

<tr valign='top'><td height='4'><img src='images/blank.gif'></td></tr>

<tr valign='top'><td style='padding-left: 40px;'><font color='#E3F5DF' size='4'><b>You must enter a search term in box 1 prior clicking Search.</b></font></td></tr>

<tr valign='top'><td height='8'><img src='images/blank.gif'></td></tr>

<tr valign='top'><td style='padding-left: 40px;'><font color='#E3F5DF' size='4'><b>Please click the Back button to return to the search page...</b></font></td></tr>

<tr valign='top'><td height='4'><img src='images/blank.gif'></td></tr>

<tr><td style='border-top: 1px solid #cccccc;border-bottom: 1px solid #cccccc' height='20' background='images/cellbk_dam.gif'><img src='images/blank.gif'></td></tr>

<tr valign='top'><td height='570'><img src='images/blank.gif'></td></tr>

</table></body>

";

}

if ($trimmed3 == "")

{

echo "

<body topmargin='0' leftmargin='0'>

<table cellpadding='0' cellspacing='0' border='0' width='800' height='650' valign='top' bgcolor='#223322' background='images/cellbk_bull.gif'>

<tr valign='top'><td height='10'><img src='images/blank.gif'></td></tr>

<tr valign='top'><td style='border-top: 1px solid #cccccc;border-bottom: 1px solid #cccccc' height='20' background='images/cellbk_dam.gif'><img src='images/blank.gif'></td></tr>

<tr valign='top'><td height='4'><img src='images/blank.gif'></td></tr>

<tr valign='top'><td style='padding-left: 40px;'><font color='#E3F5DF' size='4'><b>You must enter a search term in box 2 prior clicking Search.</b></font></td></tr>

<tr valign='top'><td height='8'><img src='images/blank.gif'></td></tr>

<tr valign='top'><td style='padding-left: 40px;'><font color='#E3F5DF' size='4'><b>Please click the Back button to return to the search page...</b></font></td></tr>

<tr valign='top'><td height='4'><img src='images/blank.gif'></td></tr>

<tr valign='top'><td style='border-top: 1px solid #cccccc;border-bottom: 1px solid #cccccc' height='20' background='images/cellbk_dam.gif'><img src='images/blank.gif'></td></tr>

<tr valign='top'><td height='570'><img src='images/blank.gif'></td></tr>

</table></body>

";

exit;

}

// check for a search parameter

if (!isset($var2))

{

echo "

<body topmargin='0' leftmargin='0'>

<table cellpadding='0' cellspacing='0' border='0' width='800' height='650' valign='top' bgcolor='#223322' background='images/cellbk_bull.gif'>

<tr valign='top'><td height='10'><img src='images/blank.gif'></td></tr>

<tr valign='top'><td style='border-top: 1px solid #cccccc;border-bottom: 1px solid #cccccc' height='20' background='images/cellbk_dam.gif'><img src='images/blank.gif'></td></tr>

<tr valign='top'><td height='4'><img src='images/blank.gif'></td></tr>

<tr valign='top'><td style='padding-left: 40px;'><font color='#E3F5DF' size='4'><b>You must enter a search term in both search boxes prior clicking Search.</b></font></td></tr>

<tr valign='top'><td height='8'><img src='images/blank.gif'></td></tr>

<tr valign='top'><td style='padding-left: 40px;'><font color='#E3F5DF' size='4'><b>Please click the Back button to return to the search page...</b></font></td></tr>

<tr valign='top'><td height='4'><img src='images/blank.gif'></td></tr>

<tr valign='top'><td style='border-top: 1px solid #cccccc;border-bottom: 1px solid #cccccc' height='20' background='images/cellbk_dam.gif'><img src='images/blank.gif'></td></tr>

<tr valign='top'><td height='570'><img src='images/blank.gif'></td></tr>

</table></body>

";

}

if (!isset($var3))

{

echo "

<body topmargin='0' leftmargin='0'>

<table cellpadding='0' cellspacing='0' border='0' width='800' height='650' valign='top' bgcolor='#223322' background='images/cellbk_bull.gif'>

<tr valign='top'><td height='10'><img src='images/blank.gif'></td></tr>

<tr valign='top'><td style='border-top: 1px solid #cccccc;border-bottom: 1px solid #cccccc' height='20' background='images/cellbk_dam.gif'><img src='images/blank.gif'></td></tr>

<tr valign='top'><td height='4'><img src='images/blank.gif'></td></tr>

<tr valign='top'><td style='padding-left: 40px;'><font color='#E3F5DF' size='4'><b>You must enter a search term in both search boxes prior clicking Search.</b></font></td></tr>

<tr valign='top'><td height='8'><img src='images/blank.gif'></td></tr>

<tr valign='top'><td style='padding-left: 40px;'><font color='#E3F5DF' size='4'><b>Please click the Back button to return to the search page...</b></font></td></tr>

<tr valign='top'><td height='4'><img src='images/blank.gif'></td></tr>

<tr valign='top'><td style='border-top: 1px solid #cccccc;border-bottom: 1px solid #cccccc' height='20' background='images/cellbk_dam.gif'><img src='images/blank.gif'></td></tr>

<tr valign='top'><td height='570'><img src='images/blank.gif'></td></tr>

</table></body>

";

exit;

}

$numresults=mysql_query($query);

$numrows=mysql_num_rows($numresults);

if ($numrows == 0)

{

echo "<h4>Results</h4>";

echo "<p>Sorry, your search: " . $trimmed2 . " and " . $trimmed3 . " returned zero results</p>";

}

// next determine if s has been passed to script, if not use 0

if (empty($s))

{

$s=0;

}

// get results

$result = mysql_query($query) or die("Couldn't execute query");

if($numrows > 1){ $return = "results";}

else{ $return = "result"; }

/////////////START OUTPUT////////////////

// display what the person searched for

// begin to show results set

$count = 1 + $s ;

while ($row= mysql_fetch_array($result))

{

$Name = $row["Name"];

$Sire = $row["Sire"];

$gs1 = $row["gs1"];

$gs2 = $row["gs2"];

$ggs1 = $row["ggs1"];

$ggs2 = $row["ggs2"];

$ggs3 = $row["ggs3"];

$ggs4 = $row["ggs4"];

$Dam = $row["Dam"];

$gd1 = $row["gd1"];

$gd2 = $row["gd2"];

$ggd1 = $row["ggd1"];

$ggd2 = $row["ggd2"];

$ggd3 = $row["ggd3"];

$ggd4 = $row["ggd4"];

$count++ ;

?>

<!--HTML STARTS-->

<html>

<head>

<title>Shetland Cattle Herd Stud Book</title>

<link rel="stylesheet" href="schbs.css">

</head>

<body>

<table cellspacing="0" cellpadding="0" border="0" width="800" height="312" align="center" bgcolor="#eeeeee" valign="top">

<tr valign="top"><td valign="top">

<table cellspacing="0" cellpadding="0" border="0" valign="top" height="312">

<tr><td rowspan="8">

<table cellspacing="0" cellpadding="0" border="0" valign="top" height="312" width="200">

<tr><td>

<table cellspacing="0" cellpadding="0" border="1" bgcolor="#223322">

<tr><td height="312" width="200" style="padding: 0px 0px 0px 15px"><h6 class="a"><? echo $Name ?></h6></td></tr>

</table>

</td></tr>

</table>

</td>

<td rowspan="4">

<table cellspacing="0" cellpadding="0" border="1" valign="top" height="312" width="200">

<tr><td style="padding: 0px 0px 0px 15px" bgcolor="#223322" background="images/cellbk_bull.gif"><a href="pedigree.php?&query=<? echo $Sire ?>" target = "pedigree"><h6 class="a"><? echo $Sire ?></h6></td></tr>

<tr><td style="padding: 0px 0px 0px 15px" bgcolor="#943122" background="images/cellbk_dam.gif"><a href="pedigree.php?&query=<? echo $Dam ?>" target = "pedigree"><h6 class="a"><? echo $Dam ?></h6></td></tr>

</table>

</td>

<td rowspan="2">

<table cellspacing="0" cellpadding="0" border="1" valign="top" height="312" width="200">

<tr><td style="padding: 0px 0px 0px 15px" bgcolor="#223322" background="images/cellbk_bull.gif"><a href="pedigree.php?&query=<? echo $gs1 ?>" target = "pedigree"><h6 class="a"><? echo $gs1 ?></h6></td></tr>

<tr><td style="padding: 0px 0px 0px 15px" bgcolor="#943122" background="images/cellbk_dam.gif"><a href="pedigree.php?&query=<? echo $gd1 ?>" target = "pedigree"><h6 class="a"><? echo $gd1 ?></h6></td></tr>

<tr><td style="padding: 0px 0px 0px 15px" bgcolor="#223322" background="images/cellbk_bull.gif"><a href="pedigree.php?&query=<? echo $gs2 ?>" target = "pedigree"><h6 class="a"><? echo $gs2 ?></h6></td></tr>

<tr><td style="padding: 0px 0px 0px 15px" bgcolor="#943122" background="images/cellbk_dam.gif"><a href="pedigree.php?&query=<? echo $gd2 ?>" target = "pedigree"><h6 class="a"><? echo $gd2 ?></h6></td></tr>

</table>

</td>

<td>

<table cellspacing="0" cellpadding="0" border="1" valign="top" height="312" width="200">

<tr><td style="padding: 0px 0px 0px 15px" bgcolor="#223322" background="images/cellbk_bull.gif"><a href="pedigree.php?&query=<? echo $ggs1 ?>" target = "pedigree"><h6 class="b"><? echo $ggs1 ?></h6></td></tr>

<tr><td style="padding: 0px 0px 0px 15px" bgcolor="#943122" background="images/cellbk_dam.gif"><a href="pedigree.php?&query=<? echo $ggd1 ?>" target = "pedigree"><h6 class="b"><? echo $ggd1 ?></h6></td></tr>

<tr><td style="padding: 0px 0px 0px 15px" bgcolor="#223322" background="images/cellbk_bull.gif"><a href="pedigree.php?&query=<? echo $ggs2 ?>" target = "pedigree"><h6 class="b"><? echo $ggs2 ?></h6></td></tr>

<tr><td style="padding: 0px 0px 0px 15px" bgcolor="#943122" background="images/cellbk_dam.gif"><a href="pedigree.php?&query=<? echo $ggd2 ?>" target = "pedigree"><h6 class="b"><? echo $ggd2 ?></h6></td></tr>

<tr><td style="padding: 0px 0px 0px 15px" bgcolor="#223322" background="images/cellbk_bull.gif"><a href="pedigree.php?&query=<? echo $ggs3 ?>" target = "pedigree"><h6 class="b"><? echo $ggs3 ?></h6></td></tr>

<tr><td style="padding: 0px 0px 0px 15px" bgcolor="#943122" background="images/cellbk_dam.gif"><a href="pedigree.php?&query=<? echo $ggd3 ?>" target = "pedigree"><h6 class="b"><? echo $ggd3 ?></h6></td></tr>

<tr><td style="padding: 0px 0px 0px 15px" bgcolor="#223322" background="images/cellbk_bull.gif"><a href="pedigree.php?&query=<? echo $ggs4 ?>" target = "pedigree"><h6 class="b"><? echo $ggs4 ?></h6></td></tr>

<tr><td style="padding: 0px 0px 0px 15px" bgcolor="#943122" background="images/cellbk_dam.gif"><a href="pedigree.php?&query=<? echo $ggd4 ?>" target = "pedigree"><h6 class="b"><? echo $ggd4 ?></h6></td></tr>

</table>

</td>

</tr>

</table>

</td></tr>

</table>

</body></html>

<?php

}

?>

The above code works as part of a pedigree search for cattle.
Its the output for a common ancestory search. (input of two animal names to see if they have any common ancestors)

What i would like to add to this, is a script that will automatically colour the echo's if any of the results from either animal is the same.

ie, if animal ones sire was the same as animal two great sire , then these two echo's would be printed in a different colour to the other results.

Any help on this would be great.

Thanks in advance.

eelixduppy

9:52 pm on Nov 12, 2008 (gmt 0)



Create an array with the same size as the number of things you are grabbing from the database. In each element you have a color that you want to make the background and each time you come across something you color it with the corresponding color found in the array. It shouldn't be too difficult to implement. I'd like to ask you to try to write it yourself and ask questions along the way when you encounter them.

MBundy

1:15 am on Nov 13, 2008 (gmt 0)

10+ Year Member



Thanks for the response.

if ($row[$Sire]=$row[$gs1]) { color="green";}

Do you mean something on the lines of that ?

<snip>This is an image of how the page appears at the moment. As you see in that, the top animals' sire is same as lower animals' grandsire, this is what i'm trying to acheive is that those names would appear the same colour.

[edited by: dreamcatcher at 7:56 am (utc) on Nov. 13, 2008]
[edit reason] No urls please! [/edit]

MBundy

3:07 am on Nov 13, 2008 (gmt 0)

10+ Year Member



I know the above didnt work, so i tried :

<h6 <?php if ($Sire=$gs1){echo "class='a1'";} else {echo "class='a'";}?>><? echo $Sire ?></h6>

THis resulted in the <? echo $Sire ?> being replaced by the $gs1 but the text colour changed.

So i tried
<h6 <?php if ($row[$Sire]=$row[$gs1]){echo "class='a1'";} else {echo "class='a'";}?>><? echo $Sire ?></h6>
but nothing happened.