Jump to content

if statement


spearchilduser

Recommended Posts

hi i need a little help with a if statement please:

 

my current query

 

$sql = mysql_query("SELECT * FROM quotes WHERE User_ID='$userid' AND accept_Decline= 5"); 
$sql1 = mysql_num_rows($sql);
	while($row = mysql_fetch_array($sql)){
		$customer_Location = $row["Customer_Location"];
		$customer_Longitude = $row["User_Longitude"];
		$customer_Latitude = $row["User_Latitude"];
		$customer_Destination = $row["Customer_Destination"];
		$how_Many = $row["How_Many"];	
		$wait_Time = $row["Wait_Time"];
		$pric = $row['Price'];
		$qid = $row ['Quote_ID'];
	}

 

then i wan a if statement so

 

if ( $sql1==1)

 

then display:

<table class = tablestyle width = 40% height = 3% align=left>
<tr align = center>
<th width = 10%> Customer Location</th>
<td>

</tr>
<tr><th width = 10% > Customer Destination</th>
<td width = 10%><input readonly type= "text" name="Customer_Destination" value="<?php echo "$customer_Destination"; ?>"></td>
</tr> 					

<tr><th width = 10%>Wait Time (minutes)</th>
<td width = 10%><input readonly type= "text" name="mins" maxlength="2" value="<?php echo "$wait_Time"; ?>"></td>						
</tr>
<tr><th width = 10%>How Many(people)</th>
<td width = 10%><input readonly type= "text" name="numb" value="<?php echo "$how_Many"; ?>"></td>					
</tr>
<tr><th width = 10%>Price</th>
<td width = 10%><input readonly type= "text" name="price" value=£<?php echo "$pric"; ?>>
</td>
</tr>
<tr>
</table>
</br></br></br></br></br></br></br></br></br></br></br></br></br>
<?php
$sql = mysql_query("SELECT * FROM quotes WHERE User_ID='$userid'"); 

	while($row = mysql_fetch_array($sql)){
		$customer_Location = $row["Customer_Location"];
		$customer_Longitude = $row["User_Longitude"];
		$customer_Latitude = $row["User_Latitude"];
		$customer_Destination = $row["Customer_Destination"];
		$how_Many = $row["How_Many"];	
		$wait_Time = $row["Wait_Time"];
		$pric = $row['Price'];
		$qid = $row ['Quote_ID'];
	}

$sql = mysql_query("SELECT * FROM bids 
					WHERE Quote_ID='$qid' AND DeclienedByCustomer=0 "); 
$sql1 = mysql_query("SELECT * FROM bids 
					WHERE Quote_ID='$qid' AND DeclienedByCustomer=2 ");

$sql2 = mysql_query("SELECT * FROM quotes 
					WHERE Quote_ID='$qid' AND accept_Decline=5 "); 
$sql3 = mysql_query("SELECT * FROM quotes 
					WHERE Quote_ID='$qid' AND accept_Decline=2 "); 
$sql4 = mysql_query("SELECT * FROM quotes 
					WHERE Quote_ID='$qid' AND accept_Decline=3 ");
$sql5 = mysql_query("SELECT * FROM quotes 
					WHERE Quote_ID='$qid' AND accept_Decline=4 ");


while($row = mysql_fetch_array($sql)){
		$bidId = $row['Bid_ID'];
		$firmId = $row['Firm_ID'];

		$sql6 = mysql_query("SELECT Firm_Name FROM taxi_firms 
					WHERE Firm_ID='$firmId' "); 

	while($row1 = mysql_fetch_array($sql6)){
		$username = $row1['Firm_Name'];
	}

	echo ' Company Name:  '; echo  $username.'     <a href = "acceptapp.php?Quote_ID='.$qid.'&Firm_ID='.$firmId.'" >     Accept  </a> |    <a href = "declinedapp.php?Quote_ID='.$qid.'&Firm_ID='.$firmId.'" > Decline</a><br />';
	}
echo'</br>';
echo'</br>';
while($row = mysql_fetch_array($sql1)){

echo' you declined this job';
echo'</br>';
echo'</br>';


}
While($row = mysql_fetch_array($sql2)){

echo' Job is being assessed';
echo'</br>';
echo'</br>';


}
While($row = mysql_fetch_array($sql3)){

echo' you declined this job';
echo'</br>';
echo'</br>';


}
While($row = mysql_fetch_array($sql4)){

echo' Company Have Declined This Job';
echo'</br>';
echo'</br>';
echo '<a href="userentryapp.php">Book another taxi</a>';
}
While($row = mysql_fetch_array($sql5)){

echo' Company Have Accepted This Job Please Respond';
echo'</br>';
echo'</br>';

 

else

header("usertentry.php");

}

 

ANY HELP ?

Link to comment
Share on other sites

You need to use brackets.

 

if ($sql1==1) {
    // ... code if statement is true
} else {
    // ... code if statement is false
}

 

I would seriously look into some tutorials regarding SQL JOIN's. Whenever you have queries running inside loops, you are probably doing it wrong. Queries are expensive, don't run them needlessly.

 

Also, normally you wouldn't need to query the same table twice, since you should be able to get all of the data you need the first time 'round. For example you are querying the same table several times to get nearly identical data.

$sql = mysql_query("SELECT * FROM bids 
					WHERE Quote_ID='$qid' AND DeclienedByCustomer=0 "); 
$sql1 = mysql_query("SELECT * FROM bids 
					WHERE Quote_ID='$qid' AND DeclienedByCustomer=2 ");

$sql2 = mysql_query("SELECT * FROM quotes 
					WHERE Quote_ID='$qid' AND accept_Decline=5 "); 
$sql3 = mysql_query("SELECT * FROM quotes 
					WHERE Quote_ID='$qid' AND accept_Decline=2 "); 
$sql4 = mysql_query("SELECT * FROM quotes 
					WHERE Quote_ID='$qid' AND accept_Decline=3 ");
$sql5 = mysql_query("SELECT * FROM quotes 
					WHERE Quote_ID='$qid' AND accept_Decline=4 ");

 

You could instead use logic flow and do something like:

$query = "SELECT * FROM bids WHERE Quote_ID=$qid";

$result = mysql_query($query);

$row = mysql_fetch_assoc($result);

switch($row['accept_Decline'])
{
case 0:
	// do something
break;

case 2:
	// do something
break;

// ... etc ...
}

 

 

Link to comment
Share on other sites

so i have

$sql = mysql_query("SELECT * FROM quotes WHERE User_ID='$userid' AND accept_Decline= 5"); 
$sql1 = mysql_num_rows($sql);

 

if ($sql1==0)

{

header( 'students.comp.glam.ac.uk/08023190/taxi/userentry.php' ) ;

}

else {

 

all the other code

 

 

}

 

but it seems to just show nothing if the first condition is met

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.