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. Link to comment https://forums.phpfreaks.com/topic/229618-for-_getmenot/ 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. Link to comment https://forums.phpfreaks.com/topic/229618-for-_getmenot/#findComment-1183024 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. Link to comment https://forums.phpfreaks.com/topic/229618-for-_getmenot/#findComment-1183027 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 Link to comment https://forums.phpfreaks.com/topic/229618-for-_getmenot/#findComment-1183068 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. Link to comment https://forums.phpfreaks.com/topic/229618-for-_getmenot/#findComment-1183099 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 Link to comment https://forums.phpfreaks.com/topic/229618-for-_getmenot/#findComment-1185412 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.