İyinet'e Hoşgeldiniz!

Türkiye'nin En Eski Webmaster Forum'una Hemen Kayıt Olun!

Kayıt Ol!

kayıt yok hatası vermek

Darkart

0
İyinet Üyesi
Katılım
1 Temmuz 2005
Mesajlar
7,037
Reaction score
56
Arkadaşlar php ile veritabanı sorgusu yaptıktan sonra kayıt yoksa hatayı nasıl veriyoruz?

örneğin ben aşağıdaki gibi yaptım. Gelen id ye göre yorumları listeliyor ancak gelen id nin yorumu yoksa bomboş çıkıyor sayfa. Oysaki yorum yok yazsın istiyorum.

PHP:
<?php
$id = $_GET['ID'];
$YorumRs = mysql_query("Select * from tblyorumlar where HaberID='$id'") or die ("hata");
while ($Yorumlar = mysql_fetch_array($YorumRs)) {

if (mysql_num_rows($Yorumlar)>0){
echo "Hiç kayıt bulunamadı !";
}
else
{
echo "<div id=\"Comment\">";
echo "<div id=\"CommentAuthor\">";
echo "<div id=\"CommentAuthorInfo\"><img src='images/comment_author.png' width='70' height='70' /></div>";
echo "<div id=\"CommentAuthorShadow\"></div>";
echo "</div>";
echo "<div id=\"CommentMeta\">";
echo "<div class=\"date\">12 Ocak 2011 Pazartesi 18:57</div>";
echo $Yorumlar['Yorum'];
echo "</div>";
echo "</div>";
}
}
?>
 

dinamikdivx

0
İyinet Üyesi
Katılım
1 Ocak 2011
Mesajlar
340
Reaction score
6
Konum
in İstanbul
PHP:
<?php
$id = $_GET['ID'];
$YorumRs = mysql_query("Select * from tblyorumlar where HaberID='$id'") or die ("hata");
while ($Yorumlar = mysql_fetch_array($YorumRs)) {

if (mysql_num_rows($YorumRs)>0){
echo "<div id=\"Comment\">";
echo "<div id=\"CommentAuthor\">";
echo "<div id=\"CommentAuthorInfo\"><img src='images/comment_author.png' width='70' height='70' /></div>";
echo "<div id=\"CommentAuthorShadow\"></div>";
echo "</div>";
echo "<div id=\"CommentMeta\">";
echo "<div class=\"date\">12 Ocak 2011 Pazartesi 18:57</div>";
echo $Yorumlar['Yorum'];
echo "</div>";
echo "</div>";
}
else
{
echo "Hiç kayıt bulunamadı !";
}
}
?>

bole olucak ..
 

Darkart

0
İyinet Üyesi
Katılım
1 Temmuz 2005
Mesajlar
7,037
Reaction score
56
Teşekkürler cevap için ancak hata mesajı çıkmıyor, yorum alanı bomboş çıkıyor.
 

CSManager.NET

