zgkhoo Posted October 20, 2007 Share Posted October 20, 2007 $result = mysql_query("SELECT * FROM transaction where DrawNumber='$_POST[drawnumber]'") or die('Query failed: ' . mysql_error()); $result2 = mysql_query("SELECT * FROM rate") or die('Query failed: ' . mysql_error()); echo "</br>big rate==".$result2[big]; <-------------------here show empty while($row = mysql_fetch_array($result,MYSQL_ASSOC)){ echo "</br></br></br>DB UserID=".$row[userID]; echo "</br><font color=red>DB bet mode=".$row[betMode]; echo "</font>"; echo "</br>DB bet amount=".$row[Amount]; echo "</br>DB purchase no=".$row[PurchaseNo]; echo "</br>Actual First Prize =".$_POST[first]; $TotalWon=0; //if betmode==even odd if($row[betMode]=="Even"){ echo "</br>even trigger"; //set win lost for even //$example=substr($_POST['first'], 0, 1); //echo "substr".substr($_POST['firstprize'], 0, 1); //echo "</br>example=".$example; //detect the post first prize if(substr($_POST['first'], 0, 1)%2 ) { echo "</br>even not WON!!!"; } else{ echo "</br>even WON!!!!!"; $TotalWon=$row[amount]*$row2[big]; <------------here cant function echo "TotalWon=".$TotalWon; } echo "</br>big rate==".$result2[big]; display null what i want is $TotalWon=$row[amount]*$row2[big](the rate from rate table) and it seem cant get the data for $row2[big] but it just empty. ... Quote Link to comment https://forums.phpfreaks.com/topic/74086-how-to-compare-two-db-query/ Share on other sites More sharing options...
zgkhoo Posted October 20, 2007 Author Share Posted October 20, 2007 note: that rate table just one single record. Quote Link to comment https://forums.phpfreaks.com/topic/74086-how-to-compare-two-db-query/#findComment-374033 Share on other sites More sharing options...
Simon Moon Posted October 20, 2007 Share Posted October 20, 2007 Result here is a resource link, not an array. You want to run mysql_fetch_array first. Look at the example there, it should show you precisely how to use it. You will have to change the code a little. Seriously, go and read a couple tutorials. Most of your questions i have come across are elemental things explained in tutorials. Quote Link to comment https://forums.phpfreaks.com/topic/74086-how-to-compare-two-db-query/#findComment-374045 Share on other sites More sharing options...
zgkhoo Posted October 21, 2007 Author Share Posted October 21, 2007 <?php include 'config.php'; include 'opendb.php'; $sql = "SELECT * FROM rate"; $result = mysql_query($sql); if(mysql_num_rows($result)){ while($row = mysql_fetch_row($result)){ echo $row['Big']; } } else { echo 'No records exist.'; } ?> i read the tutorial and copy its code and modify but the above code showing nothing/empty after i modify. may i know is it mysql_fetch_row() must associate with while loop in order retrieve one row record from the table? if i change echo $row['Big']; to echo $row; then it show word Array Quote Link to comment https://forums.phpfreaks.com/topic/74086-how-to-compare-two-db-query/#findComment-374547 Share on other sites More sharing options...
zgkhoo Posted October 21, 2007 Author Share Posted October 21, 2007 i cant use mysql_fetch_array() cos i just wanna retrieve one row from the table which mysql_fetch_array() retrieve an array. my rate table fields contains null value, is it the problem ? thankss... Quote Link to comment https://forums.phpfreaks.com/topic/74086-how-to-compare-two-db-query/#findComment-374548 Share on other sites More sharing options...
zgkhoo Posted October 21, 2007 Author Share Posted October 21, 2007 $sql = "CREATE TABLE rate ( RateID Integer(6), SetDate Date, Even Double(6,2), Odd Double(6,2), Big Double(6,2), Small Double(6,2), Flower10 Double(6,2), Flower100 Double(6,2), Four1B Double(6,2), Four2B Double(6,2), Four3B Double(6,2), FourSB Double(6,2), FourCB Double(6,2), Four1S Double(6,2), Four2S Double(6,2), Four3S Double(6,2), FourSS Double(6,2), FourCS Double(6,2), FourSure Double(6,2), Primary key(RateID) )"; Quote Link to comment https://forums.phpfreaks.com/topic/74086-how-to-compare-two-db-query/#findComment-374554 Share on other sites More sharing options...
zgkhoo Posted October 21, 2007 Author Share Posted October 21, 2007 solve by echo $row[0] <--- y cant echo $row[big] or $row[userID] <---all these will display "Array" word weird ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/74086-how-to-compare-two-db-query/#findComment-374569 Share on other sites More sharing options...
derwert Posted October 21, 2007 Share Posted October 21, 2007 Do echo '<pre>'; print_r ($row); echo '</pre>'; so you can see what the array looks like in cases where you are unsure. Also in your code you are using for instance $row[userID] This is incorrect, you need to put string indexes in quotations e.g. $row['UserID']. If you don't put it in quotations PHP will look at it as a constant. Quote Link to comment https://forums.phpfreaks.com/topic/74086-how-to-compare-two-db-query/#findComment-374588 Share on other sites More sharing options...
zgkhoo Posted October 21, 2007 Author Share Posted October 21, 2007 but in the mysql query it cant be $row['UserID'] must remove the quotation right? else it will be syntax error so it make me confuse..which different rule for different place.. Quote Link to comment https://forums.phpfreaks.com/topic/74086-how-to-compare-two-db-query/#findComment-374876 Share on other sites More sharing options...
trq Posted October 21, 2007 Share Posted October 21, 2007 <?php include 'config.php'; include 'opendb.php'; $sql = "SELECT * FROM rate LIMIT 1"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); echo $row['Big']; } else { echo 'No records exist.'; } } else { echo mysql_error(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/74086-how-to-compare-two-db-query/#findComment-374883 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.