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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:00:10+00:00 2026-06-02T21:00:10+00:00

I’m having trouble with some PHP since yesterday, looked through the web and had

  • 0

I’m having trouble with some PHP since yesterday, looked through the web and had the stupid feeling that I’m missing something important.

Using mysql_fetch_object usually, tried it with mysql_fetch_array though (did not help). Here’s the part of the code which gives me an headache:

public static function get_datacenter_by_id($id) {
$result = mysql_query("SELECT COUNT(rack.id) AS Racks, COUNT(device.id) AS Devices, COUNT(card.id) AS Cards, COUNT(port.id) AS Ports 
          FROM datacenter, rack, device, card, port, location, building 
          WHERE location.id = building.location_id AND
          building.id = datacenter.building_id AND
          datacenter.id = '.$id.' AND
          rack.id = device.rack_id AND
          device.id = card.device_id AND
          (card.id = port.card_id1 OR
          card.id = port.card_id2)") or die ("Error in query: ".mysql_error());

$array = array();

while($row = mysql_fetch_object($result)) {
    $array[] = array($row->Racks, $row->Devices, $row->Cards, $row->Ports);                     
}

return $array;
}

$array is used in another .php file, but using print_r $array already shows you, that the array stays empty (0). I’m quite sure that the error appears in this block of code, could “COUNT (x) AS y” be at fault?

PS: The MySQL Query works, tested it via Workbench before. I’d appreciate some good adivce! 🙂

Have a nice day!

  • 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-02T21:00:11+00:00Added an answer on June 2, 2026 at 9:00 pm

    Isn’t this as simple as:

    $result = mysql_query("SELECT COUNT(rack.id) AS Racks, COUNT(device.id) AS Devices,     COUNT(card.id) AS Cards, COUNT(port.id) AS Ports 
          FROM datacenter, rack, device, card, port, location, building 
          WHERE location.id = building.location_id AND
          building.id = datacenter.building_id AND
          datacenter.id = '" . $id . "' AND
          rack.id = device.rack_id AND
          device.id = card.device_id AND
          (card.id = port.card_id1 OR
          card.id = port.card_id2)") or die ("Error in query: ".mysql_error());
    

    Note the modification from ‘.$id.’ to ‘” . $id . “‘. Your query is looking for a data centre ID of ‘.$id.’.

    • 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
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm trying to create an if statement in PHP that prevents a single post
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

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.