Türkiye'nin En Eski Webmaster Forumu İyinet'e Hoşgeldiniz!

kayıt yok hatası vermek

Darkart

0
Onaylı Üye
Üye
Katılım
1 Temmuz 2005
Mesajlar
7,037
Açılan Konu
291
Tepki puanı
53
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
Onaylı Üye
Üye
Katılım
1 Ocak 2011
Mesajlar
340
Açılan Konu
18
Tepki puanı
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
Onaylı Üye
Üye
Katılım
1 Temmuz 2005
Mesajlar
7,037
Açılan Konu
291
Tepki puanı
53
Teşekkürler cevap için ancak hata mesajı çıkmıyor, yorum alanı bomboş çıkıyor.
 

CSManager.NET

0
Onaylı Üye
Üye
Katılım
20 Aralık 2010
Mesajlar
447
Açılan Konu
33
Tepki puanı
4
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
Onaylı Üye
Üye
Katılım
1 Temmuz 2005
Mesajlar
7,037
Açılan Konu
291
Tepki puanı
53
yok hayır yine boş çıkıyor. Şakamı bu yahu :(
asp nin gözünü seveyim şimdiye kadar bitmişti elli kere...
 

daRius

0
Onaylı Üye
Üye
Katılım
9 Nisan 2011
Mesajlar
1,187
Açılan Konu
54
Tepki puanı
14
Konum
İzmir / Manisa
if (mysql_num_rows($YorumRs)==lisanssız)
olarak deneyebilirmisiniz birde ?
 

Siarem

0
Üye
Katılım
10 Temmuz 2011
Mesajlar
2
Açılan Konu
0
Tepki puanı
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
Onaylı Üye
Üye
Katılım
1 Temmuz 2005
Mesajlar
7,037
Açılan Konu
291
Tepki puanı
53
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.
 
Üst