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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.