How to pull database information into a php code

Asked

Viewed 1,649 times

0

Hello, I have a code in PHP, and inside it I would like to pull information.

@$host = "23.98.102.87";
@$port = "9498";

Where has the number s is where I wanted to pull the data, I’ve already made the select, but I wonder, how I could pull information from the database within a php. For example, I have a database, where you already have this IP and number, and I wanted it to come from there, not that I change manually.

Well, I have a huge code, and it makes mistakes using the echo.

Code:

<?php
$id = $_GET['id'];
$radios1_3 = mysql_query("SELECT * FROM radios ORDER BY id DESC LIMIT 300") or die(mysql_error());
$linha = mysql_fetch_array($radios1_3);
echo "
@$host = " . $linha["sc"] . ";
@$port = " . $linha["sc2"] . ";
@$listenlink = 'http://23.238.135.80:9998/listen.pls';  //make link to stream
@$fp = fsockopen($host, $port); //open connection
if(!$fp) {
@$success=2;  //se-t if no connection
}
if(@$success!=2){ //if connection
@fputs($fp,"GET /index.html HTTP/1.0\r\nUser-Agent: XML Getter (Mozilla Compatible)\r\n\r\n"); //get 7.html
while(!feof($fp)) {
@$pg .= fgets($fp, 1000);
}
@fclose($fp); //close connection
@$paage = ereg_replace(".*<font class=default>Stream Title: </font></td><td><font class=default><b>", "", $pg); //extract data
@$paage = ereg_replace("</b></td></tr><tr><td width=100 nowrap>.*", "", $paage); //extract data
@$pge = ereg_replace(".*<font class=default>Stream Genre: </font></td><td><font class=default><b>", "", $pg); //extract data
@$pge = ereg_replace("</b></td></tr><tr><td width=100 nowrap>.*", "", $pge); //extract data
@$pe = ereg_replace(".*<font class=default>Stream Genre: </font></td><td><font class=default><b>", "", $pg); //extract data
@$pe = ereg_replace("</b></td></tr><tr><td width=100 nowrap>.*", "", $pe); //extract data
@$musica = ereg_replace(".*com:<font class=default>Current Song: </font></td><td><font class=default><b>", "", $pg); //extract data
@$musica = ereg_replace("</b></td></tr></table>.*", "", $musica); //extract data
@$numbers = explode(",",$paage); //extract data
@$servertitle=$numbers[0]; //set variable
@$connected=$numbers[4]; //set variable
}
@$fp2 = fsockopen("$host", $port); //open connection
if(!$fp2) {
@$success2=2;  //se-t if no connection
}
if(@$success2!=2){ //if connection
fputs($fp2,"GET /7.html HTTP/1.0\r\nUser-Agent: XML Getter (Mozilla Compatible)\r\n\r\n"); //get 7.html
while(!feof($fp2)) {
@$pg2 .= fgets($fp2, 1000);
}
fclose($fp2); //close connection
@$pag = ereg_replace(".*<body>", "", $pg2); //extract data
@$pag = ereg_replace("</body>.*", ",", $pag); //extract data
@$numbers = explode(",",$pag); //extract data
$currentlisteners=$numbers[0]; //set variable
}
// ATUALIZADOR
if(@$_GET['ver'] == "dj"){
echo"$paage";
}
if(@$_GET['ver'] == "ouvintes"){
echo $currentlisteners;
}
if(@$_GET['ver'] == "musica"){
echo "$musica";
}
if(@$_GET['ver'] == "programa"){
echo"$pge";
}
if(@$_GET['ver'] == "imgloc"){
echo'<div id="boneco" style="background:url(https://www.habbo.com.br/habbo-imaging/avatarimage?img_format=gif&user='.$paage.'&action=std&direction=2&head_direction=2&gesture=spk&size=b);"></div>';
}
";
// ATUALIZADOR
?>
  • What error appears? or what does not happen?

  • http://prntscr.com/7lrnbi

  • Only this error appears? Which is the line 14, could evidence it.

  • Yeah, when I erase the line from that bug, it’s still on the same line, even the underside replacing.

  • pq needs the echo, precise separates instructions from text output.

2 answers

1

The modifications I suggest are, remove echo and its closure

$linha = mysql_fetch_array($radios1_3);
echo "

//Muito código depois...

