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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:15:01+00:00 2026-06-18T00:15:01+00:00

I am having a small trouble retrieving results that I hope someone can help

  • 0

I am having a small trouble retrieving results that I hope someone can help me with.

I have a field called $incategory which is a comma based string, and what I want to do is explode the into an array that can be used to retrieve results as below (Hope that makes sense):

<?php 

$showlist = $row_listelements['incategory']; 

// ** e.g. $incategory = 1,3,5, 
// ** What I want to do is look at table 'category' 
// ** and retrieve results with an 'id' of either 1, 3 or 5

// ** Display Results
mysql_select_db($database_db, $db);
$query_display = "SELECT * FROM category WHERE id = ".$showlist." ORDER BY name ASC";
$display = mysql_query($query_display, $db) or die(mysql_error());
$row_display = mysql_fetch_assoc($display);
$totalRows_display = mysql_num_rows($display);

?>
  • 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-18T00:15:02+00:00Added an answer on June 18, 2026 at 12:15 am

    You can use the IN keyword of SQL directly like this.

    query_display = "SELECT * FROM category WHERE id IN (".$showlist.") ORDER BY name ASC";
    

    Another tip would be to stop using MYSQL_QUERY as it is deprecated in PHP 5.3

    Edit: If $showlist = ‘1,3,5,’ you will need to remove the last comma from the string to make it useable in the query. Just use this query then

    query_display = "SELECT * FROM category WHERE id IN ('".str_replace(",", "','", substr($showlist, -1))."') ORDER BY name ASC";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a small trouble with ASP.net. I have a small DataTable that i
I'm having trouble with javascript's oop. I have a small code snippet which is
I have a small class hierarchy that I'm having trouble implementing copyWithZone: for. I've
I have a small task in Flash, that I'm having a little trouble with.
I've been working on a small blog form but have been having trouble with
I am having trouble correctly modeling related objects that can use templates. This is
I am having trouble with IE7. I have a header, which is an IMG.
I'm having a bit of trouble with a small Javascript library that I am
I'm coming from Java/C++ to Ada and am having trouble figuring out the small
Im having a small problem with my code. I have been trying to read

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.