NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page 30 NP$ For Whoever Can Give Me Simple Code Snippet

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 09-12-2005, 04:32 PM THREAD STARTER               #1 (permalink)
NamePros Regular
 
buddybuddha's Avatar
Join Date: May 2005
Location: PA
Posts: 216
buddybuddha is an unknown quantity at this point
 



30 NP$ For Whoever Can Give Me Simple Code Snippet


Im looking for a small sql code snippet to do an extremely simple task. Surely I could read an online tutorial, but Im really lazy. So there a 30 NP$ reward for whoever can give me the code.

I know how to connect to the database and how to select a database.

So assuming Im in the database, how do I:

1- Select a table named plog_users
2- View a given row, lets say for your code, row #2
3- Store the data contained in that raw as variable $nug
buddybuddha is offline  
Old 09-12-2005, 04:41 PM   #2 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 573
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




PHP Code:
<?php

$db_host 
"localhost";
$db_username "";
????: NamePros.com http://www.namepros.com/programming/123190-30-np-whoever-can-give-me.html
$db_password "";
$database "plog_users";


mysql_connect(localhost,$db_username,$db_password);
@
mysql_select_db($database) or die( "Unable to select database");


$query "SELECT * FROM 'row#2' ";
$result=mysql_query($query);
$num=mysql_num_rows($result);

$i=0;
while (
$i $num) {

$nug=mysql_result($result,$i,"row#2");

$i++;
}


?>

I think something along those lines
Encenta.com is offline  
Old 09-12-2005, 04:53 PM THREAD STARTER               #3 (permalink)
NamePros Regular
 
buddybuddha's Avatar
Join Date: May 2005
Location: PA
Posts: 216
buddybuddha is an unknown quantity at this point
 



I think thats wrong because the database isn't plog_users the table is.
buddybuddha is offline  
Old 09-12-2005, 04:57 PM   #4 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 573
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




PHP Code:
<?php

$db_host 
"localhost";
$db_username "";
$db_password "";
$database "";


mysql_connect(localhost,$db_username,$db_password)  ;
@
mysql_select_db($database) or die( "Unable to select database");


$query "SELECT 'row#2' FROM 'plog_users' WHERE UID=' ' ";
$result=mysql_query($query);
$num=mysql_num_rows($result);

$i=0;
while (
$i $num) {

$nug=mysql_result($result,$i,"row#2");
????: NamePros.com http://www.namepros.com/showthread.php?t=123190

$i++;
}


?>
I'm sure somebody will corect me on that. I have my own frustrations with MySQL
Last edited by Encenta.com; 09-12-2005 at 05:09 PM.
Encenta.com is offline  
Old 09-12-2005, 05:01 PM THREAD STARTER               #5 (permalink)
NamePros Regular
 
buddybuddha's Avatar
Join Date: May 2005
Location: PA
Posts: 216
buddybuddha is an unknown quantity at this point
 



Ah wait I forgot something too. Im looking for a specific column as well. The column name is UID.
buddybuddha is offline  
Old 09-12-2005, 05:09 PM   #6 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 573
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




Edited ^

It's wrong but it's a guideline
Last edited by Encenta.com; 09-12-2005 at 05:13 PM.
Encenta.com is offline  
Old 09-12-2005, 05:13 PM   #7 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Something like this?

PHP Code:
<?php

$dbhost 
"localhost";
$dbuser "username";
$dbpass "password";
$dbname "";


$db mysql_connect($dbhost$dbuser$dbpass);
mysql_select_db($dbname$db) or die("Error: " .mysql_error());


$query mysql_query("SELECT `UID` FROM `plog_users`") or die("Error: " .mysql_error());
$result mysql_query($query);

while (
$row mysql_fetch_array($result))
{
$nug $row['row#2'];
echo 
$nug;
}


?>
Eric is offline  
Old 09-12-2005, 05:36 PM   #8 (permalink)
NamePros Member
Join Date: Jul 2005
Posts: 100
Le Wolf is on a distinguished roadLe Wolf is on a distinguished road
 



PHP Code:
$result mysql_query("SELECT `UID` FROM `plog_users`");
????: NamePros.com http://www.namepros.com/showthread.php?t=123190
$uid mysql_result($result,1); // row 2 
__________________
My host is better than yours
Le Wolf is offline  
Old 09-13-2005, 02:00 PM THREAD STARTER               #9 (permalink)
NamePros Regular
 
buddybuddha's Avatar
Join Date: May 2005
Location: PA
Posts: 216
buddybuddha is an unknown quantity at this point
 



Hmm well that just about did it, sorta. And since Iused part of everyones code, I couldnt think of a fair way to distribute the NP$.

So whoever can figure out this error gets the 30 + a bonus 10!

I wrote the following code

Code:
<?php

$x = 0;

/* Set mysql variables */
$db_host = "localhost"; //Leave localhost
$db_user = "buddha_nugget"; //DB username
$db_name = "buddha_nugget"; //DB Name
$db_pass = "*****"; //DB User password

$connect = mysql_connect("$db_host","$db_user","$db_pass") or die(mysql_error());
$select_db = mysql_select_db("$db_name");

//Do sqlquery and get variable num
$sqlquery = mysql_query("SELECT * FROM plog_users");
$num = mysql_num_rows($sqlquery);

echo $num;
echo "<br>";

//Found Number of Rows

while ($x == 0)
{

	//Generate Random Number
	$random = rand(0,$num-1);

	//Connect
	$dbhost = "localhost";
	$dbuser = "buddha_nugget";
	$dbpass = "*****";
	$dbname = "buddha_nugget";

	$db = mysql_connect($dbhost, $dbuser, $dbpass);
	mysql_select_db($dbname, $db) or die("Error: " .mysql_error());

	$query = mysql_query('SELECT id FROM plog_users');
	$uid = mysql_result($query, $random); //Random Row

	$result = mysql_query('SELECT status FROM plog_users');
	$stat = mysql_result($result, $random); //Random Row

	if ($stat == "1"){$x = 1;}
	
	echo $random;
	echo "<br>";
	echo $uid;
	echo "<br>";
	echo $stat;
	echo "<br>";
}

echo "final";
echo "<br>";
echo $random;
echo "<br>";
echo $uid;
echo "<br>";
echo $stat;

?>
Tried to comment, but its a diagnostics code to tell me why it isnt working.
????: NamePros.com http://www.namepros.com/showthread.php?t=123190

Inside the plog_users table I have the following data.

id column- 1,22,21
status column- 1,3,2

After running the diagnostic program I get wierd results.

something along the lines of

3
2
22
2
1
21
3
0
1
1
final
0
1
1

The 3 is right, there are that man rows. Also, the 0,1,1 part is right.

But grouping the other two

2,22,2
and
1,21,3
which represent row,id,status

we find an error.

Row 2 is supposed to have 21,2
Row 1 is supposed to have 22,3

So it finds the proper status code, but not the proper id.

Anyone know why?

BTW- Im using phpmyadmin to view the tables.

Also, the grouping of those errors is consistent.
buddybuddha is offline  
Closed Thread


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
2 Huge Name Forsale Vegas Entertainment Domains For Sale - Make Offer 9 09-21-2004 03:37 PM
Tutorial: Creating a simple cgi hit counter for your site using Perl deadserious Webmaster Tutorials 3 05-29-2004 02:31 AM
A simple cgi hit counter for your site using Perl deadserious CODE 2 11-07-2003 09:23 AM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 02:15 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger