Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
spoofter
Forum Newbie
Posts: 2
Joined: Wed Oct 21, 2009 2:10 pm

Help

Post by spoofter »

Hi guys, can anyone help me with this script? The problem is that even with right values in data base it still fails, but only when i have more than 1 row in db.

Any suggestions on how to make this work properly ?

-------------------------------------------------------------------------------------------------------------------

<?php

include 'config.php';
$p=1;
$q=1;
$r=1;
$s=1;

$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");

$selected = mysql_select_db("db",$dbhandle)
or die("Could not select db");

$result = mysql_query("SELECT a, b, c, d FROM Table");
while ($row = mysql_fetch_array($result)) {
$a = $row['a'];
$b = $row['b'];
$c = $row['c'];
$d = $row['d'];
}

$result2= mysql_query("SELECT x, y, z, t FROM Table2");
while ($row = mysql_fetch_array($result2)) {
$x = $row['x'];
$y = $row['y'];
$z = $row['z'];
$t = $row['t'];
}


$ex = $a+$b+$c+$d;
$ex2 = $x+$y+$z+$t;
$ex3 = $ex+$ex2;
$ex4 = $p+$q+$r+$s;

//-------------------------------------------------------------------------------

if ($ex4 >= $ex && $ex4 <= $ex3) {
echo "Succes"."<br>"; }
else {
echo "Fail"."<br>";
}

//------------------------------------------------------------------------------


?>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Help

Post by requinix »

Code: Select all

while ($row = mysql_fetch_array($result)) {
$a = $row['a'];
$b = $row['b'];
$c = $row['c'];
$d = $row['d'];
}
Every time through that loop you overwrite the values of $a, $b, $c, and $d. After the loop you'll only have the values from the last row. Same for the other loop.

If you had given a description of the problem I would have suggested another method.
spoofter
Forum Newbie
Posts: 2
Joined: Wed Oct 21, 2009 2:10 pm

Re: Help

Post by spoofter »

Thx man, you really helped me a lot. You've shown me where the problem was and I fix it.
Post Reply