Jump to content

how to compare two db query?


zgkhoo

Recommended Posts

 	 $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.

...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<?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

 

 

 

Link to comment
Share on other sites

$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)

 

 

 

)";

Link to comment
Share on other sites

 

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.

 

Link to comment
Share on other sites

<?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();
}

?>

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.