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
    Jun 2012
    Thanked 0 Times in 0 Posts

    MYSQLI fetching data from table

    PHP Code:

    "SELECT title,artist FROM picker WHERE songID=$tune";

    $result mysqli_query($link$query);

    /* numeric array */
    $row mysqli_fetch_array($resultMYSQLI_NUM);

    This code results in a blank line.

    What I don't understand is, why is there 3 variables and 3 lines of code?
    KISS! Keep it simple stupid!
    What the heck is mysqli_num?

    My script I am trying to write is fairly simply.
    I have two basic arrays.
    Array 1 is built using scandir, which reads the files in the directories.
    this will be several thousand items.

    Array 1 is then shuffled.
    Array 2 then gets the top 500 items of array 1.
    At this point, the table is consulted and other information is added.

    Sounds simple right?
    So why isn't the coding?

    Anyone have a better way of doing this?

  2. #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Denver, Colorado USA
    Thanked 510 Times in 498 Posts
    This code results in a blank line.
    What debugging have you done to find out why? Either your query is failing due to an error (you have no error checking logic in your code to test for this possibility) or your query matched no rows (you have no logic in your code to test for this condition either.)

    What I don't understand is, why is there 3 variables and 3 lines of code?
    Because programming is a tedious process of building code that performs the operations that you need. If you want to reduce the number of statements that are in your main code, learn to write functions/classes.

    KISS! Keep it simple stupid!
    In programming, KISS would mean to write the correct amount of code, not too much and not too little, that's needed to accomplish a task. That's not necessarily the least amount of code.

    Using oop notation generally results in less typing and clutter, i.e. $result = $link->query($query);

    Learning and using php's functions and features can result in more compact and clearer code (often clearer code is better than minimal code since it helps to document what the code means) -
    list($title,$artist) = $result->fetch_row();
    echo $title,$artist;
    What the heck is mysqli_num?
    That would be covered in the php.net documentation. Programming, being a tedious and exacting activity, pretty much requires that you make use of the documentation so that you know what each statement means or does so that you can effectively use it to build your code.
    Finding out HOW to do something is called research, i.e. keep searching until you find the answer. After you attempt to do something and cannot solve a problem with it yourself, would be when you ask others for help.


Posting Permissions

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