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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:38:31+00:00 2026-05-23T04:38:31+00:00

supposed a variable named $xlnum value is as this 20,4,56,987,68,96….. the variable $xlnum value

  • 0

supposed a variable named $xlnum value is as this 20,4,56,987,68,96.....the variable $xlnum value is input by the vistor.

the next i will passed the value to a sql query. if the value is one. that i can know how to do it. eg:

$result=mysql_query("select nid,title form node where nid=20");
while($row = mysql_fetch_object($result)) {
    echo $row->nid;
    echo $row->title;
}

but now the value is 20 4 56...,i want to loop out all the nid and title of 20,4,56,987,68,96.....how do i do.

  • 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-23T04:38:32+00:00Added an answer on May 23, 2026 at 4:38 am

    In short:

    $result = mysql_query("select nid,title form node where nid IN ($xlnum)");
    

    But you need to validate that it contains sane values.

    Assume $xlnum = '20,4,56,987,68,96'; in these examples. Both end up with $sql that you can pass to mysql_query.

    Option 1

    // remove white space
    $xlnum = preg_replace('/\s+/', '', $xlnum);
    
    // make sure the string is nothing but numbers separated by commas
    if (!preg_match('/^(\d+,)*\d+$/', $xlnum))
      die("invalid format");
    
    $sql = "select nid,title form node where nid IN ($xlnum)";
    

    Option 2

    $nids = array();
    // loop through each comma delimited value
    foreach (explode(',', $xlnum) as $nid)
    {
      // force the value to an integer
      $nid = (int) $nid;
    
      // if it is non-zero add it to the list
      if ($nid) $nids[] = $nid;
    }
    
    // if the array is empty, nothing valid was entered
    if (!$nids)
      die("invalid format");
    
    // recreate the comma delimited string 
    $xlnum = implode(',', $nids);
    
    $sql = "select nid,title form node where nid IN ($xlnum)";
    

    These are just two different ways to make sure the input is valid. The second is slightly different in that it will just ignore the pieces that are invalid.

    I prefer something more like the second since it’s easy to accidentally mess up a regular expression.

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

Sidebar

Related Questions

I am trying to echo a variable, from a mysql query, like this: <?php
Suppose that I have an integer variable in a class, and this variable may
I have a function that is supposed to take a variable number of arguments
I have this code that is supposed to load the attributes of an XML
I've got a named scope like this: named_scope :by_items, lambda |*items| { :joins =>
I think this isn't supposed to happen, but I can't find why this isn't
I'm starting with a csv variable of column names. This is then exploded into
Suppose I have a root controller MyViewController, with an instance variable named var1. I
I know that I'm not supposed to do this in C90, and it's a
I have a simple problem with the server global variable named : DOCUMENT_ROOT. Here's

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.