4

i am trying to display mysql data in html

table format is

table name:: App

   appid |    app    | version |     date     |      apk file   |
   1        sample     1.0.0      2012-10-12         sample.apk

//mysql query is

   <?php
    $query="SELECT * FROM `App` where appid=1";
    $res=mysql_query($query);
    $row=mysql_fetch_row($res);
    $app=$row[1];
    $vesion=$row[2];
    $date1=date('M j,Y',strtotime($row[3]));
 ?>

//html code is given below

 <html>
     <body>
      <div style="text-align:left"><p>App:<b><? $app.' '.$vesion ?></b></p></div>
      <div style="text-align:left"><p>Date Uploaded: <b><? $date1 ?></b></p></div>
      <ol class="instructions">
         <li>Click <a href="http://localhost/downloads/$row[4]">Here</a> todownload.
 <br></li>

     </ol>
     </body>
     </html>
<?php 

?>

but do not getting mysql data in html file

any one help me for correct solution

3 Answers 3

4

Ok so two things may be happening here.

  1. You need to wrap any PHP code with the opening and closing PHP tags - <?php ?>. This includes single variables like you did with row[4]. You'll also need to echo out the variable -

    <a href="http://localhost/downloads/<?php echo $row[4]; ?>">Here</a>

  2. Make sure you HTML file has the .php file extension. Other wise the server will simply not parse the file as PHP and your code will not be executed as PHP but rather as plain text. You can setup your server to parse PHP even in HTML files - this is done sometimes for security measures as to not let users know what technologies are being used on the server (but I'm not sure if that's what you are going for here).

Sign up to request clarification or add additional context in comments.

Comments

4

You can print the value of the variables out like so:

<div style="text-align:left"><p>App:<b><? echo $app . ' ' . $vesion ?></b></p></div>

1 Comment

Need to note here the settings related to the short_open_tag. Not all setups support this by default.
1

Yeah. You missed the echo And try this:

<?php
$query="SELECT * FROM `App` where appid=1";
$res=mysql_query($query);
$row=mysql_fetch_array($res);
$app=$row['app'];
$vesion=$row['version'];
?>
<a href="http://localhost/downloads/<?=$row['apk file']?>">Here</a>

Use var_dump to test what you get from DB.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.