Mam problem
[php]<?php
if( tep_db_fetch_array( $statusbirthday_query ) == null )
{
echo 'Nie wysłane';
}
else
{
$message = '';
while ( $statusbirthday = tep_db_fetch_array( $statusbirthday_query ))
{
echo 'cze';
if( $geburtstag['customers_id'] == $statusbirthday['customer_id'])
{
if($statusbirthday['used_time'] == date("Y-m-d H:i",time()) || $statusbirthday['birthday_status'] == 1)
{
$message = 'Wysłane';
$sendbirthday = true;
break;
}
else
{
$message = 'Nie wysłane';
break;
}
}
}
echo $message ;
}
?>
/php]
tak wyglada zapytanie :
[php]<?php
$statusbirthday_query = tep_db_query("SELECT customers_id , used_time , birthday_status FROM customers_birthday");
?>[/php]
Problem tkwi w tym ze jeśli dodaje recznie jeden rekord do bazy customers_birthday to funckcja while nie wykrywa żadnego rekordu poprostu nie działa , ale gdy dołoże jeszcze jeden rekord wtedy widzi ten nowo dodany a tego pierwszego nie widzi , w czym tkwi problem ??[/img]
PHP + mysql problem
Re: PHP + mysql problem
instrukcja pobiera ci już pierwszy rekord z tabeli więc while pobiera drugi w kolejności (a gdy jest tylko jedna w tabeli to nic).
masz dwie opcje: najszybciej ulepszyć warunek if i zmienić while na do while
[php]<?php
if( !($statusbirthday = tep_db_fetch_array( $statusbirthday_query )) )
{ echo 'Nie wysłane'; } else {
$message = '';
do { echo 'cze';
if ($geburtstag['customers_id'] == $statusbirthday['customer_id'])
{ if($statusbirthday['used_time'] == date("Y-m-d H:i",time()) || $statusbirthday['birthday_status'] == 1)
{$message = 'Wysłane'; $sendbirthday = true; break; }
else { $message = 'Nie wysłane'; break; }
}
} while ( $statusbirthday = tep_db_fetch_array( $statusbirthday_query ));
echo $message ;
}
?>[/php]
albo lepiej od razu zamienić ten if na while
[php]<?php
while ( $statusbirthday = tep_db_fetch_array( $statusbirthday_query )) {
$message = '';
echo 'cze';
if ($geburtstag['customers_id'] == $statusbirthday['customer_id'])
{ if($statusbirthday['used_time'] == date("Y-m-d H:i",time()) || $statusbirthday['birthday_status'] == 1)
{$message = 'Wysłane'; $sendbirthday = true; break; }
else { $message = 'Nie wysłane'; break; }
}
echo $message ;
} ?>[/php]
[/code]
Kod: Zaznacz cały
if( tep_db_fetch_array( $statusbirthday_query ) == null )masz dwie opcje: najszybciej ulepszyć warunek if i zmienić while na do while
[php]<?php
if( !($statusbirthday = tep_db_fetch_array( $statusbirthday_query )) )
{ echo 'Nie wysłane'; } else {
$message = '';
do { echo 'cze';
if ($geburtstag['customers_id'] == $statusbirthday['customer_id'])
{ if($statusbirthday['used_time'] == date("Y-m-d H:i",time()) || $statusbirthday['birthday_status'] == 1)
{$message = 'Wysłane'; $sendbirthday = true; break; }
else { $message = 'Nie wysłane'; break; }
}
} while ( $statusbirthday = tep_db_fetch_array( $statusbirthday_query ));
echo $message ;
}
?>[/php]
albo lepiej od razu zamienić ten if na while
[php]<?php
while ( $statusbirthday = tep_db_fetch_array( $statusbirthday_query )) {
$message = '';
echo 'cze';
if ($geburtstag['customers_id'] == $statusbirthday['customer_id'])
{ if($statusbirthday['used_time'] == date("Y-m-d H:i",time()) || $statusbirthday['birthday_status'] == 1)
{$message = 'Wysłane'; $sendbirthday = true; break; }
else { $message = 'Nie wysłane'; break; }
}
echo $message ;
} ?>[/php]
[/code]
