Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jan 2010
    Thanked 0 Times in 0 Posts

    $data not returning

    Hi there,

    I need the $data to return from the database if the data was found from the database, but unfortunately, my code is not working to return the data.

    I tried to enter non-exist data, it managed to return the error message but if the data exist, the page displays nothing.

    May I know where did I go wrong in my if statement?

    Below is my code that contain after the $data return the script will execute.

    PHP Code:
    $day  $_POST['day'];
    $month $_POST['month'];
    $year  $_POST['year'];
    $dob implode('/', array($day,$month,$year));

    $_POST['day']) || empty($_POST['month']) || empty($_POST['year'])){
    "You need to fill in each field.<br /><br /><a href=\"./\" title=\"Fill In Again\">Click here to <b>fill in each field</b> again</a>";

    //Date that user keyin
    $userDate $dob;
    $dateTime DateTime::createFromFormat('d/m/Y'$userDate);
    $myFormat $dateTime->format('Y-m-d');

    //Query string and put it in a variable.
    $query "SELECT * FROM $table_n WHERE dob_chi = :date";
    } else {
    $query "SELECT * FROM $table_n WHERE dob_eng = :date";

    $stmt $db->prepare($query);
    $stmt->execute(array('date' => $myFormat));
    $data $stmt->fetchAll();
    if ( !
    $data ) {
    'No data found in database!';
    } else {

    //Now we create a while loop for every entry in our DB where the date is match.
    while ($row $stmt->fetchObject()) {
    $r1          $row->rowone;
    $r2          $row->rowtwo;
    $r3          $row->rowthree;
    $englishdate $row->dob_eng;
    $chinesedate $row->dob_chi;
    $zodiac      $row->zodiac;
    //add all initial data into a matrix variable for easier access to them later
        //To access rowone use $rows[0][0], rowtwo $rows[1][0] ect.
        //The matrix is an array which contains multiple array. eg. 2-dimensional arrays
        //To get all the variables with $r1X simply retrieve the first array of the matrix eg $rows[0]
    $rows = array(array($r1),array($r2),array($r3),array());       
    //Similarities between row1 and row2 made me incorporate modulo value as an argument.
    function incmod($a$m){
        return (
    $a $m) + 1;

    Thank you for your time

  2. #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Saskatoon, Saskatchewan
    Thanked 2,668 Times in 2,637 Posts
    Start by removing this:
    PHP Code:
    else {

    You don't return from the main method unless its the return result of the program which should be 0 unless its a failure.

    After this, you'll need to do something with the $data, $rows, $row. Currently there is no output, so you'll need to print something if you want it to display.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts