Explicit type casts error in postgresql

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
kousalya
Forum Newbie
Posts: 4
Joined: Mon Feb 02, 2009 2:25 am

Explicit type casts error in postgresql

Post by kousalya »

Hi all...
can anyone help me in rectifying the below error
Warning:pg_query()[function.pg-query]:Query failed:ERROR:operator does not exist: character=integer LINE 1:...goryid,categoryname FROM category where categoryid=1 order by.... HINT: No operator matches the given name and argument type(s).You might need to add explicit type casts. in /var/www/exp1.php on line 48
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Explicit type casts error in postgresql

Post by VladSun »

It seems that your categoryid column is of type char - which I think is not good - you should redefine it as integer (long) by using ALTER TABLE.

Type casting in PGSQL is done in the form:
categoryid::integer=1
There are 10 types of people in this world, those who understand binary and those who don't
kousalya
Forum Newbie
Posts: 4
Joined: Mon Feb 02, 2009 2:25 am

Re: Explicit type casts error in postgresql

Post by kousalya »

Thanks a lot for your response,
I have three combo boxes, when i select a value in the first combo box, the second combo box should populate automatically and depending upon the second combo box the third should populate automatically.But i am getting the following error:

lay[0] = "rawmaterial"; cat[0] = [ "IC"scat[0] = [
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /opt/lampp/htdocs/combo.php on line 30
]; , "MOSFET"scat[0] = [
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /opt/lampp/htdocs/combo.php on line 30
]; ]; lay[1] = "Semi finished Product"; cat[1] = [];

Choose a layer

Choose a category

Choose a subcategory:

can u rectify my error in the following code..............

<?php
?>
<html>
<head>

<script language="JavaScript">
var lay = new Array();
var cat = new Array();
var scat = new Array();</script>
<?php

$con = mysql_connect("localhost","root","jairam") or die('Could not connect');
mysql_select_db("ERP");
$makes = mysql_query("SELECT * FROM layer");
$make_count = 0;
while($make_row = mysql_fetch_array($makes, MYSQL_ASSOC))
{
echo "lay[".$make_count."] = \"".$make_row["layername"]."\";\n";
$models = mysql_query("SELECT categoryname FROM category WHERE layerid=".$make_row["layerid"]);
$model_count = 0;
$num_models = mysql_num_rows($models);

echo "cat[".$make_count."] = [";
while($model_row = mysql_fetch_array($models, MYSQL_ASSOC))
{
echo " \"".$model_row["categoryname"]."\"";
$bittis = mysql_query("SELECT subcategoryname FROM subcategory WHERE categoryid=".$model_row["categoryid"]);
$bitti_count=0;
echo "scat[".$bitti_count."] = [";
while($bitti_row = mysql_fetch_array($bittis, MYSQL_ASSOC))
{
echo "\"".$bitti_row["subcategoryname"]."\"";
$bitti_count++;
}
echo "];\n";

$model_count++;
if($model_count < $num_models)
echo ", ";
}
echo "];\n";

$make_count++;
}

mysql_close($con);
?>
<script>
function populateMakes() {
var makeSel = document.getElementById("layername");
makeSel.length = 0;
for(var i=0; i<lay.length; i++) {
makeSel.options = new Option(lay, lay);
}
}

function doChangeOptions() {
var modelSel = document.getElementById("categoryname");
modelSel.length = 0;
var sel = document.getElementById("layername").selectedIndex;
alert(sel);
var currArr = cat[sel];
alert(currArr);
for(var i=0; i<currArr.length; i++) {
modelSel.options = new Option(currArr, currArr);
}

}

function doChangeOptions1() {
var bittiSel = document.getElementById("subcategoryname");
bittiSel.length = 0;
var sel = document.getElementById("categoryname").selectedIndex;
alert(sel);
var currArr = scat[sel];
alert(currArr);
for(var i=0; i<currArr.length; i++) {
bittiSel.options = new Option(currArr, currArr);
}

}

</script>
</head>
<body onload="populateMakes();doChangeOptions();doChangeOptions1();">
<P>Choose a layer
<select id="layername" onchange="doChangeOptions()">

</select>
</p>
<p>Choose a category
<select id="categoryname" onchange="doChangeOptions1()">

</select>
</p>
<p>Choose a subcategory:
<select id="subcategoryname">

</select>
</p>
</body>
</html>
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Explicit type casts error in postgresql

Post by Benjamin »

Please use [ code = php ] tags when posting code in the forums. You may edit your post and most likely get more responses.
Post Reply