0

hello,

i want to show mysql query results into a table on a web page...but can i pass variable values from html tp php script i wanna show as it is important for my project

3
Contributors
9
Replies
29
Views
2 Years
Discussion Span
Last Post by mattster
0

You can pass HTML into PHP by submitting forms or using $_GET (ie. idx.php?var1=XYZ).

You would then do something along the lines of:

<table>

    <?php  
    foreach(...) {
        echo "<tr><td>".$row['col_name']."</td></tr>";
    } ?>

</table>

You need to tweak this snippet to work inline with your code.

0

my code is below not working:--

    <head>
        <title>Main Page</title>


    </head>

        <?php

        if($_POST["csv"])
        {
    $db=$_POST["db"];

$skills = explode(",", $_POST["skills"]);
$table = explode(",", $_POST["table"]);
$city = explode(",", $_POST["city"]);
$region = explode(",", $_POST["region"]);
$country = explode(",", $_POST["country"]);

$latitude=$_POST["lat"];
$longitude=$_POST["long"];

$distance=$_POST["dist"];

$latitude*=0.01745;
$longitude*=0.01745;
//print_r($skills);

$filename=  strtotime("now").".csv";

/* @var $table type */
$f="SELECT 'first','last','email' UNION";
$s=$f." select first,last,email from $table[0] where skills regexp \"$skills[0]\"";


for($i=1;$i<count($skills);$i++)
{
    $s.=" and skills regexp \"$skills[$i]\"";

    }
    $s.=" and deposit>=bid";

    for($i=0;$i<count($region);$i++)
if(!$region[$i]=="")
    {
    $s.=" and region regexp \"$region[$i]\"";

    }

    for($i=0;$i<count($city);$i++)
if(!$city[$i]=="")
    {
    $s.=" and city regexp \"$city[$i]\"";

    }


    for($i=0;$i<count($country);$i++)
if(!$country[$i]=="")
    {
    $s.=" and country regexp \"$country[$i]\"";

    }
    if(!$latitude=="")
    {

   $s.=" and acos(sin($latitude) * sin(Lati) + cos($latitude) * cos(Lati) * cos(Longi - ($longitude))) * 6371 <= $distance";
    }


    $s.=" INTO OUTFILE '/var/tmp/$filename'
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\\n';";



    $con=mysqli_connect("localhost","root","cutiepie_100",$db);
    if (mysqli_connect_errno()) 
        {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//print_r($s);
$abc=mysqli_query($con, $s) or die('cannot show tables');
echo $filename;
        }

        else if ($_POST["update"])
        {
             $db=$_POST["db"];
$skills = explode(",", $_POST["skills"]);
$table = explode(",", $_POST["table"]);
$city = explode(",", $_POST["city"]);
$region = explode(",", $_POST["region"]);
$country = explode(",", $_POST["country"]);

$latitude=$_POST["lat"];
$longitude=$_POST["long"];

$distance=$_POST["dist"];

$latitude*=0.01745;
$longitude*=0.01745;
//print_r($skills);



/* @var $table type */
$s="update $table[0] set deposit=deposit-bid where skills regexp \"$skills[0]\"";

$s.=" and deposit>=bid";
for($i=1;$i<count($skills);$i++)
{
    $s.=" and skills regexp \"$skills[$i]\"";

    }

    for($i=0;$i<count($region);$i++)
if(!$region[$i]=="")
    {
    $s.=" and region regexp \"$region[$i]\"";

    }

    for($i=0;$i<count($city);$i++)
if(!$city[$i]=="")
    {
    $s.=" and city regexp \"$city[$i]\"";

    }


    for($i=0;$i<count($country);$i++)
if(!$country[$i]=="")
    {
    $s.=" and country regexp \"$country[$i]\"";

    }
    if(!$latitude=="")
    {

   $s.=" and acos(sin($latitude) * sin(Lati) + cos($latitude) * cos(Lati) * cos(Longi - ($longitude))) * 6371 <= $distance;";
    }
    $s.=";";

     print_r($s);

    $con=mysqli_connect("localhost","root","cutiepie_100",$db);
    if (mysqli_connect_errno()) 
        {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$abc=mysqli_query($con, $s) or die('cannot show tables');

        }

 else if ($_POST["deposit"])
        {
            $db1=$_POST["db1"];
            $sno=$_POST["sno"];
            $amount=$_POST["amount"];
            $t=$_POST["table1"];

            $f="update $t set deposit=deposit+$amount where sno=$sno;";
            print_r($f);            

            $con=mysqli_connect("localhost","root","cutiepie_100",$db1);
    if (mysqli_connect_errno()) 
        {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$abc=mysqli_query($con, $f) or die('cannot show tables');

        }
 else if($_POST["results"])
        {

             $db=$_POST["db"];

$skills = explode(",", $_POST["skills"]);
$table = explode(",", $_POST["table"]);
$city = explode(",", $_POST["city"]);
$region = explode(",", $_POST["region"]);
$country = explode(",", $_POST["country"]);

$latitude=$_POST["lat"];
$longitude=$_POST["long"];

$distance=$_POST["dist"];

$latitude*=0.01745;
$longitude*=0.01745;



$s="select sno from $table[0] where skills regexp \"$skills[0]\"";


for($i=1;$i<count($skills);$i++)
{
    $s.=" and skills regexp \"$skills[$i]\"";

    }
    $s.=" and deposit>=bid";

    for($i=0;$i<count($region);$i++)
if(!$region[$i]=="")
    {
    $s.=" and region regexp \"$region[$i]\"";

    }

    for($i=0;$i<count($city);$i++)
if(!$city[$i]=="")
    {
    $s.=" and city regexp \"$city[$i]\"";

    }


    for($i=0;$i<count($country);$i++)
if(!$country[$i]=="")
    {
    $s.=" and country regexp \"$country[$i]\"";

    }
    if(!$latitude=="")
    {

   $s.=" and acos(sin($latitude) * sin(Lati) + cos($latitude) * cos(Lati) * cos(Longi - ($longitude))) * 6371 <= $distance";
    }
    $s.=";";



    $con=mysqli_connect("localhost","root","cutiepie_100",$db);
    if (mysqli_connect_errno()) 
        {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//print_r($s);
$abc=mysqli_query($con, $s) or die('cannot show tables');

while ($row = mysql_fetch_row($abc))
{
 echo "<tr>";
  echo "<td>" . $row['sno'] . "</td>";
   echo "</tr>";
} 
echo "</table>";
        }   
  ?>
0

Why didn't you post your code streight away?

my code is below not working

'Not working' can mean alot of things. How is it not working? Any error messages? Explain what bits you know work and the areas you think the problem are.

Firstly you need a <body> tag, and a <html> tag if you haven't already got one. You need to open the <table> tag as well.

0

actually;
in post(results)i'm showing the data out from mysql onto webpage...in the above complete code

while ($row = mysql_fetch_row($abc))
{
echo "<tr>";
echo "<td>" . $row['sno'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
?>

this code does not show anything on page....else it has to show output from mysql in tabular form

0

i mean can i access php variables after closing up

<?php
$a=10?>

echo $a;

??

0

after closing up

Yes, if you reopen:

<?php
    $a = "XYZ";
?>
<html>
<body>

<?php
    echo $a;
?>

</body>
</html>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.