[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PHP, MySQL, check for record, if empty then

Posted on 2009-04-21
4
Medium Priority
?
711 Views
Last Modified: 2013-12-12
Hello,

I need to have it so that if there is no for propid then it shows:

print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';

if there is a record then it shows the below I tried to do:

      if(($garage == ''))
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';

But it does not work
<?php
 
$query = "SELECT * FROM properties WHERE propid = '$propid'"; 
	 	 
$result = mysql_query($query) or die(mysql_error());
 
while($row = mysql_fetch_array($result)){
 
 
	if(($garage == '')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '1')) 
print '<option></option><option selected value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '2')) 
print '<option></option><option value="1">No Dedicated Parking</option><option selected value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '3')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option selected value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '4')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option selected value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '5')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option selected value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '6')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option selected value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '7')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option selected value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '8')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option selected value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '9')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option selected value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '10')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option selected value="10">Other</option>';
 
}
?>

Open in new window

0
Comment
Question by:movieprodw
  • 2
4 Comments
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 24196439
what is "$garage"
0
 
LVL 1

Author Comment

by:movieprodw
ID: 24196566
garage is one of the fields in the property table. I need it to check if a propid is posted if not then make it 'n' if it is then it works as usual.

Below is how I just fixed it but I want to make sure that its ok to do it.
<?php
if (empty($propid))
{
$propid2 = 'n';
 
}
 
	if(($propid2 == 'n')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
 
	if(($propid == $propid)) 
 
$query = "SELECT * FROM properties WHERE propid = '$propid'"; 
	 	 
$result = mysql_query($query) or die(mysql_error());
 
while($row = mysql_fetch_array($result)){
 
 
	if(($garage == '1')) 
print '<option></option><option selected value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '2')) 
print '<option></option><option value="1">No Dedicated Parking</option><option selected value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '3')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option selected value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '4')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option selected value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '5')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option selected value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '6')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option selected value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '7')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option selected value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '8')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option selected value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '9')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option selected value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '10')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option selected value="10">Other</option>';
 
}
?> 

Open in new window

0
 
LVL 16

Accepted Solution

by:
CWS (haripriya) earned 2000 total points
ID: 24196794
If $garage is a field from properties table then, you should change it like this:
<?php
if (empty($propid))
{
$propid2 = 'n';
 
}
 
	if(($propid2 == 'n')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
 
	if(($propid == $propid)) 
 
$query = "SELECT * FROM properties WHERE propid = '$propid'"; 
	 	 
$result = mysql_query($query) or die(mysql_error());
 
while($row = mysql_fetch_array($result)){
 $garage=$row['garage'];
 
	if(($garage == '1')) 
print '<option></option><option selected value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '2')) 
print '<option></option><option value="1">No Dedicated Parking</option><option selected value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '3')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option selected value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '4')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option selected value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '5')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option selected value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '6')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option selected value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '7')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option selected value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '8')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option selected value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '9')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option selected value="9">Four Car Garage</option><option value="10">Other</option>';
	if(($garage == '10')) 
print '<option></option><option value="1">No Dedicated Parking</option><option value="2">Street Parkng</option><option value="3">Assigned Parking Spot</option><option value="4">One Car Carport</option><option value="5">Two Car Carport</option><option value="6">One Car Garage</option><option value="7">Two Car Garage</option><option value="8">Three Car Garage</option><option value="9">Four Car Garage</option><option selected value="10">Other</option>';
 
}
?> 

Open in new window

0
 
LVL 1

Author Closing Comment

by:movieprodw
ID: 31572868
Worked great, thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month20 days, 14 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question