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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:05:01+00:00 2026-06-01T12:05:01+00:00

I’m into networking so the data you see is switch/port information. The problem: I

  • 0

I’m into networking so the data you see is switch/port information.

The problem:

I only want the “ge-0/0/x” part of the SQL query and I want it sorted by “ge-0/0/x” and I only want to “select distinct” of the “ge-0/0/x” part(only 1 port, if you follow me).

As there are some dots on some results I’ve figured out that i could use rtrim to get rid of them. There are some dashes(-) in the result as well so any help to get rid of them as well is much appreciated.

PHP:

// "nodes" is the number of swithes, thus the ge-[node].
$host_name = 'switch_host_name';
$nodes = 2;
for($node=0;$node<$nodes;$node++){
    $ge = '%: ge-'.$node.'%';
    $portquery = mysql_query("SELECT service_description FROM service WHERE host_name='$host_name' AND service_description LIKE '$ge'") or die(mysql_error());
    while($portarray = mysql_fetch_array($portquery)){
        $port = substr($portarray['service_description'],8,10);
        echo '<div id="'.$port.'_'.$host_name.'">'.$port.'</div>';
    }
    echo '<br />';
}

SQL example:

+-------------------+----------------------------------+
| host_name         | service_description              |
+-------------------+----------------------------------+
| switch_host_name  | IF 151: ge-0/0/28.0 - Status     |
| switch_host_name  | IF 153: ge-0/0/29 - Status       |
| switch_host_name  | IF 155: ge-0/0/3 - Description   |
| switch_host_name  | IF 155: ge-0/0/3 - Status        |
| switch_host_name  | IF 155: ge-0/0/3.0 - Traffic     |
| switch_host_name  | IF 195: ge-0/0/5 - Description   |
| switch_host_name  | IF 195: ge-0/0/5 - Status        |
| switch_host_name  | IF 195: ge-0/0/5.0 - Traffic     |
+-------------------+----------------------------------+

Any clues, links, guides, tuts that you can point me to is much appreciated.
Of course a solution would be great!

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-06-01T12:05:02+00:00Added an answer on June 1, 2026 at 12:05 pm

    If you have MANY of these records, I’d suggest you massage the strings to extract the relevant portions into dedicated DB fields at the time you’re inserting the records into the DB. While I understand this is device config data, storing formatted data in a field negates the purpose of having a relational database, as you’re finding out. Doing sorting/filtering becomes very difficult.

    That being said, you can probably do some basic string manipulations in a query to extract your ge data:

    SELECT
        @start := LOCATE('ge-', service_description),
        @end := LOCATE(' - ', service_description),
        SUBSTR(service_description, @start, @end - @start) AS ge
    FROM ...
    GROUP BY ge
    ORDER BY ge
    

    This presumes that there’ll only be one ge- and one - string per record in that field.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
I want to construct a data frame in an Rcpp function, but when I
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.