if(@$_GET['ver'] == "imgloc"){
echo'<div id="boneco" style="background:url(https://www.habbo.com.br/habbo-imaging/avatarimage?img_format=gif&user='.$paage.'&action=std&direction=2&head_direction=2&gesture=spk&size=b);"></div>';
}
"; //<---- Fim do echo 

Remove all the @ because they hide the errors/Warning they must be treated, sometimes only isset already resolves.

If you only take the first record, you can leave the limit at 1 instead of 300

$radios1_3 = mysql_query("SELECT * FROM radios ORDER BY id DESC LIMIT 300") or die(mysql_error());
$linha = mysql_fetch_array($radios1_3);

All modifications:

    $id = $_GET['id'];
    $radios1_3 = mysql_query("SELECT * FROM radios ORDER BY id DESC LIMIT 1") or die(mysql_error());
    $linha = mysql_fetch_array($radios1_3);
    $host =  $linha["sc"];
    $port =  $linha["sc2"];
    $listenlink = 'http://23.238.135.80:9998/listen.pls';  //make link to stream
    $fp = fsockopen($host, $port); //open connection
    if(!$fp) {
        $success=2;  //se-t if no connection
    }

    if($success!=2){ //if connection
        fputs($fp,"GET /index.html HTTP/1.0\r\nUser-Agent: XML Getter (Mozilla Compatible)\r\n\r\n"); //get 7.html
        while(!feof($fp)) {
            $pg .= fgets($fp, 1000);
        }
        fclose($fp); //close connection
        $paage = ereg_replace(".*<font class=default>Stream Title: </font></td><td><font class=default><b>", "", $pg);
        $paage = ereg_replace("</b></td></tr><tr><td width=100 nowrap>.*", "", $paage);
        $pge = ereg_replace(".*<font class=default>Stream Genre: </font></td><td><font class=default><b>", "", $pg);
        $pge = ereg_replace("</b></td></tr><tr><td width=100 nowrap>.*", "", $pge);
        $pe = ereg_replace(".*<font class=default>Stream Genre: </font></td><td><font class=default><b>", "", $pg);
        $pe = ereg_replace("</b></td></tr><tr><td width=100 nowrap>.*", "", $pe);
        $musica = ereg_replace(".*com:<font class=default>Current Song: </font></td><td><font class=default><b>", "", $pg);
        $musica = ereg_replace("</b></td></tr></table>.*", "", $musica);
        $numbers = explode(",",$paage); //extract data
        $servertitle=$numbers[0]; //set variable
        $connected=$numbers[4]; //set variable
    }

    $fp2 = fsockopen("$host", $port); //open connection
    if(!$fp2) {
        $success2=2;  //se-t if no connection
    }

    if($success2!=2){ //if connection
        fputs($fp2,"GET /7.html HTTP/1.0\r\nUser-Agent: XML Getter (Mozilla Compatible)\r\n\r\n"); //get 7.html
        while(!feof($fp2)) {
            $pg2 .= fgets($fp2, 1000);
        }
        fclose($fp2); //close connection
        $pag = ereg_replace(".*<body>", "", $pg2);
        $pag = ereg_replace("</body>.*", ",", $pag);
        $numbers = explode(",",$pag);
        $currentlisteners=$numbers[0];
    }
    // ATUALIZADOR
    if(isset($_GET['ver'])){
        if($_GET['ver'] == "dj"){
            echo $paage;
        }

        if($_GET['ver'] == "ouvintes"){
            echo $currentlisteners;
        }

        if($_GET['ver'] == "musica"){
            echo $musica;
        }

        if($_GET['ver'] == "programa"){
            echo $pge;
        }

        if($_GET['ver'] == "imgloc"){
            echo'<div id="boneco" style="background:url(https://www.habbo.com.br/habbo-imaging/avatarimage?img_format=gif&user='.$paage.'&action=std&direction=2&head_direction=2&gesture=spk&size=b);"></div>';
        }
    }   
    // ATUALIZADOR
    ?>

0

If you already have select, just do the following:

$linha = mysql_fetch_array($seu_select);
echo "@$host = " . $linha["ip"] . "; @$port = " . $linha["porta"];

Assuming you’re using mysql_query, not PDO or Mysqli, if you’re using either, tell me.

  • Hi, you’re making a mistake with the echo, there was no error in the part of pulling the data, but in another thing gave, could you help me to solve? I posted the code in the edition of my question. Thank you.

  • You need to fix your echo. Notice that it is used with double quotes, so you cannot put another double quotes inside it. For this you would have to use 'escape' (backslash) character before the quotes you want to print.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.