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 8081443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:43:51+00:00 2026-06-05T16:43:51+00:00

for example i have: <?php foreach($query as $q): ?> <div class=item> <?php echo img($q->images);

  • 0

for example i have:

<?php foreach($query as $q): ?>
        <div class="item">
        <?php echo img($q->images); ?>
        </div>
<?php endforeach; ?>

so this code renders 5 divs in a line, each line 5 divs, and this code:

<?php foreach($url->result() as $u): ?>

<script>
$(document).ready(function(){
    $('div.item').click(function(){

        setTimeout(function(){

                    window.open('<?php echo $u->url; ?>');


        }, 500)

    })
})
</script>
<?php break; ?>
<?php endforeach; ?>

doesn’t matter what div we click, it will open a new window with the same url, but what if I have 5 different urls in my database, and I want that when we click the first div of each line it open one window with the first url and when we click the second it will open the second url

i thinked that this is possible by using classes, for example class=”item1″, item2, item3, item4, item5, but what if we have only 3 urls, not 5, in this case how can i make that the first three divs will open the first 3 urls, but the 2 left, will open the last, it is the 3 div

sorry for my poor english, maybe you have an idea of how to do this, thanks!

ps: i am using codeigniter

  • 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-06-05T16:43:53+00:00Added an answer on June 5, 2026 at 4:43 pm

    Instead of a class you can have id like item_1, item_2 etc. for each of the division and in javascript you can setup listeners in each of the divs separately.

    <?php $index = 0;?>
    <?php foreach($query as $q): ?>
            <div id="item_<?php echo $index++;?>">
            <?php echo img($q->images); ?>
            </div>
    <?php endforeach; ?>
    

    For Javascript the code goes as:

    <?php $index = 0;?>
    <?php foreach($url->result() as $u): ?>
    
    <script>
    $(document).ready(function(){
        $('#item_<?php echo $index++;?>').click(function(){
    
            setTimeout(function(){
    
                    window.open('<?php echo $u->url; ?>');
    
    
        }, 500)
    
    })
    })
    </script>
    <?php break; ?>
    <?php endforeach; ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For Example if i have my code like this (php): <?php somefunc(1); function somefunc($a)
Suppose I have a example.php file like that: <p> <?php echo _('Hello world') ?>
I have a PHP array which looks like this example: $array[0][0] = 'apples'; $array[0][1]
I have a basic PHP question, take the code below for example, let's say
I have looked at this example using php and GD to piecewise-render a spiral
I have a PHP array: foreach($xpath->query('//a') as $element) { $linklabel[] = $element->textContent; $link[] =
I have some php code that was like this: $row = mysql_fetch_array ( mysql_query(SELECT
I have this $img['hash'] which is a long hash code 32-64 digits a09806aa003033128f44d5fd4c56786b (as
For example I have in a conf.php file: $GLOBALS[no_access] = '^forbidden|restricted|xampp|apache\_pb'; blocking these files/folders
Here is example which I have try <?php include 'spider/classes/simple_html_dom.php'; $html = new simple_html_dom();

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.