AL123 Posted March 4, 2011 Share Posted March 4, 2011 New guy. I am trying to pass a value through $_GET to an sql statement. I am first getting that value from the DB and printing it as a link. When you click the link, go to the DB and get more info. I know my second sql statement works in phpMyAdmin. For some reason I can't 'get' my value into the sql. Here is the code: <form method="GET" action="?"> <table> <tr><td valign="top"> <table> <tr><td class="pickBiz"><?php $pickMessage; ?></td></tr> <?php $sql = "SELECT categoryId FROM categories"; $sth = $dbh->prepare($sql); $sth-> execute(); $result = $sth->fetchAll(PDO::FETCH_COLUMN, 0); // foreach($result as $value) { echo '<tr><td class="showBiz">'; echo "<a href='index.php?catId=$value'>"; echo "$value</a></td></tr>\n"; } ?> </table> </td> <td valign="top"> <table> <?php if($_GET['value']) { $sql = "SELECT * FROM business, businessCat WHERE businessCat.categoryId = '$value' AND business.businessId = businessCat.businessId"; $sth = $dbh->prepare($sql); $sth-> execute(); $result = $sth->fetchAll(PDO::FETCH_ASSOC); foreach($result as $key => $value) { if($color == 1) {$bgShade = 'dark'; $color = 0;} else {$bgShade = 'light'; $color = 1;} echo "<tr>\n"; for($i = 0; $i < count($Value); $i++) {echo "<td class=\"$bgShade\">$value[i]</td>\n";} } echo "</tr>\n"; } if(empty($_GET['value'])){ echo "No GET variables"; } ?> </table> </td></tr> </table> </form> <hr /> </div><!--END View BizList--> Can anyone see what I am missing? AL. Quote Link to comment Share on other sites More sharing options...
crabfinger Posted March 4, 2011 Share Posted March 4, 2011 i see that there is an unwanted whitespace character in this line $sth-> execute(); other than that try some error reporting. Quote Link to comment Share on other sites More sharing options...
AL123 Posted March 4, 2011 Author Share Posted March 4, 2011 I took out the whitespace, no luck. good eye. AL. Quote Link to comment Share on other sites More sharing options...
WTFranklin Posted March 5, 2011 Share Posted March 5, 2011 Hey AL, I could be wrong, but the one thing I noticed is you have this line if($_GET['value']) { $sql = "SELECT * FROM business, businessCat WHERE businessCat.categoryId = '$value' AND business.businessId = businessCat.businessId"; I noticed that you use the $value variable that you were using in your foreach loop, only this part of your code is outside of your foreach loop. Maybe try replacing that line with: $sql = "SELECT * FROM business, businessCat WHERE businessCat.categoryId = '" . $_GET['value'] . "' AND business.businessId = businessCat.businessId"; or setting up a variable that holds the get variable... if that's not already set that is. If you have $value already set it might be getting changed in your foreach loop That's my best guess from looking at your code, hopefully that helps. -Frank Quote Link to comment Share on other sites More sharing options...
AL123 Posted March 5, 2011 Author Share Posted March 5, 2011 I tried changing the sql var to $_GET['$value'] to no avail. also tried: $passTo = $_GET['$value'] nothing. If I do this: if(in_array($value, $result)) { foreach($result as $value) {echo $value;} // rest of code I get every category name. Witch is what I want, I just can't get it into the sql. (If I manually add the 'value' I am trying to pass, in phpMyAdmin, I get the correct response. ) Running the code I get this error: Notice: Undefined variable: Value Thanks for the help so far - AL. Quote Link to comment Share on other sites More sharing options...
WTFranklin Posted March 10, 2011 Share Posted March 10, 2011 Hey Al, sorry for the delay in response. With the $_GET variable you'd do $_GET['value'] instead of putting the $ in the single quotes with value. I hope that helps! -Frank 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.