Out OFF Topic » Güncel

sql konusunda kendine güvenenlere acil bir sorum war.

http://forum.whmdestek.com/

Go Back   WHM/cPanel Support Platform » Türkçe » Out OFF Topic » Güncel
 


Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 01.11.07, 02:15
wdp wdp is offline
Sempron
 
Join Date: Jun 2007
Location: ank
Posts: 29
Rep Power: 0
wdp is on a distinguished road
sql konusunda kendine güvenenlere acil bir sorum war.

merhabalar .
üzerinde çalıştığım yeni projemde sql sorunu yaşıyorum.

konuyu açıklayacak olursak :
veri tabanında yorumlar ve isimler diye iki tablom var .


isimler tablosu şu şekilde :

+-----+-------+-------+------------+------------+-----------+----------+--------+----------+-------|
|--------------------------------------------|isimler|--------------------------------------------|
+-----+-------+-------+------------+------------+-----------+----------+--------+----------+-------|
| iid | isim |
+-----+-------+-------+------------+------------+-----------+----------+--------+----------+-------|
| 1 | mehmet |
| 3 | ali |





yorumlar tablosu şu şekilde :

+-----+-------+-------+------------+------------+-----------+----------+--------+----------+-------|
|--------------------------------------------|yorumlar|--------------------------------------------|
+-----+-------+-------+------------+------------+-----------+----------+--------+----------+-------|
|yid| iid | yorum |
+-----+-------+-------+------------+------------+-----------+----------+--------+----------+-------|
|56 | 1 | yorumlardan biri |
|57 | 3 | baska bir yorum |
|57 | 1 | dahada baska bir yorum |

yid=yorum id
iid= isim id
yorum = yorumlar





şimdi şöle bişey yapmak istiyorum :
en çok yorum yazılan 10 isimi alt alta dizmek :
yani şu şekilde:

mehmet (2)
ali (1)



en çok yorum alanı en üste almalı ve parantez içerisinde yorum sayısını yazmalı.


bu konuda bir çalışma yaptım her isime parantez içerisinde kaç tane yorum olduğunu yazıyorum ama bu isimleri parantez içerisindeki rakamın büyükten küçüğe doğru sıralayamıyorum.

yani sıralama yorum sayısına göre olmuyor isime göre oluyor :


kullandığım kodlar aşağıdaki gibi...

<? $sql6= "SELECT * FROM isimler ORDER BY fadi ASC";
$Calistirlistele6 = mysql_query ($sql6); while(list($v_fid1,$v_fadi1,$v_adres1,$v_ftelefon1 ,$v_kateid1,$v_yetkili1,$v_ykadi1,$v_ysifre1)=mysq l_fetch_array($Calistirlistele6))
{ ?>
&nbsp;<lii>&nbsp;<a style='text-decoration: none' href="isimincele.php?iid=<? print $v_fid1; ?>"><? print $v_fadi1; ?>(<? $sql3= "SELECT COUNT(*) FROM yorumlar WHERE fid='$v_fid1' and durum='Onayli' ";
$Calistirlistele3 = mysql_query ($sql3);
while(list($veri3)=mysql_fetch_array($Calistirlist ele3))
print $veri3;?>)</a></lii><br>
<? } ?>



bu kodları nasıl düzenlersek istediğim gibi yaparız sıralamayı ? yorum sayısına göre sıralamalı.



yardımlarınız için tşkkr ederim.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2  
Old 01.11.07, 09:21
ALEXIS's Avatar
phpBB Türkiye
 
Join Date: Aug 2007
Location: istanbul
Posts: 112
Rep Power: 2
ALEXIS is on a distinguished road
http://www.canver.net/viewtopic.php?f=19&t=15504

Kullanım mantığı bana, komutlar php.net'e aittir. Dosya GPL lisanslıdır, istediğiniz gibi kullanabilirsiniz, sadece nereden geldiğini unutmayın.

Aşağıdaki örnekte, direk sayfa içinde mysql bağlantısı yapıldı, ve tüm işlemler mysql komutları ile yapıldı. Acemilerin zorlanmamı için hata fonksiyonlarını da ekledim.

