Page 2 of 2

Posted: Tue Jan 24, 2006 11:10 am
by mhouldridge
Suppose if I use your suggestion I could specify the column to use??

Posted: Tue Jan 24, 2006 11:10 am
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.

Posted: Tue Jan 24, 2006 11:11 am
by Chris Corbyn
mhouldridge wrote:Suppose if I use your suggestion I could specify the column to use??
Yes... third parameter in mysql_result()

Posted: Tue Jan 24, 2006 11:15 am
by mhouldridge
Nope, that doesnt work... still get value of 0 when echo'd

Posted: Tue Jan 24, 2006 11:17 am
by Chris Corbyn
Post your code.

Posted: Tue Jan 24, 2006 11:25 am
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;

Posted: Tue Jan 24, 2006 11:28 am
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.

Posted: Tue Jan 24, 2006 11:36 am
by mhouldridge
Ok,

Have added that under the first query and it has given me a syntax error.

Posted: Tue Jan 24, 2006 11:38 am
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;

Posted: Wed Jan 25, 2006 4:02 am
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;

Posted: Wed Jan 25, 2006 5:37 am
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