Jump to content

Load more from database


snallemap

Recommended Posts

This is the code im using:

 

<?php
        include "config.php";

if (isset($_GET['id'])) {
  $id = mysql_real_escape_string($_GET['id']);
  $sql = "SELECT email FROM gusers WHERE id = $id LIMIT 1";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      $row = mysql_fetch_assoc($result);
      echo "Email: " . $row['email'];
    }
  }
}

 

I am trying to get more informations than just the e-mail address, but everytime it seems to fail, i am a completly newb to php but ill try my best.... Could someone tell how this is done properly (like loading name, info, and so on from the database and showing it aswell)

Link to comment
https://forums.phpfreaks.com/topic/214202-load-more-from-database/
Share on other sites

What is it not doing correctly? / What is it doing? What should it be doing?

 

You don't need to put in all those if statements.

Try something like this:

 

<?php
        include "config.php";

if (isset($_GET['id'])) {
  $id = mysql_real_escape_string($_GET['id']);
  $sql = "SELECT email FROM gusers WHERE id = $id LIMIT 1";
  $result = mysql_query($sql) or die (mysql_error());
  if (mysql_num_rows($result) > 0) {
      $row = mysql_fetch_assoc($result);
      echo "Email: " . $row['email'];
  }
}

SELECT email FROM

 

should be either SELECT email, nextcollumn, anothercollumn, etc FROM

 

Or, if you want to pull all the collumns from the database: SELECT * FROM

 

Then just echo each row as you want it:

 

echo "Email: " . $row['email'] . "and" . $row['nextcollumn'];

 

etc  ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.