aebstract Posted January 22, 2008 Share Posted January 22, 2008 I guess that is how I could explain it.. Here is what I have: if ($$sheet == 0) { header("Location: acchome.php"); } Which isn't working, probably pretty obvious. I have a variable "sheet" and need to check if it is set to 0. The variable sheet could be set to a number of different things, and depending on what it is, it will check against the correct db column, which is what sheet is set to. This is why I need a $ in front of my variable. Is there a way to do this? Quote Link to comment Share on other sites More sharing options...
revraz Posted January 22, 2008 Share Posted January 22, 2008 You probably want to use a SWITCH and CASE statement Quote Link to comment Share on other sites More sharing options...
aebstract Posted January 22, 2008 Author Share Posted January 22, 2008 Isn't that basically the same thing as an if/else/elseif statement except a little cleaner? Quote Link to comment Share on other sites More sharing options...
aebstract Posted January 22, 2008 Author Share Posted January 22, 2008 What would this error mean: Unknown column 'ph' in 'where clause' I have a column in my db called PH Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 22, 2008 Share Posted January 22, 2008 paste the whole query Quote Link to comment Share on other sites More sharing options...
aebstract Posted January 22, 2008 Author Share Posted January 22, 2008 It's not a query problem, I have it working fine.. I'm just translating it over so that it works globally depending on the variable that is set, which comes from the url from the previous page. All I need to do is plop a variable in, which means I need to actually create a variable from the result of another variable. Which logically would be $$sheet or $($sheet). If $sheet = ph then I want $ph. If $sheet = fp then I want $fp. $sheet = ($_GET['sheet']); mysql_connect("localhost","berryequipment","gU8Kso8Y") or die(mysql_error()); mysql_select_db("berryequipment_net"); $id = $_SESSION["id"]; $result = mysql_query("SELECT * FROM plants WHERE id='$id'") or DIE(mysql_error()); while($r=mysql_fetch_array($result)) { $id=$r["id"]; $plantloc=$r["plantloc"]; $address=$r["address"]; $ph=$r["PH"]; $fp=$r["FP"]; if ($$sheet == 0) { header("Location: acchome.php"); } } $result2 = mysql_query("SELECT * FROM parts WHERE MCHN=$sheet ORDER BY LOC ASC") or DIE(mysql_error()); while($r2=mysql_fetch_array($result2)) { $pid=$r2["id"]; $loc=$r2["LOC"]; $pn=$r2["PN"]; $desc=$r2["DESC"]; Two different parts that would feed off of this, but I really just need to get that variable created? Quote Link to comment Share on other sites More sharing options...
revraz Posted January 22, 2008 Share Posted January 22, 2008 Means you need to use PH and not ph or you have single quotes around it, which is why he asked to see the Query. If you ask for help and someone asks to see something and you don't provide it, don't expect help. What would this error mean: Unknown column 'ph' in 'where clause' I have a column in my db called PH Quote Link to comment Share on other sites More sharing options...
aebstract Posted January 22, 2008 Author Share Posted January 22, 2008 I did provide it.. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 22, 2008 Share Posted January 22, 2008 Try something like this: <?php $sheet = $_GET['sheet']; mysql_connect("localhost","username","password") or die(mysql_error()); //You shouldn't inlcude actual passwords on this site mysql_select_db("my_db"); $id = $_SESSION["id"]; $result = mysql_query("SELECT * FROM `plants` WHERE `id`='".mysql_real_escape_string($id)."'") or DIE(mysql_error()); while($r=mysql_fetch_array($result)){ //you may want to try print_r($r) here to check the case of your array keys $id=$r["id"]; $plantloc=$r["plantloc"]; $address=$r["address"]; $ph=$r["PH"]; $fp=$r["FP"]; if (!$$sheet == 0) { header("Location: acchome.php"); exit; } } $result2 = mysql_query("SELECT * FROM `parts` WHERE `mchn`=".mysql_real_escape_string($sheet)." ORDER BY `loc` ASC") or DIE(mysql_error()); while($r2=mysql_fetch_array($result2)){ print_r($r2); } ?> Quote Link to comment Share on other sites More sharing options...
aebstract Posted January 22, 2008 Author Share Posted January 22, 2008 $sheet = $_GET['sheet']; mysql_connect("localhost","berryequipment","gU8Kso8Y") or die(mysql_error()); mysql_select_db("berryequipment_net"); $id = $_SESSION["id"]; $result = mysql_query("SELECT * FROM plants WHERE id='$id'") or DIE(mysql_error()); while($r=mysql_fetch_array($result)) { $id=$r["id"]; $plantloc=$r["plantloc"]; $address=$r["address"]; $ph=$r["PH"]; $fp=$r["FP"]; if (!$$sheet == 0) { header("Location: acchome.php"); exit; } } In my db FP = 0 and PH = 1, if I go to order.php?sheet=PH it works, FP works too.. it isn't kicking me back to acchome.php Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 22, 2008 Share Posted January 22, 2008 First..sorry..i meant to use if (!$$sheet) { But if you have the actual values 0 and 1 in there, then your original should work: if ($$sheet == 0) { There is a simpler way to do this though: while($r=mysql_fetch_array($result)){ if ($r[$sheet] == 0) { header("Location: acchome.php"); exit; } } Quote Link to comment Share on other sites More sharing options...
aebstract Posted January 22, 2008 Author Share Posted January 22, 2008 Perfect, that second way is definitely a better and cleaner way of doing it. Thanks for your help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.