-1

I have written a calendar implementation, which is working, but displays only one set of data, I'm trying to make it appear all of the data in my select query:

$events = '';
$query = mysql_query('SELECT event_id, event_type, time, date, location, home_or_away, team_id FROM event WHERE date = "'.$deets.'"'); 
$num_rows = mysql_num_rows($query);
if($num_rows > 0) {
$events .= '<div id="eventsControl"><button onMouseDown="overlay()">Close</button><br /><br /><b> ' . $deets . '</b><br /><br /></div>';

while($row = mysql_fetch_array($query)){

I know it has to do with something with this, but I don't know exactly what code to imply to get 'event_type', 'time' and etc

$desc = $row['event_id'] ;

$events .= '<div id="eventsBody">' . $desc . '<br /> <hr><br /></div>';
}
}
echo $events;
?>
Raj
  • 22,346
  • 14
  • 99
  • 142
  • `$event_type = $row['event_type'];` and BTW your query is prone to SQL injections – Raj Mar 03 '13 at 14:07
  • `$row['event_type'], $row['location']`, etc... To see what is in `$row`, do `print_r($row)` – Michael Berkowski Mar 03 '13 at 14:07
  • Please don't use mysql_* functions in new code as they are deprecated. See question: [Why shouldn't I use mysql_* functions in PHP?](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – Alexander Christiansson Mar 03 '13 at 14:35

3 Answers3

1

You can use your columns as keys in the array. So to have time, use $row['time'] and so on.

For showing multiple data, try concatenating

$desc = $row['time'] .$row['event_type']

kms
  • 389
  • 2
  • 6
  • hello thanks for the advice, its now displaying more than one set of data, but now theres error while($row = mysql_fetch_assoc($query)){ echo $row['event_id'] ; echo $row['event_type']; $events .= '
    ' . $query . '


    '; } } echo $events; saying that 344game Close 5/22/2013 Resource id #5 - which is rather confusing and I was also wondering if you know how to space the data with a comma
    – user2108423 Mar 03 '13 at 14:40
  • Modify the body of the while as: { $events .= '
    ' .$row['event_id'] .', ' .$row['event_type'] .'


    '; } In this case you will have the id and type inside div, and the resource number will not show.
    – kms Mar 03 '13 at 16:18
0

You mean something like

$time  = $row['time']

etc? I'm not sure I've got your point

amik
  • 5,613
  • 3
  • 37
  • 62
  • basically i want it to display more than just the event_id. I want to display all the other fields ('event_type' , 'time' and etc). I tryed the other pieces of code doesnt work still :( any other ideas? – user2108423 Mar 03 '13 at 14:20
0

not sure what you are trying to do but if you are trying to display all columns, you can use a foreach loop

 while($row = mysql_fetch_array($query)){
     foreach($row as $key=>$value)
      {
        echo("<b>$key</b>$value<br/>");
      }
  }
Youn Elan
  • 2,379
  • 3
  • 23
  • 32
  • thanks for the help it actually partly works, for some reason its displaying them twice first number value e.g 1 12:00, then 'time12:00' do you know why that is and also it still has reference id #5 – user2108423 Mar 03 '13 at 14:57
  • this is by design. either use mysql_fetch_assoc or pass MYSQL_ASSOC as second parameter to mysql_fetch_array: mysql_fetch_array($query, MYSQL_ASSOC); – Youn Elan Mar 03 '13 at 19:07