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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:03:32+00:00 2026-06-05T08:03:32+00:00

I have a PHP script with which I want to read servers from database

  • 0

I have a PHP script with which I want to read servers from database and connect to them with cURL. Servers responds with results from sql query. The problem is that script after each respond from server displays number 1. The ouput looks like this:

Server 1: some results

1Server 2: some results

1Server 3: some results

1

Here is the code that reads servers from database and connects to them:

<?php

$mysql_id = mysql_connect('localhost', 'ms', 'pass');
mysql_select_db('servers', $mysql_id);
mysql_query("SET NAMES utf8");

$query = "SELECT * FROM svr";
$result = mysql_query($query);
$num = mysql_num_rows($result);
while ($data = mysql_fetch_assoc($result))
{
    $server[] = $data;
}

mysql_close($mysql_id);

$i = 0;
while($i < $num) {
    $dealer = $server[$i]['dealer'];

    echo $dealer . "<br />";

    $data = "val=a"; //just for testing                                                                    

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);    
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                                                                                                       
        'Content-Type: text/html; charset=utf-8')                                                                       
    );                                                                                                                                                                                   

    $result = curl_exec($ch);
    echo $result;
    $i++;
}

?>

I discovered that 1 is displayed with “echo $result;” and the code for creating response is this:

<?php

$mysql_id1 = mysql_connect('localhost', 'ms', 'pass');
mysql_select_db('servers', $mysql_id1);
mysql_query("SET NAMES utf8");

    $query2 = "SELECT * FROM data";
    $result2 = mysql_query($query2);
    $num2 = mysql_num_rows($result2);
    while ($data2 = mysql_fetch_assoc($result2))
    {
        $deli[] = $data2;
    }
    $i1 = 0;
    $space = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
    while ($i1 < $num2) {
        echo $space . $deli[$i1]['id'] . " ";
        echo $deli[$i1]['artikel'] . " ";
        echo $deli[$i1]['znamka'] . " ";
        echo $deli[$i1]['model'] . " ";
        echo $deli[$i1]['letnik'] . " ";
        echo $deli[$i1]['cena'] . " € ";
        echo $deli[$i1]['zaloga'] . "<br />";
        $i1++;
    }
    echo "<br />";
    mysql_close($mysql_id1);
?>

Please help me

  • 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-05T08:03:38+00:00Added an answer on June 5, 2026 at 8:03 am

    Use the CURLOPT_RETURNTRANSFER option. Otherwise cURL will automatically echo the data and just return true (which is converted to 1 by echo).

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    

    PHP.net says,

    TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it directly.

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

Sidebar

Related Questions

Here I have a simple php script which displays some values from a database
I have this PHP script which i'm grabbing images from a directory and displaying
I have written a PHP script which generates an SQL file containing all tables
i have a database in MySQL who i query from a php script. Now
I have a PHP script which downloads files to the client, in a new
I have a PHP script which checks on a _SESSION variable (upon creating a
I have a php script which saves the original image, then resizes it -
I have a PHP script which creates and listens on a port for connections
I have a PHP script which is generating buttons to each content schedule. The
I have a PHP search script which I've altered slightly and works well for

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.