| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| NamePros Regular | 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
__________________ The Kevin Dolan Design By Dolan Genetic Programming Source EuroToDollar: Forex Basics |
| |
| | #2 (permalink) |
| SQLdumpster.com | PHP Code: I think something along those lines |
| |
| | #3 (permalink) |
| NamePros Regular | I think thats wrong because the database isn't plog_users the table is.
__________________ The Kevin Dolan Design By Dolan Genetic Programming Source EuroToDollar: Forex Basics |
| |
| | #4 (permalink) |
| SQLdumpster.com | PHP Code: Last edited by miseria; 09-12-2005 at 04:09 PM. |
| |
| | #5 (permalink) |
| NamePros Regular | Ah wait I forgot something too. Im looking for a specific column as well. The column name is UID.
__________________ The Kevin Dolan Design By Dolan Genetic Programming Source EuroToDollar: Forex Basics |
| |
| | #7 (permalink) |
| NPQ's PA, Slave, and On Call Coder Technical Services | Something like this? ![]() PHP Code:
__________________ |
| |
| | #8 (permalink) |
| NamePros Member | PHP Code:
__________________ My host is better than yours |
| |
| | #9 (permalink) |
| NamePros Regular | 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;
?>
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.
__________________ The Kevin Dolan Design By Dolan Genetic Programming Source EuroToDollar: Forex Basics |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Tutorial: Creating a simple cgi hit counter for your site using Perl | deadserious | Webmaster Tutorials | 3 | 05-29-2004 01:31 AM |
| A simple cgi hit counter for your site using Perl | deadserious | CODE | 2 | 11-07-2003 08:23 AM |