0

Here is the code :

$sorular_hepsi = mysql_query("select * from tblsorular where hafta=1 order by rand() limit 1");
$soru_ust = mysql_fetch_assoc($sorular_hepsi);
$soru_id = $soru_ust_rs["id"];
$soru_grup_id = $soru_ust["sId"];
$sorular = mysql_query("select * from tblsorular where sId=$soru_grup_id");
$sorular_rs=mysql_fetch_array($sorular);

And here is my db schema :

id   soru   sId   hafta
==   ====   ===   =====
1    xxxx    4      1
2    yyyy    4      1
3    zzzz    5      1

And My Query

<?php       
$soru1 = $sorular_rs["soru"];
$soru2 = $soru_ust["soru"];
?>

EDIT I want to get soru1=xxxx and soru2=xxxx values but i know that i have to put some extra request in the second query like .... and id<>$idat the en of the query. It couldn't work.

EDIT-2

I did something like that :

$sorular_hepsi = mysql_query("select * from tblsorular group by sId order by rand() limit 2");
    while($soru_ust = mysql_fetch_assoc($sorular_hepsi)) {

    echo "<pre>";
    print_r($soru_ust);

and this is the result :

Array
(
    [id] => 45
    [soru] => İznik Çinisi
    [sId] => 23
    [hafta] => 1
)
Array
(
    [id] => 31
    [soru] => Maraş Biberi
    [sId] => 16
    [hafta] => 1
)

here you can see the sId values. 23 and 16. I want to list them only same group elements.

struggling hard!

Any suggestions?

Levent Kaya
  • 49
  • 10
  • 2x **highly** suggested reads (do before going LIVE) - [This one](http://stackoverflow.com/q/60174/1415724) and [this one](https://www.owasp.org/index.php/Top_10_2013-Top_10) – Funk Forty Niner Nov 05 '13 at 18:22
  • yes i know :) safety first. thanx again – Levent Kaya Nov 05 '13 at 18:25
  • Always a pleasure. Stay safe ;-) – Funk Forty Niner Nov 05 '13 at 18:25
  • Could you be clearer in regards to your problem please? – Sebas Nov 05 '13 at 18:28
  • @Sebas I want to get same "sId" valued fields. – Levent Kaya Nov 05 '13 at 18:34
  • you're performing 2 queries. Are you talking about the 2nd one or the first one? what about the `hafta=1` filter? – Sebas Nov 05 '13 at 18:34
  • @LeventKaya I think you need to use [`LIKE`](http://beginner-sql-tutorial.com/sql-like-in-operators.htm) if I understand correctly. – Funk Forty Niner Nov 05 '13 at 18:35
  • 'hafta' filter is same for 50 rows..its not important.. i'm getting first records sId from first query. And its randomly getting from mysql in 50 records. but i have to list all group elements. than i'm using the second query for the take the element of the same group. But its printing the same values sometimes because of the rand() query. I have to equal this two rows. I think its better to understand now :) – Levent Kaya Nov 05 '13 at 18:43
  • @LeventKaya Then use [`GROUP BY`](http://beginner-sql-tutorial.com/sql-group-by-clause.htm) – Funk Forty Niner Nov 05 '13 at 18:48
  • $sorular_hepsi = mysql_query("select * from tblsorular where hafta=1 group by sId order by rand() limit 1"); i did like that. but couldn't print it on the page. i mean i couln't assinged them into an array – Levent Kaya Nov 05 '13 at 19:10

0 Answers0