PDA

View Full Version : database if found stop output


barkermn01
07-10-2008, 08:52 AM
ok what i want is
check the databace for the dates if it returns the date then dont output it
but if it is not there output it
this is my code so far

if($_GET['days'] == '7'){
$con = mysql_connect('localhost', 'User', 'pass');
$db = mysql_select_db('web177-orders');
while($i != 20){
$sql = "SELECT * FROM `Orders` WHERE `date`='$todayI' AND `year`='$year' AND `month`='$month'";
$query = mysql_query($sql, $con);
$row = mysql_fetch_array($query);
if(!isset($row['date']))
{
echo 'Friday '.$todayI.'th '.$months[$month].' '.$year.';';
$todayI += 7;
if($todayI > $days[$month]){$todayI = $todayI - $days[$month]; $month++;}
if($month > 12){$year++; isLeap($year); $month = $month - 12;}
$i++;
}
}
mysql_close($con);
}

if i change if
"(!isset($row['date']))" to if"(isset($row))" it is always true coz $row is set to array so how would i do it

At the moment this part of the script is creating a time out error of 30 secodns even thought there is nothing in the database

Meep3D
07-10-2008, 09:55 AM
Maybe use the function mysql_num_rows() in your if statement to determine if a result was passed rather than using the $row array.

You don't really need the isset, it may even be causing problems. if ( $row['date'] ) { } should do the same thing.

barkermn01
07-10-2008, 10:43 AM
i have done it cheated lol saved all booked dates into array

$ban = array();
$con = mysql_connect('localhost', 'web177-orders', 'Saskia44');
$db = mysql_select_db('web177-orders');
$todayIc = $todayI;
$sql = "SELECT `date`,`year`,`month` FROM `Orders`";
$query = mysql_query($sql, $con);
while($row = mysql_fetch_array($query))
{
$ban[] = $row['date'];
}


if($_GET['days'] == '7'){
while($i != 20){
if($todayI > $days[$month]){$todayI = $todayI - $days[$month]; $month++;}
if($month > 12){$year++; isLeap($year); $month = $month - 12;}
if (!in_array($todayI, $ban)) {
echo 'Friday '.$todayI.' '.$months[$month].' '.$year.';';
}
$i++;
$todayI += 7;
}
}

oesxyl
07-10-2008, 08:47 PM
I see in few posts of yours this:


while($i != 20){


what do you want to achive whith this line?
another question is why don't check if everything work fine when you use mysql function?


$con = mysql_connect('localhost', 'web177-orders', 'Saskia44');
$db = mysql_select_db('web177-orders');
....
$query = mysql_query($sql, $con);


regards