Incorrect mysql_query

Discussion in 'PHP' started by Hubertas, Mar 22, 2010.

  1. #1
    Hello, sorry if a similar post was in the past, but I would like to ask for an advice.
    I have a problem with sql query (I think so):
    Firstly, I'm passing two variables in URL:
    http://localhost/e-pazymiu_knygele/mokinio_informacija.php?klase_id=1&mokinio_id=100

    Secondly, I'm retreiving necessary information from the table:
    $mokiniai_query= "SELECT mokinio_id, mok_vard, mok_pavard FROM mokiniai WHERE mokinio_id=' " . $_GET['mokinio_id'] . " ' ";
    $mokiniai_result=mysql_query($mokiniai_query, $link) or die(mysql_error());


    ...
    while($mokiniai_row = mysql_fetch_array($mokiniai_result)){
    $mokiniai_flag =1;
    $mokinio_vardas[]=$mokiniai_row['mok_vard'];
    $mokinio_pavarde[]=$mokiniai_row['mok_pavard'];
    $dydis[]=$mokiniai_row['mok_pavard'];
    }


    Lastly, I'm printing retreived information in a table:

    $i=0;
    $mokiniai_lentele='';
    while($i<sizeof($dydis)){
    $mokiniai_lentele .=<<<EOD
    <tr>
    <td width='41%' valign='top'>$mokinio_vardas</td>
    <td width='41%' valign='top'>$mokinio_pavarde</td>
    </tr>
    EOD;
    $i++;
    }


    The problem is I'm getting Array word in a place of $mokinio_vardas and $mokinio_pavarde.
     
    Hubertas, Mar 22, 2010 IP
  2. Sabbir

    Sabbir Banned

    Messages:
    210
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
    #2
    you should declare both array first. then
    Here 'i' is an incremental value.
     
    Sabbir, Mar 22, 2010 IP
  3. Hubertas

    Hubertas Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The problem was, that a browser didn't know what name to write, because I forgoted to write an index of the array.
    <td width='41%' valign='top'>$mokinio_vardas</td>
    <td width='41%' valign='top'>$mokinio_pavarde</td>

    <td width='41%' valign='top'>$mokinio_vardas[$i]</td>
    <td width='41%' valign='top'>$mokinio_pavarde[$i]</td>

    Thanks for the directing advice :)
     
    Hubertas, Mar 22, 2010 IP