Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4049106
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:54:09+00:00 2026-05-20T13:54:09+00:00

EDITED I’m trying to setup a random link at the bottom of all my

  • 0

EDITED

I’m trying to setup a random link at the bottom of all my pages. I’m using the code below, but want to make it so the current page is not included in the random rotation of links.

Example:

I need code to randomly select and display ONE of these links. The exception being, IF article1.php is currently being viewed, I want it to be excluded from the random selection. That way only links to OTHER articles are seen on any given article.

http://mysite.com/article1.php
http://mysite.com/article2.php
http://mysite.com/article3.php
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T13:54:11+00:00Added an answer on May 20, 2026 at 1:54 pm

    I would use array_rand with something like:

    <?php
    $links = array(array('url' => 'http://google.com', 'name'=>'google'),
                   array('url' => 'http://hotmail.com', 'name' => 'hotmail'),
                   array('url' => 'http://hawkee.com', 'name' => 'Hawkee'));
    $num = array_rand($links);
    $item = $links[$num];
    
    printf('<a href="%s" title="%s">%s</a>', $item['url'], $item['name'], $item['name']);
    ?>
    

    Where links makes it easier to build an array. Nevertheless, I think we miss some details about how you grab your links.
    What is the mean of “current page”? because the simplest way to do, is just not add the page to the array.

    And the use of array_rand avoids confusion with size of array and so.

    Edit: I suppose you use a database, so you may have an sql request like:

    SELECT myfieldset FROM `articles` WHERE id = 'theid';
    

    So you know the id of the current article. Now you just have to build an array with some other articles with a query like:

    SELECT id FROM `articles` WHERE id NOT IN ('theid') ORDER BY RAND LIMIT 5
    

    And build the candidate array with those results.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

*edited 6/17/10 I'm trying to understand how to improve my code (make it more
EDITED I'm using Twitter Bootstrap and need to move navbar right( not float:right, but
[EDITED: I left the original question below, with some more context and code to
/* Edited to make sense! */ I 900 lines of this: ;745;ref;name;Adress;zipcode;;mobphone;;;;;;;;; i want
(edited to include suggestions from Martin Honnen) Hello All, I've been trying to get
[edited] I am trying to make a script that downloads a file, the problem
Edited Question: Trying to use a .dll file from Java using JNA. I've managed
EDITED BELOW FOR UPDATES!!! Thank you for the help, please by all means point
Edited after initial suggestions about using IEnumerable instead of List. I am trying to
EDITED I am using Sencha touch charts sample provided for column charts. The code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.