I'm a novice at PHP to do MySQL manipulations. When the problem is boiled down, the database has 2 columns - city, borough. Some cities have a borough and the field is populated. Some cities do not, and the borough field is null. I only want to retrieve data into an array if the borough field is populated. My code looks like:
while ($row = mysql_fetch_array($fetch, MYSQL_ASSOC)){
if ( what_column_identifier_goes_here? != null ){
/* For each row containing borough_data, put it in the return array */
$row_array['city'] = $row['borough'];
array_push($return_arr,$row_array);
}
}
I tried searching for an answer, but I couldn't figure out good terms. From the search, I suspect this is deprecated. For the moment, I just want to get something working and then I'll learn PDO and make a whole bunch of changes in several scripts.
Thanks for any help.
if ($row['borough']) // do something
Or do it in the query:
SELECT city, borough FROM table WHERE borough IS NOT NULL
assuming your query looks like
SELECT city, borough FROM ...
then you can use mysql_fetch_assoc(), which returns a simple associative array: fieldname -> value: (no need for the extra fetch parameter)
if (!empty($row['borough'])) {
$city stuff....
}
with fetcharray, you have to count positions yourself:
SELECT field1, field2, field3, ... <-- in SQL
$row[0], $row[1], $row[2], ... <--- in PHP
SELECT FROM TABLE WHERE borough<>''
perhaps this can help you quickly. if you want more help then please visit at http://www.w3made.com