0
İyinet Üyesi
Katılım
20 Aralık 2010
Mesajlar
447
Reaction score
6
Konum
İstanbul
PHP:
<?php
$id = $_GET['ID'];
$YorumRs = mysql_query("Select * from tblyorumlar where HaberID='$id'") or die ("hata");
while ($Yorumlar = mysql_fetch_array($YorumRs)) {

if (mysql_num_rows($YorumRs)>0){
echo "<div id=\"Comment\">";
echo "<div id=\"CommentAuthor\">";
echo "<div id=\"CommentAuthorInfo\"><img src='images/comment_author.png' width='70' height='70' /></div>";
echo "<div id=\"CommentAuthorShadow\"></div>";
echo "</div>";
echo "<div id=\"CommentMeta\">";
echo "<div class=\"date\">12 Ocak 2011 Pazartesi 18:57</div>";
echo $Yorumlar['Yorum'];
echo "</div>";
echo "</div>";
}
if (mysql_num_rows($YorumRs)<=0)
{
echo "Hiç kayıt bulunamadı !";
}

?>

en altta else yerine saydırdım bunu dene birde.
 

Darkart

0
İyinet Üyesi
Katılım
1 Temmuz 2005
Mesajlar
7,037
Reaction score
56
yok hayır yine boş çıkıyor. Şakamı bu yahu :(
asp nin gözünü seveyim şimdiye kadar bitmişti elli kere...
 

Siarem

0
İyinet Üyesi
Katılım
10 Temmuz 2011
Mesajlar
2
Reaction score
0
Aslında yapmanız gerekenin tam tersini yapmışsınız. Önce SQL sorgusundan dönen sonuç olup olmadığını kontrol edip sonra eğer sonuç varsa while döngüsüne sokmalısınız. Sizin yaptığınız gibi olunca döngüye girecek sonuç olmadığından döngü içindeki kod çalışmıyor doğal olarak.

PHP:
<?php
$id = $_GET['ID'];
$YorumRs = mysql_query("Select * from tblyorumlar where HaberID='$id'") or die ("hata");

if(mysql_num_rows($YorumRs)>0)
{
while ($Yorumlar = mysql_fetch_array($YorumRs)) {
echo "<div id=\"Comment\">";
echo "<div id=\"CommentAuthor\">";
echo "<div id=\"CommentAuthorInfo\"><img src='images/comment_author.png' width='70' height='70' /></div>";
echo "<div id=\"CommentAuthorShadow\"></div>";
echo "</div>";
echo "<div id=\"CommentMeta\">";
echo "<div class=\"date\">12 Ocak 2011 Pazartesi 18:57</div>";
echo $Yorumlar['Yorum'];
echo "</div>";
echo "</div>";
}
}
else
{
echo "Hiç kayıt bulunamadı !";
}
?>
 
E

Erturk

Misafir
Bu sekilde daha saglıklı calısacaktır.
PHP:
<?php
$id = $_GET['ID'];
$YorumRs = mysql_query("Select * from tblyorumlar where HaberID='$id'") or die ("hata");
if (mysql_num_rows($YorumRs)<1){
echo "Hiç kayıt bulunamadı !";
} else {
while ($Yorumlar = mysql_fetch_array($YorumRs)) {
echo "<div id=\"Comment\">";
echo "<div id=\"CommentAuthor\">";
echo "<div id=\"CommentAuthorInfo\"><img src='images/comment_author.png' width='70' height='70' /></div>";
echo "<div id=\"CommentAuthorShadow\"></div>";
echo "</div>";
echo "<div id=\"CommentMeta\">";
echo "<div class=\"date\">12 Ocak 2011 Pazartesi 18:57</div>";
echo $Yorumlar['Yorum'];
echo "</div>";
echo "</div>";
}}
?>
 

Darkart

0
İyinet Üyesi
Katılım
1 Temmuz 2005
Mesajlar
7,037
Reaction score
56
Aslında yapmanız gerekenin tam tersini yapmışsınız. Önce SQL sorgusundan dönen sonuç olup olmadığını kontrol edip sonra eğer sonuç varsa while döngüsüne sokmalısınız. Sizin yaptığınız gibi olunca döngüye girecek sonuç olmadığından döngü içindeki kod çalışmıyor doğal olarak.

PHP:
<?php
$id = $_GET['ID'];
$YorumRs = mysql_query("Select * from tblyorumlar where HaberID='$id'") or die ("hata");

if(mysql_num_rows($YorumRs)>0)
{
while ($Yorumlar = mysql_fetch_array($YorumRs)) {
echo "<div id=\"Comment\">";
echo "<div id=\"CommentAuthor\">";
echo "<div id=\"CommentAuthorInfo\"><img src='images/comment_author.png' width='70' height='70' /></div>";
echo "<div id=\"CommentAuthorShadow\"></div>";
echo "</div>";
echo "<div id=\"CommentMeta\">";
echo "<div class=\"date\">12 Ocak 2011 Pazartesi 18:57</div>";
echo $Yorumlar['Yorum'];
echo "</div>";
echo "</div>";
}
}
else
{
echo "Hiç kayıt bulunamadı !";
}
?>

Bu sekilde daha saglıklı calısacaktır.
PHP:
<?php
$id = $_GET['ID'];
$YorumRs = mysql_query("Select * from tblyorumlar where HaberID='$id'") or die ("hata");
if (mysql_num_rows($YorumRs)<1){
echo "Hiç kayıt bulunamadı !";
} else {
while ($Yorumlar = mysql_fetch_array($YorumRs)) {
echo "<div id=\"Comment\">";
echo "<div id=\"CommentAuthor\">";
echo "<div id=\"CommentAuthorInfo\"><img src='images/comment_author.png' width='70' height='70' /></div>";
echo "<div id=\"CommentAuthorShadow\"></div>";
echo "</div>";
echo "<div id=\"CommentMeta\">";
echo "<div class=\"date\">12 Ocak 2011 Pazartesi 18:57</div>";
echo $Yorumlar['Yorum'];
echo "</div>";
echo "</div>";
}}
?>

Her ikinizede çok teşekkürler. Tamamen mantık hatası yapmışım aslında. Yardım için saolun.
 

Türkiye’nin ilk webmaster forum sitesi iyinet.com'da forum üyeleri tarafından yapılan tüm paylaşımlardan; Türk Ceza Kanunu’nun 20. Maddesinin, 5651 Sayılı Kanununun 4. maddesinin 2. fıkrasına göre, paylaşım yapan üyeler sorumludur.

Üst