Inserting PHP into homelinks array

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
TheNoLifer
Veteran Member
Posts: 67
Joined: 2015-06-06 12:10

Inserting PHP into homelinks array

Post by TheNoLifer » 2015-12-16 03:25

Hi all,

I have written some horribly inefficient PHP, at the limit of my abilities, to select a random ID number from one of my tables, with the purpose of creating a URL which, when clicked, will take you to a random record in the table. I have it working in a test page, here - http://ada.abernyte.org/random.php

The code, for those interested, is;

Code: Select all

//connect to DB up here - not shown
$result = mysql_query("SELECT id FROM ContentItem ORDER BY RAND() LIMIT 1") or die(mysql_error());
if(is_resource($result) and mysql_num_rows($result)>0){
    $row = mysql_fetch_array($result);
//    echo $row["id"];
}
then in the html section;

Code: Select all

<p><?php echo "<a href='http://ada.abernyte.org/ContentItem_view.php?SelectedID=".$row['id']."'>Display a Random Content Item Record</a>" ?></p>
Now! I wish to add a new homelink to the main screen - something like this;
random_item_1.PNG
random_item_1.PNG (46.92 KiB) Viewed 3585 times
But I am having trouble inserting my $row['id'] code into the array which builds the homelinks;
homelinks_syntax.PNG
homelinks_syntax.PNG (6.83 KiB) Viewed 3585 times
I've tried many different combinations - I'm sure it's a syntax issue, but my php skills are poor and I'm not sure what I'm doing wrong. It most often just displays a white page when I try to add it.

Any ideas would be much appreciated!

Ally

TheNoLifer
Veteran Member
Posts: 67
Joined: 2015-06-06 12:10

Re: Inserting PHP into homelinks array

Post by TheNoLifer » 2015-12-16 17:28

Solved.

Syntax is;

Code: Select all

'url' => '/ContentItem_view.php?SelectedID='.$row[id].'',
Button is working. New ID is selected on each page reload.
random_item.JPG
random_item.JPG (22.25 KiB) Viewed 3569 times

User avatar
a.gneady
Site Admin
Posts: 1354
Joined: 2012-09-27 14:46
Contact:

Re: Inserting PHP into homelinks array

Post by a.gneady » 2015-12-16 22:08

Thanks for sharing your solution.
One little modification I'd recommend for more portable code is to remove the starting slash:

Code: Select all

'url' => 'ContentItem_view.php?SelectedID='.$row[id],
This would allow the link to work fine if your application is in a sub folder rather than the website root (and would still work in your case where the application is in the site root folder).
:idea: AppGini plugins to add more power to your apps:

Post Reply