Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: MYSQLI fetching data from table
05-07-2014, 08:07 AM #1
- Join Date
- Jun 2012
- Thanked 0 Times in 0 Posts
MYSQLI fetching data from tablePHP Code:
$query = "SELECT title,artist FROM picker WHERE songID=$tune";
$result = mysqli_query($link, $query);
/* numeric array */
$row = mysqli_fetch_array($result, MYSQLI_NUM);
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?
05-07-2014, 11:23 AM #2
- Join Date
- Oct 2006
- Denver, Colorado USA
- Thanked 350 Times in 342 Posts
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.)This code results in a blank line.
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.What I don't understand is, why is there 3 variables and 3 lines of code?
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.KISS! Keep it simple stupid!
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;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.What the heck is mysqli_num?
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.