Ecommerce software home
Shopping Cart Software Forum for Ecommerce Templates
 
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

Find us on Facebook Follow us on Twitter View our YouTube channel
Search our site
 All Forums
 General
 Off topic, News and Updates
 How to add a count to a link?
Author « Topic »  

Positivek9
Ecommerce Template Guru

USA
4061 Posts

Pre-sales questions only
(More Details...)

Posted - 08/14/2019 :  10:17:30  
Hi all,

I tried to google this but came up with nada..hope maybe someone can lend a hand?

On my dog database site I have a button that you click to view the offspring of each dog. What I'd like to do is show a count on the button. A dog has 9 offspring - button would show Offspring (9). No offspring would show Offspring (0).

Code for Offspring button:
if ($szPPOffspring)
echo "<a href='$szPPOffspring?id=$szUrlName&db=$szDatabase&gens=$nGens' role='button' class='btn btn-default btn-xs'>Offspring</a> ";

Any ideas? I'm happy to pay for someone's time.. :)

Site: https://**see-cool-link-in-profile**/pp_offspring.php?id=Faye%20of%20Wolverhampton&db=pedigree&gens=4




Julie
Owned & loved by 6 German Shepherds
~ RIP Menace ~

dbdave
ECT Moderator

USA
10271 Posts

Posted - 08/14/2019 :  10:42:35  
Hi Julie, the way I would do it is ask the database how many matches there are with a SELECT COUNT sql query - https://www.w3schools.com/sql/func_mysql_count.asp

Assign the result to a variable, and then call that variable up to show next to the button.

I am guessing "$szPPOffspring" is what you need to count, is that right?
You might just find the existing SQL query that creates the $szPPOffspring info and modify that query to get your count.
It should be pretty easy to do.

Positivek9
Ecommerce Template Guru

USA
4061 Posts

Pre-sales questions only
(More Details...)

Posted - 08/14/2019 :  10:56:29  
Hmmm, okay...

All I see in the code is:
function PrintLinks($szLinkName)
{
global $szPPPedigree, $szPPExternalPed, $szPPVertical, $szPPAncestors, $szPPSibling;
global $szPPOffspring, $szPPReverse, $szPPTrial, $szPPCorrection;
global $szDatabase, $nGens, $bMobile, $szEncryptionKey;

Don't think that's a query as the $szPPOffspring just comes from the config file:

$szPPOffspring = "pp_offspring.php";

Fraid this is over my head. I don't think a mysql count(0) will work as the offspring are generated dynamically?


Julie
Owned & loved by 6 German Shepherds
~ RIP Menace ~

Edited by - Positivek9 on 08/14/2019 11:00:41

Positivek9
Ecommerce Template Guru

USA
4061 Posts

Pre-sales questions only
(More Details...)

Posted - 08/14/2019 :  11:03:46  
Here is the code that generates the offspring:

# get list of breedings
$sql = $nIsMale ? "select $szFieldSet FROM $szDatabase where sireid=$nId order by dob, damid limit 1000;" :
"select $szFieldSet FROM $szDatabase where damid=$nId order by dob, sireid limit 1000;";

$result = mysqli_query($link, $sql);
if (!$result)
{
die('Invalid query: ' . mysqli_error($link));
}
$nLastMate = -2;
$LastDob = "";
$nLitter = 0;
while ($aRow = mysqli_fetch_row($result))
{
if ($nIsMale)
{
if ((int)$aRow[2] < -1)
continue;
# Detect change in mate
if ((int)$aRow[2] != $nLastMate || $aRow[6] != $LastDob)
{
$nLitter++;
if ($nLastMate > -2)
{
# close off previous
echo "</ol></td></tr>\n";
}
$nLastMate = (int)$aRow[2];
$LastDob = $aRow[6];
echo "<tr><td style='width:20%' rowspan='2'>Litter $nLitter<br/>$LastDob</td><td colspan='2' style='background-color:#ececec'>\n";
# echo details of the mate - look up in previous map
if ($nLastMate != -1)
PrintNode(explode('~', $hashDetails[$nLastMate]));
else
echo "Unknown";
echo "</td></tr><tr><td>Offspring</td><td><ol>";
}
}
else
{
if ($aRow[1] < -1)
continue;
# Detect change in mate
if ((int)$aRow[1] != $nLastMate || $aRow[6] != $LastDob)
{
$nLitter++;
if ($nLastMate > -2)
{
# close off previous
echo "</ol></td></tr>";
}
$nLastMate = (int)$aRow[1];
$LastDob = $aRow[6];
echo "<tr><td style='width:60px' rowspan='2'>Litter $nLitter<br/>$LastDob</td><td colspan='2' style='background-color:#ececec'>\n";
# echo details of the mate - look up in previous map
if ($nLastMate != -1)
PrintNode(explode('~', $hashDetails[$nLastMate]));
else
echo "Unknown";
echo "</td></tr><tr><td>Offspring</td><td><ol>";
}
}
# Now echo offspring
echo "\n<li>";
PrintNode($aRow);
}
echo "</table>\n";

mysqli_close($link);

function SingleNode($nNodeId)
{
global $szDatabase, $szFieldSet, $link;
$sql = "SELECT $szFieldSet FROM $szDatabase where pedigreeid=$nNodeId";
$result = mysqli_query($link, $sql);
if (!$result)
{
die('Invalid query: ' . mysqli_error($link));
}

if ($aRow = mysqli_fetch_row($result))
{
PrintNode($aRow);
}
}


Julie
Owned & loved by 6 German Shepherds
~ RIP Menace ~

dbdave
ECT Moderator

USA
10271 Posts

Posted - 08/14/2019 :  11:15:09  
Hi Julie, so the code above ^^^ is from pp_offspring.php?

The info is in the database, we just have to ask for it (the right way) and then do something with that info.

Positivek9
Ecommerce Template Guru

USA
4061 Posts

Pre-sales questions only
(More Details...)

Posted - 08/14/2019 :  11:18:56  
Yep... that code is from the pp_offspring page. :)

