Forum Moderators: coopster
".......Got paintings for this category!";
but then I get:
"data cannot be retrived from the resultset";
Please tell me why I cant display the values in $result.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Gallery</title>
<link rel="stylesheet" type="text/css" href="css/common.css">
<link href="vista_toolbar/style.css" media="all" rel="stylesheet"
type="text/css" />
<style type="text/css">
<!--
body {
background-image: url(images/back.jpg);
background-color: #F0E3C1;
background-repeat: repeat-x;
}
-->
</style></head>
<body class="twoColFixRtHdr">
<br>
<div id="container">
<div><?php @include_once("main.php");?></div>
<div id="mainContent">
<?php
global $gname;
global $result;
$gname= $_GET['x'] ;
echo"the category is............... $gname";
$db_host = 'localhost';
$db_user = 'root';
$db_pwd = 'dba';
$database = 'gallery';
$table = 'paintings';
if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database");
if (!mysql_select_db($database)) die("Can't select database");
$result=mysql_query("select p_painting_artistid from paintings where p_painting_categoryid='$gname1'") or die("MYSQL Returned: " . mysql_error());
if($result==false)
{
echo "Sorry there aren't any available paintings for this category";
}
else
{
echo ".......Got paintings for this category!";
}
?>
</div>
<br class="clearfloat" />
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="150" height="265" align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="30" align="center" valign="middle" bgcolor="#CCCCCC"><strong>Artists</strong></td>
</tr>
<?php
//just to check whether I can retrive data from the $result
if(!mysql_fetch_assoc($result))
{
echo "data cannot be retrived from the resultset";
}
else
{
echo "data can be retrived from the result set";
}
?>
<?php
while($row = mysql_fetch_assoc($result))
{
?>
blabla
<tr>
<td><a href="artist.php">Artist <?php echo $row['p_painting_artistid'] ?></a></td>
</tr>
<?php } ?>
<?php @include_once("ui_footer.php");?>
</body>
</html>
Also, don't forget that
$gname1 might contain potentially harmfull syntax so you should always escape these query variables with mysql_real_escape_string [php.net] for safety.