Results 1 to 2 of 2

Thread: PHP - SQL Query?

  1. #1
    Cheeko
    Guest

    PHP - SQL Query?

    Hi,

    Say I have an sql table, with the fields: user, pass, age - How would I get all the ages into an array?

    Say it was like:

    Matt Password 65
    Dave Password 54
    John Passwrod 12

    Who would I get it so I could type:

    echo MyArray[1]; To echo 54?

    Anyone

  2. #2
    scoutt
    Guest
    well what does your sql statement look like? do you want it to show all of them or is some one trying to see a paticular one? If you put all of them in an array you would have to show all of them, but you could do an if statement to show the one you want.

    Code:
      $result = mysql_query ("select * from sql_table");
      $num_links =mysql_num_rows($result);
    
      for ($i=0; $i<$num_links; $i++)
    		  {
       $row = mysql_fetch_array($result);
       $age = $row["age"];
    }
    
    echo"$age";
    you can try something like that.

    or if you want
    Code:
      $result = mysql_query ("select * from sql_table where age = $typed_text");
     		  {
       $row = mysql_fetch_array($result);
       $age = $row["age"];
       $name = $row["name"];
    
    echo"$name";
    echo"$age";
    that might work if some one typed an age into a text box.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width