Forum Moderators: coopster

Message Too Old, No Replies

PHP & HTML & SQL

         

malcolmcroucher

5:22 pm on Aug 28, 2008 (gmt 0)

10+ Year Member



I am pulling data from a database with a sql query .

Would the below code work if i close the php query or would it all need to be in one php query ?

e.g

<?php
include "dbaconnect.php" ;

$sql="SELECT * FROM country WHERE continentid='1'";
$result = mysql_query($sql);

while($rows = mysql_fetch_array( $result ))
{
if($rows == 0){
echo "No entries";
}
else{

while($row = mysql_fetch_array( $result ))

{

$continentid=$row["continentid"];
$countryid=$row["countryid"];
$cityid=$row["cityid"];
}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title></title>
<META NAME="keywords" CONTENT="">
<META NAME="description" CONTENT="">

<link rel="stylesheet" type="text/css" href="./css/home-font.css"/>
<link rel="stylesheet" type="text/css" href="./css/home.css" />
<link rel="stylesheet" type="text/css" href="./css/footer.css" />
</head>
<body>
<div id="banner"><h1><? echo $countryid ; ?></h1></div>
<div id="leftcontent">

StoutFiles

5:28 pm on Aug 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can open and close php queries wherever you want.

Ex:

<?php
if($number == 1)
{
?>

//html code

<?php
}
else
{
?>

//html code

<?php
}
?>

I think that's the question you're asking?

malcolmcroucher

5:32 pm on Aug 28, 2008 (gmt 0)

10+ Year Member



Thanks i found the problem , row was meant to be rows .... its working now

andrewsmd

12:45 pm on Aug 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just an FYI, you may want to look at PEAR for mysql. The syntax is much easier to code and it is much more powerful. You would want to look at DB.php within PEAR.