spearchilduser Posted April 26, 2012 Share Posted April 26, 2012 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/261638-if-statement/ Share on other sites More sharing options...
scootstah Posted April 26, 2012 Share Posted April 26, 2012 Apart from the very poor design and way too many queries, what's the problem? Quote Link to comment https://forums.phpfreaks.com/topic/261638-if-statement/#findComment-1340658 Share on other sites More sharing options...
spearchilduser Posted April 26, 2012 Author Share Posted April 26, 2012 haha yer i know is not designed well but its telling me that Parse error: parse error, unexpected T_ELSE in E:\students\08023190\taxi\user.php on line 161 which is the line of the else word Quote Link to comment https://forums.phpfreaks.com/topic/261638-if-statement/#findComment-1340660 Share on other sites More sharing options...
spearchilduser Posted April 26, 2012 Author Share Posted April 26, 2012 aww dont wory i have the statement the wrong way around ive fixed it thank you Quote Link to comment https://forums.phpfreaks.com/topic/261638-if-statement/#findComment-1340662 Share on other sites More sharing options...
scootstah Posted April 26, 2012 Share Posted April 26, 2012 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 ... } Quote Link to comment https://forums.phpfreaks.com/topic/261638-if-statement/#findComment-1340663 Share on other sites More sharing options...
spearchilduser Posted April 26, 2012 Author Share Posted April 26, 2012 hmm thanz for the reply ill look into it thank you Quote Link to comment https://forums.phpfreaks.com/topic/261638-if-statement/#findComment-1340669 Share on other sites More sharing options...
spearchilduser Posted April 26, 2012 Author Share Posted April 26, 2012 ok i thought i had fixed the problem but i havent i dnt get what the problem is i just want sql query ... if ($sqlquery ==0) { header(webpage.php); } else { } and it just displays the else statement all the time Quote Link to comment https://forums.phpfreaks.com/topic/261638-if-statement/#findComment-1340710 Share on other sites More sharing options...
scootstah Posted April 26, 2012 Share Posted April 26, 2012 Then obviously the condition isn't being met. What is $sqlquery? Quote Link to comment https://forums.phpfreaks.com/topic/261638-if-statement/#findComment-1340719 Share on other sites More sharing options...
spearchilduser Posted April 26, 2012 Author Share Posted April 26, 2012 its the query that ive written which in this case its checking if there is a row with a number 5 in a certain column Quote Link to comment https://forums.phpfreaks.com/topic/261638-if-statement/#findComment-1340737 Share on other sites More sharing options...
scootstah Posted April 26, 2012 Share Posted April 26, 2012 Can you post the actual code that defines $sqlquery please? Quote Link to comment https://forums.phpfreaks.com/topic/261638-if-statement/#findComment-1340738 Share on other sites More sharing options...
spearchilduser Posted April 26, 2012 Author Share Posted April 26, 2012 $sql = mysql_query("SELECT * FROM quotes WHERE User_ID='$userid' AND accept_Decline= 5"); $sql1 = mysql_num_rows($sql); Quote Link to comment https://forums.phpfreaks.com/topic/261638-if-statement/#findComment-1340739 Share on other sites More sharing options...
scootstah Posted April 26, 2012 Share Posted April 26, 2012 I don't see [tt]$sqlquery[tt]. Quote Link to comment https://forums.phpfreaks.com/topic/261638-if-statement/#findComment-1340741 Share on other sites More sharing options...
spearchilduser Posted April 26, 2012 Author Share Posted April 26, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/261638-if-statement/#findComment-1340744 Share on other sites More sharing options...
spearchilduser Posted April 26, 2012 Author Share Posted April 26, 2012 $sqlquery was just my way of saying the sql query its not actually called $sqlquery its called $sql and $sql1 Quote Link to comment https://forums.phpfreaks.com/topic/261638-if-statement/#findComment-1340745 Share on other sites More sharing options...
scootstah Posted April 26, 2012 Share Posted April 26, 2012 I believe you want header('location: students.comp.glam.ac.uk/08023190/taxi/userentry.php'); Quote Link to comment https://forums.phpfreaks.com/topic/261638-if-statement/#findComment-1340746 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.