Jump to content

Starting new php functions


misfitxnet

Recommended Posts

If i am writing a script in which I connect to a database and define some elements

such as

<?php

$connect=mysql_connect('host', 'username', 'password');

$db=mysql_select_db('db');

if($!db){

exit(mysql_error)

}

if($!connect){

exit(mysql_error)

}

$sql="SELECT * FROM table ORDER by id DESC";

 

?>

 

then I write some HTML,

and then create a new part of the the page which will display the sql data in a table.

 

<?php

while ($row=mysql_fetch_array($sql)){

 

<tr>

<td>

<? echo $row['name']; ?>

</td>

</tr>

?>

 

and this does not work...

however, a "while ($row=mysql_fetch_array($sql)){  echo $row['name'];" in the first part works.

 

My question is... what is the syntax regarding where a new <?php section must begin???

When won't php recognize HTML and vice versa????

Link to comment
https://forums.phpfreaks.com/topic/163082-starting-new-php-functions/
Share on other sites

<?php
$connect=mysql_connect('host', 'username', 'password');
$db=mysql_select_db('db');
if($!db){
exit(mysql_error)
}
if($!connect){
exit(mysql_error)
}
$sql="SELECT * FROM table ORDER by id DESC";

?>

then I write some HTML,
and then create a new part of the the page which will display the sql data in a table.

<?php 
while ($row=mysql_fetch_array($sql))
{

// break out of PHP tags to output some html
?>
<tr>
<td>


<?php
// add the dynamic content
echo $row['name'] . "\n";
?>

</td>
</tr>

<?php // close brace
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.