Jump to content

array to get db field which are filled in


runnerjp

Recommended Posts

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

 

 

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

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.

-- --------------------------------------------------------

--
-- 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');

ok im going with that :D

 

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?

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.