Jump to content

[SOLVED] Getting Data From Database And Turning Into Variables?


Muncey

Recommended Posts

Im fairly new to PHP but ive learnt it fast and ive worked very hard learning it. I have made a few simple things but i need help with something very simple that i have yet to learn.

 

Can someone please tell me how i can get something from a database and turn it into a variable. Not anything like a table or anything, something like a persons ID.. if there is a table for members and then there is a field called ID asweell as things like username, email ect... how do i get the ID and use it.

 

I do not want a certain ID, i want the ID of a person logged in at that time, so say they left a message on a guestbook, i could display there ID next to them by simply putting a variable like $member_id.

 

Thanks in advance.

<?php

  $db->connect();
  $query = $db->query("SELECT * FROM users WHERE userid = '$userid'");
  $userinfo = $db->fetch_array($query);
  $db->close();

  echo'
  <table class="users">
    <tr><td>'.$userinfo[id].'</td></tr>
    <tr><td>'.$userinfo[name].'</td></tr>
  </table>';

?>

The display of the guestbook entries is done using a MySQL query then displaying the data by parsing HTML in the output. I would assume this is done using a 'while' loop so it displays all the entries of your guestbook (or so many per page).

 

So, in that query it's probably asking for all the info in the guestbook entries like this:

 

"SELECT * FROM guestbooks";

 

Then display it with a while look and in the HTML output you'd specify where their ID would be located in your HTML

 

$results = mysql_query($sql);

 

while ($row = mysql_fetch_array($results) {

 

echo "<table><tr>

      <td>" . $row['member_id'] . "</td><td>" . $row['member_name'] . "</td>

        </td>

        </table><br/>\n";

}

 

 

 

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.