-
mdannatt
- Veteran Member
- Posts: 41
- Joined: 2020-01-27 17:34
Post
by mdannatt » 2021-07-23 15:40
once again my lack of talent has forced me to ask for some help. I have 3 tiles on the homepage (index.php) which show the number of open records that still need attention. (records are closed by simply selecting "yes" as a radio button option). Is there a simple way to hide a badge that is either empty (ie there are no records at all) OR has all records closed? In my header-extras I currently have:
Code: Select all
<?php
$var = sqlValue("SELECT count(1) FROM mytable WHERE record_closed = 'No'");
?>
<script>
jQuery(function () {
$j('#mytable-tile').find('.badge').text('<?php echo $var ?>');
})
</script>
I thought something like this (please don't laugh) would work, but doesn't:
Code: Select all
<?php
$var = sqlValue("SELECT count(1) FROM mytable WHERE record_closed = 'No'");
?>
<script>
jQuery(function () {
if ($var = 0) {
$j('#mytable-tile').find('.badge').hide();}
else {
$j('#mytable-tile').find('.badge').text('<?php echo $var ?>')}
});
</script>
[code]
Roses are red, Violets are blue, unexpected '}' on line 32
-
jsetzer
- AppGini Super Hero
- Posts: 1817
- Joined: 2018-07-06 06:03
- Location: Kiel, Germany
-
Contact:
Post
by jsetzer » 2021-07-23 17:53
You are close but mixed up php and javascript. Wrap the lines with if, else and the line with closing brackets in <?php ... ?>
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readability
AppGini 24.10 Revision 1579 + all AppGini Helper tools
-
jsetzer
- AppGini Super Hero
- Posts: 1817
- Joined: 2018-07-06 06:03
- Location: Kiel, Germany
-
Contact:
Post
by jsetzer » 2021-07-23 17:57
(Not tested)
Code: Select all
<?php
$var = sqlValue("SELECT count(1) FROM mytable WHERE record_closed = 'No'");
?>
<script>
jQuery(function () {
<?php if ($var == 0) { ?>
$j('#mytable-tile').find('.badge').hide();
<?php } else { ?>
$j('#mytable-tile').find('.badge').text('<?=$var ?>').show();
<?php }); ?>
</script>
[code]
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readability
AppGini 24.10 Revision 1579 + all AppGini Helper tools
-
mdannatt
- Veteran Member
- Posts: 41
- Joined: 2020-01-27 17:34
Post
by mdannatt » 2021-07-23 19:12
I looked at your solution and have decided I wasn't close at all.
Your code works, I just made a slight adjustment to the closing }
Code: Select all
<?php
$var = sqlValue("SELECT count(1) FROM mytable WHERE record_closed = 'No'");
?>
<script>
jQuery(function () {
<?php if ($var == 0) { ?>
$j('#mytable-tile').find('.badge').hide();
<?php } else { ?>
$j('#mytable-tile').find('.badge').text('<?=$var ?>').show();
<?php };
?>
});
</script>
Thank you so much, once again, Jan
M
Roses are red, Violets are blue, unexpected '}' on line 32
-
jsetzer
- AppGini Super Hero
- Posts: 1817
- Joined: 2018-07-06 06:03
- Location: Kiel, Germany
-
Contact:
Post
by jsetzer » 2021-07-23 20:51
You are right, I have missed the closing js brackets. Glad it works now!
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readability
AppGini 24.10 Revision 1579 + all AppGini Helper tools