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

  • Home
  • SEARCH
  • 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 7188235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:01:47+00:00 2026-05-28T19:01:47+00:00

Okay so the title may be a bit misleading. What I am trying to

  • 0

Okay so the title may be a bit misleading. What I am trying to do is add a favorite system to my site. I have one column for my favorite things and I set it up so after each item ID there is a :. How can I check the string returned from my database (1345:13456:232:524378:324) if it contains 232? If it does I would echo preRend else I would echo insert and insert that ID followed by a :. This is what I have so far:

<?php
session_start();
require_once(".conf.php");
$logged = $_SESSION['logged'];
$user = $_SESSION['user'];
$fwdfav = $_POST['id'];
$query = mysql_query("SELECT * FROM accountController WHERE user='$user'");

if ($logged == 1) 
{
    while ($row = mysql_fetch_array($query)) {
    if ($row['fav-itms'] //This is where I got stuck. How to check if it contains a value.)
        {
            mysql_query("INSERT INTO accountController ('fav-itms') VALUES ('$fwdfav')");
            echo 'inserted';
        }
        else
        {
            echo 'preRend';
        }

    }
} 
else
{
    echo 'nlog';
}
?>

Thank you so much! I am sure there are a lot of errors here as I am very tired.

  • 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-28T19:01:48+00:00Added an answer on May 28, 2026 at 7:01 pm

    The approach you are taking is extremely inefficient and does not take advantage of the fact that you are using a database.

    (Btw… I hope this is just example code; you have a giant SQL injection vulnerability in your INSERT query.)

    What I would do instead is create a second table that would look something like:

    favorites (
        id int(11) NOT NULL auto_increment,
        user_id int(11),
        fav_id int(11)
    )
    

    And have each row represent a user-favorite pair. Then you can let MySQL do the heavy lifting of figuring out whether a user has favorited something, e.g.,

    SELECT COUNT(*) FROM favorites WHERE user_id = %d AND fav_id = %d;
    // Substitute the actual look-up values in using prepared statements
    

    You could also similarly quickly get the actual favorites for a user, etc.

    Remember, a database is designed for the explicit purpose of storing and looking up information quickly. PHP is a general-purpose programming language. Where possible, let MySQL do the walking for you.

    (This advice is general for a moderately scaled setup. If you need to handle millions of simultaneous users, far more optimization is obviously required, and conventional relational databases might not even be suitable. But I don’t get the impression that’s where you’re at right now.)

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

Sidebar

Related Questions

Okay, the Title is a bit vague, but what I'm trying to do is
Okay the question title may not have made sense... mostly because I don't know
Okay the title may not justify what I'm trying to do here but dont
Okay so i have this code: if (isset($_GET['book'])) { $query= SELECT book_id, title, authors.`author`
okay, i'm setting up a multi-user chat system. i have a messages table, that
Okay, this may seem silly, but on an ASP.NET .ascx control, I'm trying to
Okay, the title of the question kind of suggests one solution I've been considering
Hard to think of a title for this one! I have a bean that
okay, my problem is a little bit more difficult than the title would tell...
Okay, I've set up a bit of code which searching for all the pages

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.