Julie
Owned & loved by 6 German Shepherds
~ RIP Menace ~

Positivek9
Ecommerce Template Guru

USA
4061 Posts

Pre-sales questions only
(More Details...)

Posted - 08/14/2019 :  11:21:12  
I have an offspring test page still on the server if you want to play around with it. Do you still have the ftp info?

Julie
Owned & loved by 6 German Shepherds
~ RIP Menace ~

dbdave
ECT Moderator

USA
10271 Posts

Posted - 08/14/2019 :  11:32:44  
Send the ftp over to my email if your would.
I suppose the pp_offspring page serves two purposes. It's an available page to show the offspring, and it is called to generate the button (links) on the pp_pedigree.php and other pages.
I'm just not sure if we make the change in the offspring script that it will show on the pp_pedigree.php page for example.

I can do a quick text to see though.

Positivek9
Ecommerce Template Guru

USA
4061 Posts

Pre-sales questions only
(More Details...)

Posted - 08/14/2019 :  11:42:14  
oh, yeah, I see what you're saying... arrgh. They all use commonped as an include via the header include. So somehow we'd need to get the count from the offspring page and then show as a result on the other 4 pages. See, I knew it wouldn't be simple. ;)

I'll send the ftp over in a sec.

Julie
Owned & loved by 6 German Shepherds
~ RIP Menace ~

dbdave
ECT Moderator

USA
10271 Posts

Posted - 08/14/2019 :  12:24:16  
I am looking at it Julie. The file is pp_common.php and that's where I am working now.

Positivek9
Ecommerce Template Guru

USA
4061 Posts

Pre-sales questions only
(More Details...)

Posted - 08/14/2019 :  12:29:23  
yes, sorry! common.php....

::keeping fingers crossed::

Julie
Owned & loved by 6 German Shepherds
~ RIP Menace ~

dbdave
ECT Moderator

USA
10271 Posts

Posted - 08/14/2019 :  13:36:47  
Hi Julie, I need to understand how the dogs get marked as an offspring.
When adding a dog, how do you indicate it's a sibling/offspring of another dog?
I might want to get a look at the database columns.

Positivek9
Ecommerce Template Guru

USA
4061 Posts

Pre-sales questions only
(More Details...)

Posted - 08/14/2019 :  14:01:29  
Good question!

When a dog is added, you select the sire and dam name and it pulls the database number assigned to that sire/dam (PedigreeId), then displays the name associated with the PedigreeId in the pedigree. The code makes the associations with siblings/offspring. (I guess... honestly not quite sure.)

Send me an email & I can screenshot the columns.



Julie
Owned & loved by 6 German Shepherds
~ RIP Menace ~

dbdave
ECT Moderator

USA
10271 Posts

Posted - 08/14/2019 :  20:41:30  
Just to follow up here, It looks like I got this working Julie.
It took a bit to get the logic of the code, but the select count() does the magic.

David

Positivek9
Ecommerce Template Guru

USA
4061 Posts

Pre-sales questions only
(More Details...)

Posted - 08/14/2019 :  20:49:23  
Oh my gosh!

That is so awesome, I am so thrilled you got it all working!!!

I am forever in your debt.....

Julie
Owned & loved by 6 German Shepherds
~ RIP Menace ~

dbdave
ECT Moderator

USA
10271 Posts

Posted - 08/14/2019 :  20:57:22  
No problem. I need more experience with .php so I picked up a few lessons along the way.
  « Topic »  
Jump To:
Shopping Cart Software Forum for Ecommerce Templates © 2002-2022 ecommercetemplates.com
This page was generated in 0.02 seconds. Snitz Forums 2000