Current location: Hot Scripts Forums » Programming Languages » PHP » Fetching MySQL Information


Fetching MySQL Information

Reply
  #1 (permalink)  
Old 07-23-07, 12:51 PM
bhimpfen bhimpfen is offline
Newbie Coder
 
Join Date: May 2005
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Fetching MySQL Information

I want to fetch domains under a specific user ID in a table, how do I do this?

Here is the MySQL
sql Code:
  1. CREATE TABLE `users` (
  2.   `id` int(5) NOT NULL AUTO_INCREMENT,
  3.   `login` varchar(15) DEFAULT '0',
  4.   `password` varchar(15) DEFAULT '0',
  5.   `domains` varchar(15) DEFAULT '0',
  6.   PRIMARY KEY  (`id`)
  7. ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
So, I want to display the "domains" in the users table for the id. Will be displayed in a table. It wont use login or password in the users table.

Here is an example of what I mean:
http://www.scriptplayground.com/tuto...tch-MySQL-Row/
__________________
VISIT JIVENETWORKS
FREE SOFTWARE, ARTICLES, NEWS AND MORE
ITS ALL FREE!!!

Last edited by Nico; 07-23-07 at 01:16 PM.
Reply With Quote
  #2 (permalink)  
Old 07-23-07, 01:20 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
PHP Code:



// Make sure database connection is established

$query mysql_query("SELECT domains FROM users WHERE id = XX LIMIT 1") OR die(mysql_error());
$userinfo mysql_fetch_array($query);

echo 
$userinfo['domains']; 
Reply With Quote
  #3 (permalink)  
Old 07-23-07, 02:45 PM
bhimpfen bhimpfen is offline
Newbie Coder
 
Join Date: May 2005
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
doesnt work, i get "Unknown column 'XX' in 'where clause'" eror
__________________
VISIT JIVENETWORKS
FREE SOFTWARE, ARTICLES, NEWS AND MORE
ITS ALL FREE!!!
Reply With Quote
  #4 (permalink)  
Old 07-23-07, 02:50 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
You have to replace the XX with the actual ID you want to fetch.
Reply With Quote
  #5 (permalink)  
Old 07-23-07, 02:51 PM
bhimpfen bhimpfen is offline
Newbie Coder
 
Join Date: May 2005
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
I did it like this, but it shows all of them and not a specific login row

PHP Code:

$query  "SELECT * FROM `users`";
$result mysql_query($query);

print 
"<br /><table width=\"750px;\" cellSpacing=\"1\" cellPadding=\"3\" style=\"border:1px solid #B2B2B2;\"><tr bgcolor=\"#AEB59F\"><td><strong>Domain Name</strong></td><td><strong>Whois E-mail</strong></td><td><strong>Change</strong></td></tr>";

while(
$row mysql_fetch_array($result))
{
    echo 
"<tr bgcolor=\"#C7C7C7\"><td>{$row['domains']}</td><td>{$row['domains']}@whoisprivacy.net</td><td><a href=\"mailto:enquiries@whoisprivacy.net?subject={$row['domains']} Whois Change&body=Provide e-mail or domain change here:\">change</a></td></tr>";

    
mysql_close();

print 
"</table><br />"
__________________
VISIT JIVENETWORKS
FREE SOFTWARE, ARTICLES, NEWS AND MORE
ITS ALL FREE!!!

Last edited by Christian; 07-24-07 at 11:45 PM. Reason: Please use [PHP] tags when posting PHP code.
Reply With Quote
  #6 (permalink)  
Old 07-23-07, 03:05 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Use my code, and replace the XX with the login ID.
Reply With Quote
  #7 (permalink)  
Old 07-23-07, 03:13 PM
bhimpfen bhimpfen is offline
Newbie Coder
 
Join Date: May 2005
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
if XX is $_SESSION["login"], how would I include it then
__________________
VISIT JIVENETWORKS
FREE SOFTWARE, ARTICLES, NEWS AND MORE
ITS ALL FREE!!!
Reply With Quote
  #8 (permalink)  
Old 07-23-07, 03:19 PM
bhimpfen bhimpfen is offline
Newbie Coder
 
Join Date: May 2005
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
still getting

Unknown column 'alpha' in 'where clause'

[php]$user_id = $_SESSION["login"];
$query = mysql_query("SELECT domains FROM users WHERE id = $user_id LIMIT 1") OR die(mysql_error());
$userinfo = mysql_fetch_array($query);

echo $userinfo['domains'];/php]
__________________
VISIT JIVENETWORKS
FREE SOFTWARE, ARTICLES, NEWS AND MORE
ITS ALL FREE!!!

Last edited by Christian; 07-24-07 at 11:46 PM. Reason: Please use [PHP] tags when posting PHP code.
Reply With Quote
  #9 (permalink)  
Old 07-23-07, 03:20 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
What does $_SESSION['login'] hold? The row ID or the value from the login field?

If it's the ID, try:
PHP Code:

$query mysql_query("SELECT domains FROM users WHERE id = " intval($_SESSION['login']) ." LIMIT 1") OR die(mysql_error()); 

And if it's the value from the login field, try:
PHP Code:

$query mysql_query("SELECT domains FROM users WHERE login = '"mysql_real_escape_string($_SESSION['login']) ." LIMIT 1") OR die(mysql_error()); 

Reply With Quote
  #10 (permalink)  
Old 07-23-07, 03:30 PM
bhimpfen bhimpfen is offline
Newbie Coder
 
Join Date: May 2005
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
i insert more then 1 domain my nulling password and id and using insert for login and domains, so I can have multiple domain enteries per login

way u did it, is only showing 1 domain, i want to show unlimited domains
__________________
VISIT JIVENETWORKS
FREE SOFTWARE, ARTICLES, NEWS AND MORE
ITS ALL FREE!!!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
retrieve information from MYSQL through drop down list minglou PHP 3 04-03-09 09:43 PM
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
Updating mysql information phpfreek Database 8 09-27-06 03:33 PM
Displaying Information From A MySQL Database In Specific Orders KeYBLeR PHP 3 04-25-06 08:06 PM
Adding information to MySQL database via forms. Dale PHP 8 08-13-05 09:55 PM


All times are GMT -5. The time now is 06:07 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.