I’m trying to get results from a MySQL database (for invoices) that includes multiple rows with multiple columns in each row. The database has three columns: Date (text), Hours (text), and Charged (boolean). I am trying to get an array of arrays to feed into a PHP script where the final product would be the same as this:
$invoice = array(array("date1","hours1"),array("date2","hours2"));
I currently have the following code:
$con = mysql_connect("$host", "$username", "$password");
$condb = mysql_select_db("$db_name");
...
120 | $sql = "SELECT date,hours FROM 'c1_log' WHERE charged=0";
121 | $result = mysql_query($sql,$con);
122 | $invoice = mysql_fetch_array($result);
When I run the code I get the following PHP error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in .../dbcon.php on line 122
Is there an alternate function to mysql_fetch_array() that would work?
I don’t think there is a fetch_all function for mysql you need to get it programmatically:
Link to fetch_assoc