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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:43:50+00:00 2026-05-27T04:43:50+00:00

I told Sphinx to index some strings in their CRC32 forms as attributes, like

  • 0

I told Sphinx to index some strings in their CRC32 forms as attributes, like so:

sql_query = SELECT [...], CRC32(LOWER(color)) AS color, [...], FROM table

sql_attr_uint = color

I’m trying to get some faceted search going in PHP, where users can click on a link with one of the above colors and Sphinx would get another search request going with narrowed down results, something like:

Previous page:
<h3>Narrow down results:</h3>
<p><a href="search.php?query=something&color=1678454">Red (11)</a></p>
<p><a href="search.php?query=something&color=4133605867">Yellow (5)</a></p>

<?php
    if (isset($_GET[$name]))
    {
        $sphinx->SetFilter('color', intval($_GET['color']));  // <-- Uh-oh
    }

    [...]

    $sphinx->Query($query, 'table');
?>

Things goes wrong here because MySQL’s CRC32() returns an unsigned 32-bit integer, which PHP very helpfully does not support and caps at 2^31-1. The above link for the color Yellow exposes my problem.

StackOverflow, what may be an acceptable workaround for this? I suppose doing some math on the SQL query side is possible, but I’m wary of making the worrying chance of collision even worse.

Thanks in advance.

  • 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-27T04:43:50+00:00Added an answer on May 27, 2026 at 4:43 am

    Quoting from PHP’s crc32() manual page:

    Because PHP’s integer type is signed, and many crc32 checksums will
    result in negative integers, you need to use the “%u” formatter of
    sprintf() or printf() to get the string representation of the unsigned
    crc32 checksum.

    In other words, PHP cannot handle large integers but in this precise case you can emulate unsigned integers to double precision. You can get the real value when casting to string.

    This should be enough since you don’t need to do mathematical operations, such as addition or multiplication.


    Update: I guess I’ve just ignored the vital part of your question. Rather than this:

    intval($_GET['color'])
    

    … you can validate or filter with a regular expression:

    preg_match('/^\d+$/', $_GET['color'])
    preg_replace('[^\d]', '', $_GET['color'])
    

    … and handle the CRC value as string.

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

Sidebar

Related Questions

Someone told me about a C++ style difference in their team. I have my
Someone told me that it's faster to concatenate strings with StringBuilder. I have changed
I've always been told that adding an element to an array happens like this:
Somebody told me that example.com/en is more friendly than example.com/index.php?lang=en . How can I
I have been told, AppKit controls don't take kindly to being updated from threads
I was told that Microsoft has released reference source code for some .NET libraries
Told by my boss to use Moq and that is it. I like it
I've been told by my hosting company that Python is installed on their servers.
Someone told me about swamp diagrams explaning that they were useful to predict code
Someone told me that openGL is for graphic only, and that it's very bad

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.