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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:40:46+00:00 2026-06-10T10:40:46+00:00

The following query works, but for some reason the first select statement is the

  • 0

The following query works, but for some reason the first select statement is the only URL being displayed. Items from other tables are displayed, however, their URL is wrong.

$sql = "(SELECT postsID as postsID, postsSubject AS postsSubject, postsTimestamp AS timestamp
                FROM   posts
                WHERE  postsCategory = '$id')
            UNION 
                (SELECT eventID as eventID, eventTitle as eventTitle, eventsTimestamp as timestamp
                FROM   events
                WHERE  eventLocation = '$id')
            ORDER BY timestamp DESC";

The information is being correctly displayed from both the events and posts table, but the results are appearing to ONLY come from the posts table.

For example, say I have the following info

postsID |  postsSubject |  postsTimestamp
  1            post             123

eventID |  eventTitle   | eventsTimestamp
  2           event            456

I have the following to display my results

   while($row = mysql_fetch_assoc($result)){
    ?>
        <tr><td><? echo '<a href="viewevent.php?eventID=' . $row['eventID'] . '">' . $row['eventTitle'] . '</a>' ; ?></td>
        <tr><td><? echo '<a href="viewpost.php?postID=' . $row['postsID'] . '">' . $row['postsSubject'] . '</a>' ; ?></td>
    <?  
        if(preg_match('/[0-9]/',$row['timestamp'])){        
            list($yyyy,$dd,$mm) = explode('-',$row['timestamp']);
                    $newDate = $dd."-".$mm."-".$yyyy;
            }
        ?>
            <td><center><? echo $newDate; ?></center></td></tr>
        <?
        }
        echo '</table>';
}

The output appears to be correct

post   123
event  456

However, both results link to the following (respectively)

viewpost.php?id = 1
viewpost.php?id = 2  //this should be viewevent.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-06-10T10:40:48+00:00Added an answer on June 10, 2026 at 10:40 am

    sql as below:

    $sql = "(SELECT postsID as ids, postsSubject AS description, postsTimestamp AS timestamp,'p' as status
                    FROM   posts
                    WHERE  postsCategory = '$id')
                UNION 
                    (SELECT eventID as ids, eventTitle as description, eventsTimestamp as timestamp, 'e' as status
                    FROM   events
                    WHERE  eventLocation = '$id')
                ORDER BY timestamp DESC";
    

    when retrieving data,

    while($row = mysql_fetch_assoc($result)){
         if ($row['status']=="e"){
        ?>
            <tr><td><? echo '<a href="viewevent.php?eventID=' . $row['ids'] . '">' . $row['description'] . '</a>' ; ?></td>
    <? }else{?>
            <tr><td><? echo '<a href="viewpost.php?postID=' . $row['ids'] . '">' . $row['description'] . '</a>' ; ?></td>
    <? } ?>
        <?  
            if(preg_match('/[0-9]/',$row['timestamp'])){        
                list($yyyy,$dd,$mm) = explode('-',$row['timestamp']);
                        $newDate = $dd."-".$mm."-".$yyyy;
                }
            ?>
                <td><center><? echo $newDate; ?></center></td></tr>
            <?
            }
            echo '</table>';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following query that works well. SELECT DISTINCT city,region1,region2 from static_geo_world where
i've been using the following query: select LEN(columnname) as columnmame from dbo.amu_datastaging This works,
The following query works on Oracle 10.2.0.1.0 on windows,but doesn't work on Oracle 10.2.0.2.0
I have the following query. It works just fine but I need to pull
This has to be obtained from a remote machine. The following query works not
I am using following query which works fine for me except one problem SELECT
I have the following query which works: SELECT ?page ?lat ?long (bif:st_distance(?geo, bif:st_point(42.883, -72.8981)))
Lets say I have the following query. SELECT stringdata FROM table ORDER BY FIELDS(
I'm trying to get the following query to work in Hibernate: SELECT m FROM
I have an update query that shouldbe working but for some reason it doesnt

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.