Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi all, I have a query about dis 1

Status
Not open for further replies.

sipps

Technical User
Feb 9, 2003
133
GB
Hi all,

I have a query about displaying something based on a result from the DB. I want to show an aspect of a car, and depending on what category this car is in, it will come back with a "1" or a "0". "1" meaning yes it has it, and "0" no it don't.

The code I wrote always seems to say "Yes" whatever, even if I know that the Air_Con category has a no in it!

Please could someone point me out to my mistake!

Code:

<?php if ($row_carexample['Air_Con'] = &quot;1&quot;)
{ echo &quot;Yes&quot;; }
elseif ($row_carexample['Air_Con'] = &quot;0&quot;)
{ echo &quot;No&quot;;}
?>

Cheers.
 
== is the test for equality, = is the asignment operator

if ($row_carexample['Air_Con'] == &quot;1&quot;)
...


-Rob
 
You guys are great at replying so quick! That sorted it ou, sorry, basic error, just trying to learn the language.

I have another little issue though! I have shown the user a list of places, and anchored the names in this list so that when they click on the name, they are taken to the next page to view that specific locations details.

<a href=&quot;goviewlocations.php?<?php echo $row_viewlocations['Location_ID']; ?>&quot;><?php echo $row_viewlocations['Location_Name']; ?></a>

Now, I'm not sure how to grab this number that is sitting in the URL, and get the records from the DB that match that number only.
Is it:

$query_goviewlocation = &quot;SELECT * FROM location WHERE Location_ID = '$_GET[Location_ID]'&quot;;

It doesn't seem to be doing anything but giving me an error &quot;Undefined index: Location_ID&quot;. Should I still be using $_POST even though the ID number is in the URL?

Thanks guys
 
You need quotes around Location_ID I do so believe... two ways to accomplish this... escape character (/) or append the strings... I would suggest appending the string... like so..


$query = &quot;SELECT * FROM location WHERE Location_ID = '&quot;.$_GET[&quot;Location_ID&quot;].&quot;'&quot;;

You might get away with...

$query=&quot;SELECT * FROM location WHERE Location_ID='$_GET['Location_ID']'&quot;;

But I'm not certain.

-Rob
 
Didn't do much really! Still getting the undefined error. I am not sure whether the anchor I wrote is wrong, what do you think? It sends &quot;1&quot; for example up to the URL, but will the next page know that this &quot;1&quot; is Location_ID, and how will it know this?

Cheers
 
I think the problem is in the anchor itself.

You're not assigning a variable name to the value being sent.

Shouldn't those anchors read:
&quot;goviewlocations.php?Location_ID=<?php echo $row_viewlocations['Location_ID']; ?>&quot;><?php echo $row_viewlocations['Location_Name']; ?></a> Want the best answers? Ask the best questions: TANSTAAFL!
 
Thank you all guys, that did the trick!
 
Me again!

That worked fine, but now I wanted to link another page to this one, only it wont put the Location_ID in the URL, it will &quot;POST&quot; the Location_Name from a user form select. I wrote the SQL to be:

&quot;SELECT * FROM location WHERE Location_ID = '$_GET[Location_ID]' OR WHERE Location_Name = '$_POST[Location_Name]'&quot;;

It says I have an error in my sql syntax. I was wondering whether it was becuase $_POST[Location_Name] contained spaces, i.e. 'London Town'.

Any ideas?

Cheers guys.
 
I know, an extra word &quot;WHERE&quot;! Sorry, that was annoying me for ages, I thought that I would need it in there.

Is what I wrote good practive though? I have notices turned on, and obviously, when I go from the page which puts the Location_ID in the URL it gives me an undefined notice because of Location_Name, and when I go from the page that POSTs the Location_Name I get the same error about Location_ID.

Should I be doing this differently?

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top