Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Question on mysql arrays in PHP

Featured Replies

Ok, so I have noticed something I never noticed before with MySql arrays in php, returned by mysql_query.

 

I was just using this snippet of code to look at the complete structure of the MySql array,

 

$result = mysql_query("SELECT * FROM test.$tableName") or die(mysql_error());
$row = mysql_fetch_array($result);
echo "<pre>";
print_r($row);

 

I was expecting to see an array like

 

Array
(
   [id] => 2
   [title] => IS Staff Induction
   [course_date] => 2010-05-13
   [start_time] => 09:30:00
   [end_time] => 12:30:00
   [availability] => 5
   [location] => 
)

 

but instead got

 

Array
(
   [0] => 2
   [id] => 2
   [1] => IS Staff Induction
   [title] => IS Staff Induction
   [2] => 2010-05-13
   [course_date] => 2010-05-13
   [3] => 09:30:00
   [start_time] => 09:30:00
   [4] => 12:30:00
   [end_time] => 12:30:00
   [5] => 5
   [availability] => 5
   [6] => 
   [location] => 
)

 

now why is there duplication of the data with a numerical index and an index of the MySql field name?

 

Is there a way to stop this behaviour and return just the data, indexed by field name?

 

Thanks!!

Edited by frupence

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.