Hello and welcome to our community! Is this your first visit?
Register
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
    Posts
    136
    Thanks
    0
    Thanked 0 Times in 0 Posts

    MYSQLI fetching data from table

    PHP Code:

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

    $result mysqli_query($link$query);

    /* numeric array */
    $row mysqli_fetch_array($resultMYSQLI_NUM);
    echo 
    $row[0],$row[1];

    mysqli_free_result($result); 
    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.
    alpha[0]="filename"
    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
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,122
    Thanks
    2
    Thanked 327 Times in 319 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) -
    Code:
    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.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

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