Wrong parameter count for mysql_result()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post by mhouldridge »

Suppose if I use your suggestion I could specify the column to use??
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

mhouldridge wrote:I do not want to return both row data, simply one field within value column.
Yes, but if you run the above you'll be able to see where the value is or if your query is even pulling the expected values.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

mhouldridge wrote:Suppose if I use your suggestion I could specify the column to use??
Yes... third parameter in mysql_result()
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post by mhouldridge »

Nope, that doesnt work... still get value of 0 when echo'd
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Post your code.
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post by mhouldridge »

Code: Select all

$os = $_POST['os'];
$cpu = $_POST['cpu'];
$memory = $_POST['memory'];
$hdd = $_POST['hdd'];
$raid = $_POST['raid'];

$os = stripslashes($os);
$cpu = stripslashes($cpu);
$memory = stripslashes($memory);
$hdd = stripslashes($hdd);
$raid = stripslashes($raid);

	mysql_connect("localhost","","") or die("Problem connecting");
	mysql_select_db("quote") or die("Problem selecting database");
	
	$os_query = mysql_query("SELECT value FROM `os` WHERE id = 1");
	$oscost = mysql_result($os_query, 0, "value");

	$cpu_query = mysql_query("SELECT value FROM `cpu` WHERE id = '$cpu'");
	$cpucost = mysql_result($cpu_query, 0, "value");
	
	$memory_query = mysql_query("SELECT value FROM `memory` WHERE id = '$memory'");
	$memorycost = mysql_result($memory_query, 0, "value");
	
	$hdd_query = mysql_query("SELECT value FROM `hdd` WHERE id = '$hdd'");
	$hddcost = mysql_result($hdd_query, 0, "value");
	
	$raid_query = mysql_query("SELECT value FROM `raid` WHERE id = '$raid'");
	$raidcost = mysql_result($raid_query, 0, "value");

	echo $oscost;
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Code: Select all

mysql_query($query) or die(mysql_error());
It's no doubt echoing 0 because the result is false since the query didn't execute.
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post by mhouldridge »

Ok,

Have added that under the first query and it has given me a syntax error.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Please post your code again.... I hope you did not just copy and past what I posted above... It should have been obvious what to do with it.

Code: Select all

$os = $_POST['os'];
$cpu = $_POST['cpu'];
$memory = $_POST['memory'];
$hdd = $_POST['hdd'];
$raid = $_POST['raid'];

$os = stripslashes($os);
$cpu = stripslashes($cpu);
$memory = stripslashes($memory);
$hdd = stripslashes($hdd);
$raid = stripslashes($raid);

    mysql_connect("localhost","","") or die("Problem connecting");
    mysql_select_db("quote") or die("Problem selecting database");
    
    $os_query = mysql_query("SELECT value FROM `os` WHERE id = 1") or die(mysql_error());
    $oscost = mysql_result($os_query, 0, "value");

    $cpu_query = mysql_query("SELECT value FROM `cpu` WHERE id = '$cpu'") or die(mysql_error());
    $cpucost = mysql_result($cpu_query, 0, "value");
    
    $memory_query = mysql_query("SELECT value FROM `memory` WHERE id = '$memory'") or die(mysql_error());
    $memorycost = mysql_result($memory_query, 0, "value");
    
    $hdd_query = mysql_query("SELECT value FROM `hdd` WHERE id = '$hdd'") or die(mysql_error());
    $hddcost = mysql_result($hdd_query, 0, "value");
    
    $raid_query = mysql_query("SELECT value FROM `raid` WHERE id = '$raid'") or die(mysql_error());
    $raidcost = mysql_result($raid_query, 0, "value");

    echo $oscost;
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post by mhouldridge »

Yep, I did change it to use my first query... please see below code. I still get zero as my result for the echo part at the bottom of my script..

Code: Select all

$os = $_POST['os'];
$cpu = $_POST['cpu'];
$memory = $_POST['memory'];
$hdd = $_POST['hdd'];
$raid = $_POST['raid'];

$os = stripslashes($os);
$cpu = stripslashes($cpu);
$memory = stripslashes($memory);
$hdd = stripslashes($hdd);
$raid = stripslashes($raid);

	mysql_connect("localhost","","") or die("Problem connecting");
	mysql_select_db("quote") or die("Problem selecting database");
	
	$os_query = mysql_query("SELECT value FROM `os` WHERE id = 1") or die(mysql_error());
	$oscost = mysql_result($os_query, 0, "value");

	$cpu_query = mysql_query("SELECT value FROM `cpu` WHERE id = '$cpu'");
	$cpucost = mysql_result($cpu_query, 0, "value");
	
	$memory_query = mysql_query("SELECT value FROM `memory` WHERE id = '$memory'");
	$memorycost = mysql_result($memory_query, 0, "value");
	
	$hdd_query = mysql_query("SELECT value FROM `hdd` WHERE id = '$hdd'");
	$hddcost = mysql_result($hdd_query, 0, "value");
	
	$raid_query = mysql_query("SELECT value FROM `raid` WHERE id = '$raid'");
	$raidcost = mysql_result($raid_query, 0, "value");

	echo $oscost;
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

change this bit...

Code: Select all

$os_query = mysql_query("SELECT value FROM `os` WHERE id = 1") or die(mysql_error()); 
$oscost = mysql_result($os_query, 0, "value");
..to..

Code: Select all

$os_query = mysql_query("SELECT value FROM `os` WHERE id = 1") or die(mysql_error()); 
$oscost = mysql_fetch_assoc($os_query);

echo "<pre>";
print_r($oscost);
echo "</pre>";
...and post here what output you get.

This will show us if your query is actually returning any results
Post Reply