<?php require('config.php'); $connection=mysql_connect($ddbhost,$ddbuser,$ddbpw) or die ('fail'); mysql_select_db($ddb) or die ("fail"); $test=mysql_query("SELECT uid FROM test WHERE uname='Test'"); $test2=mysql_fetch_assoc($test); mysql_close($connection); print_r($test2); ?> PHP: is my code in my database i have CREATE TABLE `test` ( `uid` int(12) NOT NULL auto_increment, `uname` varchar(255) NOT NULL default '', `upassword` varchar(255) NOT NULL default '', PRIMARY KEY (`uid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ; INSERT INTO `test` VALUES(1, 'Test', 'cbb3ad65658902b16e3eccd44a2adba9'); INSERT INTO `test` VALUES(2, 'Test', 'cbb3ad65658902b16e3eccd44a2adba9'); INSERT INTO `test` VALUES(3, 'Test', 'cbb3ad65658902b16e3eccd44a2adba9'); INSERT INTO `test` VALUES(4, 'Test', 'cbb3ad65658902b16e3eccd44a2adba9'); INSERT INTO `test` VALUES(5, 'Tes2t', 'cbb3ad65658902b16e3eccd44a2adba9'); PHP: yet, when i run my code i get am i trying to select wrong?
Hmm, I'm not sure what is wrong with your code, because I use a different approach. You might give it a try. Use this instead of mysql_fetch_assoc while($row=mysql_fetch_array($test)) { echo $row['uid']; } Code (php):
yup, that does work. hmm, is there a way to store it into an array though? edit: nevermind, got it, very rudimentary though <?php require('config.php'); $connection=mysql_connect($ddbhost,$ddbuser,$ddbpw) or die ('fail'); mysql_select_db($ddb) or die ("fail"); $test=mysql_query("SELECT uid FROM test WHERE uname='Test'"); $test2 = array(); while($row=mysql_fetch_array($test)) { array_push($test2, $row['uid']); } print_r($test2); ?> PHP:
Then you'll need to put your result to query first. $array = ''; while($row=mysql_fetch_array($test)) { $array[] = $row['uid']; } print_r($array); PHP:
seems both our methods would work. do you know if one is better than the other in terms of resources?