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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:02:48+00:00 2026-05-23T23:02:48+00:00

I made a search.php that finds articles on my site. What I was trying

  • 0

I made a search.php that finds articles on my site. What I was trying to do was create a voting system that would sort the articles by how many up votes it has. But the articles are in one table and the votes are in another. So what I needed was a foreign key that would be in the voting table that would tell the article table how many up votes it has so search.php would sort accordingly

My question was, how would I set up a foreign key that would handle that?
I just dont know how to set up the foreign key in the article table and the voting table

  • 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-23T23:02:49+00:00Added an answer on May 23, 2026 at 11:02 pm

    And why don’t you just update your artices’s vote count along when inserting a row to votes table?

    You can use it like

    <?php
    //vote.php
    require 'db.php';
    if (mysql_num_rows(mysql_query("SELECT id FROM votes WHERE article_id = '".intval($_GET['aid'])."' AND ip = '".$_SERVER['REMOTE_ADDR']."'")) {
        die("Already voted");
    }
    
    mysql_query("INSERT INTO votes (id, ip, article_id) VALUES ('', '".$_SERVER['REMOTE_ADDR']."', '".$_GET['aid']."')");
    mysql_query("UPDATE articles SET votes = votes ".($_GET['vote'] == "up" ? "+ 1" : "- 1")." WHERE article = '".intval($_GET['aid'])."'");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made a search system for my website. Let's say there are 5 datas
I have created a search feature for a site and in addition I made
I'm trying to implement a search box using php and jquery (the seach results
I made a simple ajax live search in PHP and javascript. I used standard
based on How to implement tagging system similar to SO in php/mysql? ive made
I'm working on a PHP search script that scans a text file repository of
I made a PHP page that looks up Constant Contact e-mail addresses in a
I'm trying to pass multiple checkboxes with different values to a PHP script that
I've made jQuery & AJAX script that uses a PHP function to bring back
I have a Google Instant style jQuery search script that queries a PHP file

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.