Dosya içinde yeterince açıklama yaptığımı sanıyorum, anlamadığınız yerleri sorabilir veya php.net adresine bakabilirsiniz.

Dosyalar:

database.sql
Code:
-- phpMyAdmin SQL Dump
-- version 2.10.3
-- http://www.phpmyadmin.net
-- 
-- Anamakine: localhost
-- Üretim Zamanı: 01 Kasım 2007 saat 08:08:49
-- Sunucu sürümü: 5.0.45
-- PHP Sürümü: 5.2.3
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
-- 
-- Veritabanı: `test_wdp`
-- 
-- --------------------------------------------------------
-- 
-- Tablo yapısı: `wdp_isimler`
-- 
CREATE TABLE `wdp_isimler` (
  `iid` mediumint(8) unsigned NOT NULL auto_increment,
  `isim` varchar(255) collate latin1_general_ci NOT NULL,
  PRIMARY KEY  (`iid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=4 ;
-- 
-- Tablo döküm verisi `wdp_isimler`
-- 
INSERT INTO `wdp_isimler` (`iid`, `isim`) VALUES 
(1, 'ahmet'),
(2, 'mehmet'),
(3, 'veli');
-- --------------------------------------------------------
-- 
-- Tablo yapısı: `wdp_yorumlar`
-- 
CREATE TABLE `wdp_yorumlar` (
  `yid` mediumint(8) unsigned NOT NULL auto_increment,
  `iid` mediumint(8) unsigned NOT NULL,
  `yorum` text collate latin1_general_ci,
  PRIMARY KEY  (`yid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=5 ;
-- 
-- Tablo döküm verisi `wdp_yorumlar`
-- 
INSERT INTO `wdp_yorumlar` (`yid`, `iid`, `yorum`) VALUES 
(1, 1, 'ahmet - yorum 1'),
(2, 1, 'ahmet - yorum 2'),
(3, 1, 'ahmet - yorum 3'),
(4, 2, 'mehmet - yorum 1');
sirala.php

PHP Code:
<?php
/**
*
* @version $Id: sirala.php
* @copyright (c) 2007 Canver Software
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
// mysql erişim ayarları
$sunucu     'localhost';
$veritabani 'test_wdp';
$kullanici     'root';
$parola     '';
$tablo_onek    'wdp_';
// mysql tablo adları
define('KULLANICI_TABLE',     $tablo_onek 'isimler');
define('YORUM_TABLE',         $tablo_onek 'yorumlar');
// mysql bağlantısı aç
$baglan mysql_connect($sunucu$kullanici$parola);
// bağalantı sağlanamaz ise hata ver
if (!$baglan)
{
    die (
'MySQL ile veri bağlantısı kurulamıyor!');
}
// veritabanı seç
mysql_select_db($onek $veritabani$baglan) or die('Veritabanı açılamıyor!' mysql_error());
// [+] kullanıcıları listeleme sorgusu
$sql 'SELECT * FROM ' KULLANICI_TABLE ' ORDER BY isim ASC';
$sorgu mysql_query($sql);
if (!
$sorgu
{
    die(
mysql_error());
}
while (
$row mysql_fetch_assoc($sorgu))
{
    echo 
$row['isim'] . ' (' yorum_sayisi($row['iid']) . ')<br />';
}
mysql_free_result($sorgu);
// [-] kullanıcıları listeleme sorgusu
/**
* yorum_sayisi
*
* verilen kullanıcı id'e göre yorum sayısını geri döndürür
*/
function yorum_sayisi($iid)
{
    
// [+] yorum sayısı bulma sorgusu
    
$sql 'SELECT COUNT(distinct yid) AS yorum_sayisi FROM ' YORUM_TABLE " WHERE iid = $iid";
    
$sorgu mysql_query($sql);
    
// sonuç alınamaz ise mysql hatası ver
    
if (!$sorgu
    {
        die(
mysql_error());
    }
    
$row mysql_fetch_assoc($sorgu);
    
mysql_free_result($sorgu);
    
// [+] yorum sayısı bulma sorgusu    
    
return $row['yorum_sayisi'];
}
// bağlantıyı kapat
mysql_close($baglan);
?>
Önizleme resmi:
__________________
Profesyonel phpBB3 hizmetleri
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old 01.11.07, 15:51
sinangunay's Avatar
FULL DESTEK SUNUCULAR
 
Join Date: Jul 2007
Location: biLi biLi boP
Age: 28
Posts: 1,664
Rep Power: 1073
sinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond repute
Güzelmiş. Keşke PHP bilsem
__________________
-----------------------------------------------------------------------------------------
>> LÜTFEN ÜCRETSİZ DESTEK TALEP ETMEK İÇİN MSN ADRESLERİMİZİ EKLEMEYİNİZ. HER TÜRLÜ ÜCRETSİZ DESTEK İÇİN FORUMLARIMIZI KULLANINIZ. TEŞEKKÜRLER <<
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old 02.11.07, 02:40
RAMBilisim's Avatar
www.rambilisim.com
 
Join Date: Jun 2007
Location: Samsun
Posts: 824
Rep Power: 43
RAMBilisim has a reputation beyond reputeRAMBilisim has a reputation beyond reputeRAMBilisim has a reputation beyond reputeRAMBilisim has a reputation beyond reputeRAMBilisim has a reputation beyond reputeRAMBilisim has a reputation beyond reputeRAMBilisim has a reputation beyond reputeRAMBilisim has a reputation beyond reputeRAMBilisim has a reputation beyond reputeRAMBilisim has a reputation beyond reputeRAMBilisim has a reputation beyond repute
Send a message via MSN to RAMBilisim
Quote:
Originally Posted by sinangunay View Post
Güzelmiş. Keşke PHP bilsem
Sorma sinan bende aynı sendenim
__________________
RAMBilişim İnternet Hizmetleri - YS-839
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old 02.11.07, 09:42
sinangunay's Avatar
FULL DESTEK SUNUCULAR
 
Join Date: Jul 2007
Location: biLi biLi boP
Age: 28
Posts: 1,664
Rep Power: 1073
sinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond repute
Şimdiki aklım olsa geçmişte harcadığım vakti php öğrenmek için harcardım. Sabahtan akşama çalışıyoruz 3-5 kuruşa, 2 php kodlayıp kat kat kazananları gördükçe fıttırmamak elde değil hehehe

(lafım size değil ALEXIS yanlış anlamayın)
__________________
-----------------------------------------------------------------------------------------
>> LÜTFEN ÜCRETSİZ DESTEK TALEP ETMEK İÇİN MSN ADRESLERİMİZİ EKLEMEYİNİZ. HER TÜRLÜ ÜCRETSİZ DESTEK İÇİN FORUMLARIMIZI KULLANINIZ. TEŞEKKÜRLER <<
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old 02.11.07, 16:13
ALEXIS's Avatar
phpBB Türkiye
 
Join Date: Aug 2007
Location: istanbul
Posts: 112
Rep Power: 2
ALEXIS is on a distinguished road
Bu arada "ben php bilmiyorum" diyecek kadar ben de bilmiyorum, kodları 1 saat içinde php.net teki mysql komutlarını öğrenerek yazdım. LEFT JOIN, CONCAT gibi gelişmiş SQL komutlarını ise hiç bilmiyorum.

Asıl uzmanlık alanım phpBB framework'u, oradaki sql sınıfları, hazır fonksiyonlar sıradan php kadar zor değil.
__________________
Profesyonel phpBB3 hizmetleri
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old 03.11.07, 09:27
sinangunay's Avatar
FULL DESTEK SUNUCULAR
 
Join Date: Jul 2007
Location: biLi biLi boP
Age: 28
Posts: 1,664
Rep Power: 1073
sinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond reputesinangunay has a reputation beyond repute
Ama işte parayı kazandıranda sıradan php değildir sanırım?
__________________
-----------------------------------------------------------------------------------------
>> LÜTFEN ÜCRETSİZ DESTEK TALEP ETMEK İÇİN MSN ADRESLERİMİZİ EKLEMEYİNİZ. HER TÜRLÜ ÜCRETSİZ DESTEK İÇİN FORUMLARIMIZI KULLANINIZ. TEŞEKKÜRLER <<
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Sign up for PayPal and start accepting credit card payments instantly.

Navigasyon
Menü