Jump to content

for $_GET['meNot']


AL123

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.