2 Replies - 413 Views - Last Post: 03 October 2012 - 07:25 PM Rate Topic: -----

#1 paanmoddy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-October 12

Help Retrieving Data From MySQL

Posted 03 October 2012 - 06:53 PM

hello, i need help with my php coding. currently i'm working on timetable management system and i stuck on displaying the output in timetable. my php can't retrieve the data from my mysql. this is my coding.


<?php

$con = mysql_connect("localhost","root","********");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("test", $con);

$result = mysql_query("SELECT * FROM test") or die(mysql_error());



  
   /* declare a 2d array accessible by $arr["channel"]["time"].
      all programs are initialised to nothing. */

   $arr = array(
             "Time" => array("7.30", "8.00", "8.30", "9.00", "9.30", "10.00", "10.30"),
             "Ten" => array("7.30" => "", "8.00" => "", "8.30" => "", "9.00" => "", "9.30" => ""),
             "Nine" => array("7.30" => "", "8.00" => "", "8.30" => "", "9.00" => "", "9.30" => ""),
             "Prime" => array("7.30" => "", "8.00" => "", "8.30" => "", "9.00" => "", "9.30" => ""),
             "SBS" => array("7.30" => "", "8.00" => "", "8.30" => "", "9.00" => "", "9.30" => ""),
             "ABC" => array("7.30" => "", "8.00" => "", "8.30" => "", "9.00" => "", "9.30" => ""),
             );

   /* the programs would be loaded into the array from here. */
	


   /* this step would be updating the database.
      for now we will just set the element chosen in the html page. */
   $arr[$_POST['channel']][$_POST['time']] = $_POST['program'];

   echo "<table border=\"1\">\n";

   /* loop through the channels */
   foreach($arr as $channel => $value)
   {
      echo "<tr>";
      echo "<td>" . $channel ."</td>";

      /* and the times */
      foreach($value as $time)
      {
         echo "<td>" . $time . "</td>";
      }
      echo "</tr>\n";
   }
   
?>

This post has been edited by codeprada: 03 October 2012 - 07:04 PM
Reason for edit:: When posting code always use code tags, Removed password, Renamed Topic to be more descriptive


Is This A Good Question/Topic? 0
  • +

Replies To: Help Retrieving Data From MySQL

#2 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 947
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: Help Retrieving Data From MySQL

Posted 03 October 2012 - 07:03 PM

Hey, welcome to DreaminCode!

I don't understand when you say you can't retrieve your data from MySQL. When I read through the code you never tried to get the data after querying the database on line #11. To fetch the data you have the option of mysql_fetch_assoc or mysql_fetch_array. There are a few more but those are the most commonly used ones.

My suggestion is that you learn the MySQLi API instead of using MySQL. MySQLi is the improved version and provides you with more features such as Prepared Statements which make your code immune to SQL injections when used correctly. Once you know how to use the MySQL API then learning MySQLi is a breeze.
Was This Post Helpful? 1
  • +
  • -

#3 paanmoddy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-October 12

Re: Help Retrieving Data From MySQL

Posted 03 October 2012 - 07:25 PM

i already manage retrieve the data from mysql.. thanks.. :bigsmile:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1