runnerjp Posted February 3, 2009 Share Posted February 3, 2009 I tried the code below <?php require_once 'settings.php'; $query = "SELECT * FROM pbs WHERE ID = '1'"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) $bestTimes[] = $row; foreach($bestTimes as $distance => $time) if(!empty($time)) echo $distance." = ".$time."<br>"; ?> but insted out getting the output 100m = 10.0 300m = 30.0 i just get array = 0 my table looks like this 100 200 300 10.0 30.0 im trying just to displays those entries that have a time in them Quote Link to comment https://forums.phpfreaks.com/topic/143628-array-to-get-db-field-which-are-filled-in/ Share on other sites More sharing options...
Snart Posted February 3, 2009 Share Posted February 3, 2009 Try this: $bestTimes = &$row; Quote Link to comment https://forums.phpfreaks.com/topic/143628-array-to-get-db-field-which-are-filled-in/#findComment-753601 Share on other sites More sharing options...
printf Posted February 3, 2009 Share Posted February 3, 2009 If you just want rows returned that have a time then you should add that logic to your query. It makes no sense to return rows that don't contain any relevant data! Quote Link to comment https://forums.phpfreaks.com/topic/143628-array-to-get-db-field-which-are-filled-in/#findComment-753602 Share on other sites More sharing options...
runnerjp Posted February 3, 2009 Author Share Posted February 3, 2009 how would u do it printf Quote Link to comment https://forums.phpfreaks.com/topic/143628-array-to-get-db-field-which-are-filled-in/#findComment-753617 Share on other sites More sharing options...
premiso Posted February 3, 2009 Share Posted February 3, 2009 $query = "SELECT * FROM pbs WHERE ID = '1' AND `time` <> ''"; OR if `time` can be null $query = "SELECT * FROM pbs WHERE ID = '1' AND `time` IS NOT NULL"; Quote Link to comment https://forums.phpfreaks.com/topic/143628-array-to-get-db-field-which-are-filled-in/#findComment-753670 Share on other sites More sharing options...
runnerjp Posted February 3, 2009 Author Share Posted February 3, 2009 but my table looks liek this ID 100 200 300 400 1 11.0 2 12.0 3 11.5 ect lol Quote Link to comment https://forums.phpfreaks.com/topic/143628-array-to-get-db-field-which-are-filled-in/#findComment-753684 Share on other sites More sharing options...
runnerjp Posted February 4, 2009 Author Share Posted February 4, 2009 bmp Quote Link to comment https://forums.phpfreaks.com/topic/143628-array-to-get-db-field-which-are-filled-in/#findComment-754193 Share on other sites More sharing options...
trq Posted February 4, 2009 Share Posted February 4, 2009 Your table structure makes no sense. What does a print_r($bestTimes) produce? Quote Link to comment https://forums.phpfreaks.com/topic/143628-array-to-get-db-field-which-are-filled-in/#findComment-754201 Share on other sites More sharing options...
runnerjp Posted February 4, 2009 Author Share Posted February 4, 2009 ID = 1 100m = 10:0 300m = 35:0 Array ( [iD] => 1 [100m] => 10:0 [200m] => [300m] => 35:0 ) maybe you can offer some advice how i can do this better.... i want users to be able to insert there personal bests.. so the output would look something like pb time 100m 11.00 200m 33.00 800m 2.07.4 but they can have an list of pbs to chose from 100/200/300/400/800/1000/3000/5000 ect.. but only the ones they chose and fill in get shown on their profile.. i have 2 problems realy.. how to get them to fill there pbs in and edit them and also how to show it on their profile page Quote Link to comment https://forums.phpfreaks.com/topic/143628-array-to-get-db-field-which-are-filled-in/#findComment-754218 Share on other sites More sharing options...
trq Posted February 4, 2009 Share Posted February 4, 2009 You could store the distance in one field. eg; CREATE TABLE pbs ( id INT NOT NULL AUTO_INCREMENT, uid INT, distance INT, pb INT PRIMARY KEY (id) ); Then, say user 1 had done 100m in 11 seconds and 200m in 33secs..... INSERT INTO pbs (uid, distance, pb) VALUES (100, 11); INSERT INTO pbs (uid, distance, pb) VALUES (200, 33); You would then use.... SELECT distance, pb FROM pbs WHERE uid = 1; To get user 1's times. Quote Link to comment https://forums.phpfreaks.com/topic/143628-array-to-get-db-field-which-are-filled-in/#findComment-754221 Share on other sites More sharing options...
printf Posted February 4, 2009 Share Posted February 4, 2009 Please show your table scheme... example... CREATE TABLE `bbs_spell` ( `sid` int(10) unsigned NOT NULL DEFAULT '0', `opt` text NOT NULL, PRIMARY KEY (`sid`), KEY `sid` (`sid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; Quote Link to comment https://forums.phpfreaks.com/topic/143628-array-to-get-db-field-which-are-filled-in/#findComment-754223 Share on other sites More sharing options...
runnerjp Posted February 4, 2009 Author Share Posted February 4, 2009 -- -------------------------------------------------------- -- -- Table structure for table `pbs` -- CREATE TABLE IF NOT EXISTS `pbs` ( `ID` tinyint(99) NOT NULL auto_increment, `100m` varchar(4) NOT NULL default '', `200m` varchar(4) NOT NULL default '', `300m` varchar(4) NOT NULL default '', PRIMARY KEY (`ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; -- -- Dumping data for table `pbs` -- INSERT INTO `pbs` (`ID`, `100m`, `200m`, `300m`) VALUES (1, '10:0', '', '35:0'); Quote Link to comment https://forums.phpfreaks.com/topic/143628-array-to-get-db-field-which-are-filled-in/#findComment-754227 Share on other sites More sharing options...
trq Posted February 4, 2009 Share Posted February 4, 2009 I would change it to what I suggested. Quote Link to comment https://forums.phpfreaks.com/topic/143628-array-to-get-db-field-which-are-filled-in/#findComment-754229 Share on other sites More sharing options...
runnerjp Posted February 4, 2009 Author Share Posted February 4, 2009 ok im going with that what would you say is the best way of collecting th users id's and pb's ... this one has had me stumped.. textbox or drop down menus... how would i select how many to show? how would i show them so they can be edited? Quote Link to comment https://forums.phpfreaks.com/topic/143628-array-to-get-db-field-which-are-filled-in/#findComment-754230 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.