SitePoint Sponsor |
|
User Tag List
Results 1 to 10 of 10
-
Apr 7, 2009, 20:22 #1
- Join Date
- Jan 2005
- Location
- Montreal
- Posts
- 18
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
MySQL returned an empty result set
I have a really big problem and can't get the solution in the forums I visited.
CREATE TABLE price(
`id` INT( 3 ) NOT NULL DEFAULT '0',
`fig_id` INT( 3 ) NOT NULL DEFAULT '0',
`dim_id` INT( 3 ) NOT NULL DEFAULT '0',
`dim` VARCHAR( 20 ) NOT NULL DEFAULT '0',
`fig` INT( 3 ) NOT NULL DEFAULT '0',
`price` DECIMAL( 10, 2 ) DEFAULT '0.00',
KEY `price_idx` ( `fig` , `dim` ) ,
PRIMARY KEY ( `id` )
) ENGINE = MYISAM ;# MySQL returned an empty result set (i.e. zero rows).
The problem is that I can't test the program because the aabove error.
Some help, please.
-
Apr 7, 2009, 20:29 #2
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
where did you get this error message? because there's nothing wrong with that CREATE TABLE statement
(other than the funny dimensions on the INT columns and the incorrect quotes on numeric constants)
-
Apr 7, 2009, 20:34 #3
Have you tried creating it using PHPMyadmin?
-
Apr 7, 2009, 21:12 #4
- Join Date
- Jan 2005
- Location
- Montreal
- Posts
- 18
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi,
Tha's the problem
I use MySql 3.23.58 and PhpMyAdmin 2.6.0-pl3.
Are there other ways todo that. Or is it best to ignore this warning?
-
Apr 7, 2009, 21:16 #5
- Join Date
- Jan 2005
- Location
- Montreal
- Posts
- 18
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Is it best to ignre this warning.
Anyway, Im going to change the 'funny value and bad quotes.
Tanks for your fast answer.
E. P.
-
Apr 8, 2009, 02:41 #6
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
where are you running the CREATE TABLE statement, in phpmyadmin?
-
Apr 8, 2009, 05:44 #7
- Join Date
- Jan 2005
- Location
- Montreal
- Posts
- 18
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
SQL-->Choose File
Compression: Auto
Character set: utf8
-
Apr 8, 2009, 09:39 #8
- Join Date
- Jan 2005
- Location
- Montreal
- Posts
- 18
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Besides the "empty rows" issue, I have another problem:
'dim' and 'fig' are 2 dropdown lists which value determine a given price.
Ajax/MySql/PhP/ are used for this purpose. (see details in attachment).
By clicking on "Submit" we have a "not available" result instead of the hoped price.
I don't see really what is really wrong.
Firstly, I think that the "empty_row" was responsible of this situation.
Some help, please.
E. P.
-
Apr 8, 2009, 09:42 #9
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
to save people from opening your word document, here it is in plain text --
2 dropdown
….
<script src="prototype.js" type="text/javascript"></script>
<script src="myAjax.js" type="text/javascript"></script>
</head>
<body>
<form>
<select id="fig" onchange="calc_price();return false;">
<option value = "" selected="selected">Nombre de figures sur la peinture</option>
<option value = "1">1</option>
<option value = "2">2</option>
<option value = "3">3</option>
…
<option value = "10">10</option>
</select>
<select id="dim" onchange="calc_price();return false;">
<option value = "" selected="selected">Dimensions choisies</option>
<option value = "field1">12inx16in/30cmx40cm</option>
<option value = "field2">16inx20in/40cmx50cm</option>
<option value = "field3">20inx24in/50cmx60cm</option>
<option value = "field4">24inx36in/60 cmx90cm</option>
<option value = "field5">30inx40 in/75cmx100 cm</option>
</select>
</form>
<div id="price"></div>
<form>
<input type="submit" value="Submit" onClick="new Ajax.Updater('price','newdbfunction.php',{method: 'post'})";></input>
</form>
</body>
</html>
Newdbfunction.php
<?php
<script>
//Connect to mysql server
$link = mysql_connect("localhost","xxxx","yyyyy"); // ("hostname","username","password");
if(!$link)
die('Failed to connect to server: ' . mysql_error());
//Select database
$db = @mysql_select_db("dddddd"); // dbname
if(!$db)
die("Unable to select database");
$fieldname = $_POST['dim'];
$num = $_POST['fig'];
$qresult = mysql_query("SELECT {$fieldname} FROM price WHERE fig='{$num}'");
$ret = mysql_query ($query) or die(mysql_error());
if(mysql_num_rows($result) > 0){
$data = mysql_fetch_array($result);
if($data[$fieldname] == "-"){
echo "Non-available";
}else{
echo "$" . $data[$fieldname];
}
}else{
echo "Non available";
}
</script>
?>
Javascript file (e.g. myajax.js)
function calc_price(){
if($F('dim') != "" || $F('fig')){
$('price').innerHTML = 'prix not available'; // Not available
} else{
var fig = $F('fig');
var dim = $F('dim');
var pars = "fig=" + fig + "&dim=" + dim;
var oAjax = new Ajax.Updater('price','newdbfunction.php',{method: 'post',parameters: pars}); } }
Price table name - Price.sql
Prices vs fig and size are non linear variable value
DROP TABLE IF EXISTS `price`;
CREATE TABLE IF NOT EXISTS `price` (
`id` int(3) NOT NULL default '0',
`fig_id` int(3) NOT NULL default '0',
`dim_id` int(3) NOT NULL default '0',
`dim` varchar(20) NOT NULL default '0',
`fig` int(3) NOT NULL default '0',
`price` decimal(10,2) default '0.00',
PRIMARY KEY (`id`),
KEY `price_idx`(`fig`,`dim`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Dumping data for table `price`
--
INSERT INTO `price` (`id`, `fig_id`, `dim_id`, `dim`, `fig`, `price`) VALUES (0, 0, 0, '12x16in/30x40cm', 1, 400.00),
(1, 1, 1, '12x16in/30x40cm', 2, 560.00),
(2, 2, 2, '12x16in/30x40cm', 3, 640.00),
(3, 3, 3, '16x20in/40x50cm', 1, 475.00),
(4, 4, 4, '16x20in/40x50cm', 2, 665.00),
(5, 5, 5, '16x20in/40x50cm', 3, 800.00),
(6, 6, 6, '16x20in/40x50cm', 4, 925.00),
(7, 7, 7, '16x20in/40x50cm', 5, 975.00),
(8, 8, 8, '20x24in/50x60cm', 1, 575.00),
(9, 9, 9, '20x24in/50x60cm', 2, 800.00),
(10, 10, 10, '20x24in/50x60cm', 3, 925.00),
(11, 11, 11, '20x24in/50x60cm', 4, 1050.00),
(12, 12, 12, '20x24in/50x60cm', 5, 1125.00),
(13, 13, 13, '20x24in/50x60cm', 6, 1175.00),
(14, 14, 14, '20x24in/50x60cm', 7, 1250.00),
(15, 15, 15, '24x36in/50x60cm', 1, 700.00),
(16, 16, 16, '24x36in/50x60cm', 2, 900.00),
(17, 17, 17, '24x36in/50x60cm', 3, 1100.00),
(18, 18, 18, '24x36in/50x60cm', 4, 1275.00),
(19, 19, 19, '24x36in/50x60cm', 5, 1350.00),
(20, 20, 20, '24x36in/50x60cm', 6, 1425.00),
(21, 21, 21, '24x36in/50x60cm', 7, 575.00),
(22, 22, 22, '24x36in/50x60cm', 8, 1650.00),
(23, 23, 23, '24x36in/50x60cm', 9, 1750.00),
(24, 24, 24, '30x40in/75x100cm', 1, 775.00),
(25, 25, 25, '30x40in/75x100cm', 2, 1100.00),
(26, 26, 26, '30x40in/75x100cm', 3, 1300.00),
(27, 27, 27, '30x40in/75x100cm', 4, 1475.00),
(28, 28, 28, '30x40in/75x100cm', 5, 1550.00),
(29, 29, 29, '30x40in/75x100cm', 6, 1675.00),
(30, 30, 30, '30x40in/75x100cm', 7, 1800.00),
(31, 31, 31, '30x40in/75x100cm', 8, 1925.00),
(32, 32, 32, '30x40in/75x100cm', 9, 2050.00),
(33, 33, 33, '30x40in/75x100cm', 10, 2200.00);
-
Apr 8, 2009, 10:57 #10
- Join Date
- Jan 2005
- Location
- Montreal
- Posts
- 18
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Tanks a lot.
Sorry for posting at the unappropriate forum.
E. P.
Bookmarks